Active Directory Certificate Services (AD CS) turns certificate templates into privilege escalation paths when templates are misconfigured. A template that lets a low-privilege user enrol, supply their own subject alternative name (SAN), and request a certificate usable for client authentication is effectively a credential printer - enrol as Domain Admin, authenticate with the forged certificate, and the domain trusts you. This sub-skill maps the ESC1 through ESC8 misconfiguration families, shows how to enumerate templates safely, and explains how to prove a vulnerable template inside scope without breaking the certificate authority. Authorized work only, with the parent skill privesc-ad-paths providing the graph context.
Quick Workflow
- Confirm scope includes the certificate authority and the target domain, and record which CA, templates, and enrolment endpoints are in scope.
- Enumerate certificate templates, CAs, and enrolment rights with read-only queries - do not enrol anything yet.
- Classify each template against the ESC families - ESC1, ESC2, ESC3, ESC4, ESC5, ESC6, ESC7, ESC8 - and note which condition each template meets.
- Verify the single most promising template by hand - read its flags, EKUs, enrolment rights, and manager approval settings from the directory, not from a scanner summary alone.
- Enrol once, inside scope, with a SAN or EKU that matches the misconfiguration, and convert the certificate to a usable authentication credential.
- Authenticate as the target principal, confirm the privilege level, capture the certificate request evidence, and clean up test certificates and accounts where the rules of engagement require it.
- Report the template setting as the root cause, with the exact hardening change for each ESC family, plus detection notes for certificate issuance events.
1. Enumerating templates and authorities read-only
Start with directory enumeration. Certificate templates live in the Configuration naming context, and enrolment rights are ACLs on those template objects. A scanner summary is useful, but the directory objects are the evidence.
Get-ADObject -SearchBase "CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=example,DC=local" -Filter * -Properties * |
Select-Object Name, msPKI-Certificate-Name-Flag, msPKI-Enrollment-Flag, pKIExtendedKeyUsage
certutil -config "CA01\ExampleCA" -catemplates
The first command lists templates with the flags that decide ESC status. The second lists templates published on a specific CA. Cross-check the two - a template that is vulnerable but not published on any reachable CA is not an immediate path, while a template published on a CA with a web enrolment endpoint adds the ESC8 surface. Record the CA name, DNS name, and template names exactly, because enrolment commands need them verbatim.
For Linux attack hosts, the standard enumeration tooling queries LDAP for the same objects and renders the ESC classification.
certipy-ad find -u lowprivuser@example.local -p 'PasswordHere' \
-dc-ip 10.0.0.10 -stdout -vulnerable
Use credentials obtained inside scope only, and treat the vulnerable flag as a lead to verify by hand, not as a confirmed finding. Certipy output lists the template, the CA, and the ESC number, which is the starting point for the manual checks in the next sections.
2. ESC1 - Enrolment with attacker-chosen SAN and client authentication
ESC1 is the classic case. A template allows enrolment by a low-privilege principal, permits the requester to supply a subject alternative name, does not require manager approval, and includes an EKU that permits client authentication (or no EKU restriction at all). Enrol with the SAN of a privileged user, and the issued certificate authenticates as that user.
certipy-ad req -u lowprivuser@example.local -p 'PasswordHere' \
-ca ExampleCA -target ca01.example.local -template VulnerableTemplate \
-upn administrator@example.local -dc-ip 10.0.0.10
certipy-ad auth -pfx administrator.pfx -dc-ip 10.0.0.10
The first command requests a certificate with the administrator UPN as the SAN. The second uses the resulting PFX file to authenticate and obtain the account hash or ticket, depending on the tool options and scope. Verify before enrolment that the template truly allows SAN supply - the msPKI-Certificate-Name-Flag value controls this, and a template that builds the subject from Active Directory data instead of requester input is not ESC1, no matter what a scanner says. Also verify the EKU list - a template limited to server authentication or code signing does not give client authentication, so it does not give this path.
3. ESC2, ESC3, and ESC4 - EKU, enrolment agent, and template write
ESC2 covers templates with no EKU, or with an EKU that includes any purpose, combined with enrolment rights for low-privilege users. Such a certificate can be used for any purpose, including client authentication, so the fix is to restrict the EKU to the intended purpose only.
ESC3 covers enrolment agent templates. A template that grants enrolment agent rights lets the holder request certificates on behalf of any user, including privileged users, subject to the enrolment agent restrictions. The attack has two stages - first enrol as an enrolment agent, then use that certificate to request a second certificate for the target principal. Test both stages inside scope, because a template that looks like ESC3 but restricts enrolment agent use to specific templates may not complete the second stage.
ESC4 covers write access over the template object itself. If a low-privilege principal holds GenericWrite, WriteDACL, or WriteOwner over a certificate template, they can modify the template to become ESC1 - enable SAN supply, add client authentication, remove manager approval - and then enrol. This is a parent-graph edge from privesc-ad-paths applied to a template object.
Get-ADObject -SearchBase "CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=example,DC=local" -Filter {Name -eq "VulnerableTemplate"} -Properties nTSecurityDescriptor |
Select-Object -ExpandProperty nTSecurityDescriptor |
ForEach-Object { $_.Access } |
Format-Table IdentityReference, ActiveDirectoryRights
Read the ACL output the same way you read any directory ACL - look for low-privilege principals with write rights, and check whether the template is published on a reachable CA before concluding the path is exploitable. A writable template that no CA publishes is a hardening finding, not an escalation path, until publication changes.
4. ESC5, ESC6, ESC7, and ESC8 - CA control, flags, and endpoints
ESC5 is control over the CA itself or its computer object - GenericWrite over the CA, membership in a group that administers it, or local admin on the CA server. CA control lets an attacker modify templates, issue arbitrary certificates, or disable auditing, so it collapses every other ESC check. Report CA control as the highest severity finding in this family.
ESC6 is the EDITF_ATTRIBUTESUBJECTALTNAME2 flag on the CA, which lets any requester supply a SAN in any enrolment request, regardless of template settings. Check it with certutil against the CA.
certutil -config "CA01\ExampleCA" -getreg policy\EditFlags
If the output shows EDITF_ATTRIBUTESUBJECTALTNAME2 enabled, every template that allows enrolment and client authentication becomes ESC1-like, even templates that do not themselves allow SAN supply. The fix is to clear that flag and restart the CA service during an agreed change window.
ESC7 covers CA management rights - ManageCA and ManageCertificates permissions held by low-privilege principals. ManageCA lets an attacker approve pending requests, including requests for privileged users, and ManageCertificates lets them issue certificates directly. Both are checked through the CA security settings, not through template ACLs.
ESC8 covers web enrolment endpoints - the certsrv HTTP endpoint that accepts NTLM authentication and is vulnerable to relay attacks when Extended Protection for Authentication is not enforced. If the CA publishes a web enrolment page and the scope includes relay testing, ESC8 combines with relay tooling to obtain a certificate as the relayed principal. Verify the endpoint exists and that relay is in scope before testing it, because relay attacks against production authentication infrastructure are high impact and often explicitly excluded.
5. Converting a certificate to domain privilege and cleaning up
A forged certificate authenticates through PKINIT, which maps the certificate to the account named in the SAN. The authentication step yields a ticket or hash that proves the privilege level. Confirm it with a whoami style check from the new context, and record the exact template, CA, SAN, and EKU used, so the finding is reproducible for the report and for the remediation test.
openssl pkcs12 -in administrator.pfx -nodes -out administrator.pem
ls -l administrator.pfx administrator.pem
Converting the PFX for inspection confirms the certificate subject and SAN match the intended target before you authenticate. After testing, follow the rules of engagement on cleanup - revoke test certificates where the CA supports it, remove test accounts created for enrolment, and never leave a forged Domain Admin certificate on an attack host beyond the engagement. Report the certificate serial number and issuance time so the defender can find the corresponding CA audit events.
Detection note for this family - certificate issuance generates CA audit events, and unusual enrolment stands out in several ways. Enrolment with a SAN that does not match the requester, enrolment against templates rarely used in the environment, enrolment agent use outside administrative workflows, and template modification events are all high-value alerts. Defenders should audit template ACLs regularly, alert on CA configuration changes, and monitor for PKINIT authentication by accounts that normally authenticate with passwords.
Edge cases
- A template may look vulnerable but require manager approval, which blocks automated enrolment until an administrator approves the request.
- Templates not published on any CA cannot be enrolled, even when every other ESC condition is met.
- The EDITF_ATTRIBUTESUBJECTALTNAME2 flag applies at the CA level, so fixing one template does not fix ESC6.
- Enrolment agent restrictions may limit which templates the agent certificate can request on behalf of others.
- Protected groups and AdminSDHolder do not prevent certificate-based authentication as a privileged user once a valid certificate is issued.
- Web enrolment endpoints may require HTTPS with client certificates, which changes the relay preconditions for ESC8.
- Certificate validity periods matter - a short-lived test certificate may expire before the remediation retest, so record the validity window.
- Some CAs run on hosts with additional controls, such as offline roots, where enrolment against the root is impossible and only the subordinate issuing CA matters.
Key references
- MITRE ATT&CK T1553 (Subvert Trust Controls), T1553.004 (Install Root Certificate), T1649 (Steal or Forge Authentication Certificates)
- Certipy documentation - https://github.com/ly4k/Certipy
- SpecterOps AD CS research on ESC1 through ESC8 - https://posts.specterops.io/certified-pre-owned-d95910965cd2
- Microsoft AD CS template documentation - https://learn.microsoft.com/en-us/windows-server/identity/ad-cs/certificate-templates
- HackTricks AD CS section - https://book.hacktricks.xyz/windows-hardening/active-directory-methodology/ad-certificates
