AD CS Misconfigurations: ESC1 to ESC8
Active Directory Certificate Services (AD CS) is Microsoft's enterprise PKI. It issues certificates for Wi-Fi and VPN authentication, smart-card logon, web servers, code signing and encrypted file systems, and it is integrated with AD so that a certificate can be used to authenticate to the domain (Kerberos PKINIT, or Schannel to LDAP). That integration means a certificate template is, in effect, a credential factory: if an ordinary user can obtain a certificate that names someone else, that user can sign in as them, and a certificate stays valid for a year or more, through password resets. In 2021 the SpecterOps paper Certified Pre-Owned catalogued the misconfigurations that allow this as ESC1 to ESC8; later research added more (ESC9 to ESC16 and counting). This lesson covers ESC1–ESC8 at the level of conditions, detection and fix, with a template checker you can run.
Certificates and PKI in general are in X.509 Certificates and Certificate Chains.
How a certificate becomes a logon
- A certificate template (an AD object under
CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,…) defines who may enroll, which key usages (EKUs) the certificate gets, whether issuance needs a CA manager's approval, and where the subject name comes from: built from AD (safe), or supplied by the requester in the request. - An enterprise CA that publishes the template issues the certificate.
- The user presents it to a DC with PKINIT; the DC maps the certificate to an account (by the UPN or DNS name in the subject alternative name, or by the SID in the security extension added in 2022) and issues a TGT for that account.
The eight classes
| ESC | Condition | In one sentence |
|---|---|---|
| ESC1 | template allows enrollee-supplied subject (CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT), has an authentication EKU, low-privileged users may enroll, no manager approval, no authorized signatures |
anyone can request a certificate "for" a domain admin |
| ESC2 | template has the Any Purpose EKU or no EKU, low-privileged enroll, no approval | the certificate can be used for anything, including as an enrollment agent or client authentication |
| ESC3 | template has the Certificate Request Agent EKU and low-privileged enroll | the holder may request certificates on behalf of other users from templates that allow agents |
| ESC4 | low-privileged principals have write rights on a template object | they can reconfigure a safe template into ESC1 |
| ESC5 | weak ACLs on other PKI objects (the CA's computer object, the NTAuthCertificates object, the PKI containers) |
control of the PKI's infrastructure |
| ESC6 | the CA has EDITF_ATTRIBUTESUBJECTALTNAME2 set |
every template accepts a SAN in the request attributes (largely neutralised by strong certificate mapping, but still a finding) |
| ESC7 | low-privileged principals hold ManageCA or ManageCertificates on the CA | they can change CA settings (enable ESC6) or approve pending requests |
| ESC8 | HTTP web enrollment (or the enrollment web service) accepts NTLM without Extended Protection | relay a coerced DC authentication and receive a certificate for the DC (NTLM Relay) |
A template and CA checker
Assessment tools (Certify and Certipy for testers; Locksmith and PSPKIAudit for defenders; PingCastle and Purple Knight in general AD audits) read the templates and the CA configuration from LDAP and the CA, then apply these conditions. The program applies them to a synthetic export of the lab CA CA01.corp.lab.test.
LOW_PRIV = {"Domain Users", "Authenticated Users", "Domain Computers", "Everyone"}
AUTH_EKUS = {"Client Authentication", "PKINIT Client Authentication", "Smart Card Logon"}
templates = [
{"name": "User", "enroll": {"Domain Users"}, "ekus": {"Client Authentication", "Secure Email"},
"supply_subject": False, "approval": False, "signatures": 0, "writers": {"Enterprise Admins"}},
{"name": "WebServer-Lab", "enroll": {"Domain Users"}, "ekus": {"Server Authentication", "Client Authentication"},
"supply_subject": True, "approval": False, "signatures": 0, "writers": {"Enterprise Admins"}},
{"name": "VPN-Legacy", "enroll": {"Authenticated Users"}, "ekus": set(),
"supply_subject": False, "approval": False, "signatures": 0, "writers": {"Enterprise Admins"}},
{"name": "Agent", "enroll": {"IT-Helpdesk", "Domain Users"}, "ekus": {"Certificate Request Agent"},
"supply_subject": False, "approval": False, "signatures": 0, "writers": {"Enterprise Admins"}},
{"name": "Smartcard-Admins", "enroll": {"Tier0-Admins"}, "ekus": {"Smart Card Logon"},
"supply_subject": False, "approval": True, "signatures": 0, "writers": {"Enterprise Admins", "Domain Users"}},
]
ca = {"name": "CA01", "editf_san2": True, "managers": {"PKI-Admins"}, "officers": {"PKI-Admins", "IT-Helpdesk"},
"web_enrollment": True, "epa": False}
def check(t):
low = bool(t["enroll"] & LOW_PRIV)
open_issue = low and not t["approval"] and t["signatures"] == 0
f = []
if open_issue and t["supply_subject"] and t["ekus"] & AUTH_EKUS: f.append("ESC1")
if open_issue and (not t["ekus"] or "Any Purpose" in t["ekus"]): f.append("ESC2")
if open_issue and "Certificate Request Agent" in t["ekus"]: f.append("ESC3")
if t["writers"] & LOW_PRIV: f.append("ESC4")
return f
for t in templates:
print(f"{t['name']:17} {', '.join(check(t)) or 'ok'}")
ca_findings = []
if ca["editf_san2"]: ca_findings.append("ESC6 (EDITF_ATTRIBUTESUBJECTALTNAME2)")
if (ca["managers"] | ca["officers"]) - {"PKI-Admins", "Enterprise Admins"}:
ca_findings.append("ESC7 (" + ", ".join(sorted((ca["managers"] | ca["officers"]) - {"PKI-Admins"})) + " can manage certificates)")
if ca["web_enrollment"] and not ca["epa"]: ca_findings.append("ESC8 (web enrollment without EPA)")
print(f"CA {ca['name']}: " + "; ".join(ca_findings))User ok
WebServer-Lab ESC1
VPN-Legacy ESC2
Agent ESC3
Smartcard-Admins ESC4
CA CA01: ESC6 (EDITF_ATTRIBUTESUBJECTALTNAME2); ESC7 (IT-Helpdesk can manage certificates); ESC8 (web enrollment without EPA)
WebServer-Lab is the classic ESC1: someone copied the Web Server template, let the requester supply the subject (web servers need their own DNS names in it), and left Client Authentication and Domain Users enrollment in place. Smartcard-Admins looks safe because it requires approval, but Domain Users can edit it (ESC4), so they can switch approval off. The help desk being a certificate officer is ESC7 even though nothing else is wrong.
What a misissued certificate looks like
Detection on the CA comes down to one comparison: does the identity in the certificate match the requester? The sandbox session below (no network; a throw-away lab CA created in the session) issues what an ESC1 abuse produces, a certificate requested by bob whose SAN names the domain administrator, and prints the fields a reviewer checks.
openssl req -x509 -newkey rsa:2048 -nodes -keyout ca.key -out ca.crt -days 30 -subj "/CN=Lab Issuing CA" 2>/dev/null
openssl req -newkey rsa:2048 -nodes -keyout bob.key -out bob.csr -subj "/CN=bob" 2>/dev/null
cat > ext.cnf <<'EOF'
extendedKeyUsage = clientAuth
subjectAltName = otherName:1.3.6.1.4.1.311.20.2.3;UTF8:administrator@corp.lab.test
EOF
openssl x509 -req -in bob.csr -CA ca.crt -CAkey ca.key -set_serial 0x2001 -days 30 -extfile ext.cnf -out bob.crt 2>/dev/null
openssl x509 -in bob.crt -noout -subject -serial
openssl x509 -in bob.crt -noout -ext extendedKeyUsage,subjectAltNamesubject=CN = bob
serial=2001
X509v3 Extended Key Usage:
TLS Web Client Authentication
X509v3 Subject Alternative Name:
othername: UPN::administrator@corp.lab.test
The subject says bob, the SAN's UPN (1.3.6.1.4.1.311.20.2.3) says administrator@corp.lab.test, and the EKU allows client authentication. On a real CA the request record (event 4887 and the CA database) shows the requester CORP\bob; a SAN for a different account, especially a privileged one, is the alert.
How abuse is detected
- CA auditing on (Audit Certification Services, and the CA's own audit filter enabling all categories): 4886 request received, 4887 request approved and certificate issued (with requester and attributes), 4888 denied, 4899 template updated, 4900 template security updated, 4882 CA security permissions changed, 4890 certificate manager settings changed.
- Requester vs subject mismatch in 4887 or in a scheduled review of the CA database (
certutil -viewwith requester, subject and SAN columns). - PKINIT logons of admins from unusual hosts: 4768 with pre-authentication type 16 (PKINIT) for a Tier 0 account from a workstation.
- Template and CA changes outside change windows: 5136 on
pKICertificateTemplateobjects (ESC4 in progress) and on the CA's configuration. - Relay to web enrollment (ESC8): 4886/4887 for a DC's or server's computer account received over HTTP from a non-DC address.
How it is fixed
- ESC1: remove "Supply in the request" or require CA manager approval; restrict enrollment to the group that needs it; remove client-authentication EKUs from templates that don't need them.
- ESC2/ESC3: no Any Purpose or empty EKUs on enrollable templates; enrollment-agent templates only for a small, Tier 0-managed group, with enrollment-agent restrictions on the CA.
- ESC4/ESC5: templates, the CA object and PKI containers writable only by PKI admins (Tier 0).
- ESC6:
certutil -setreg policy\EditFlags -EDITF_ATTRIBUTESUBJECTALTNAME2and restart the CA service. - ESC7: CA managers and certificate officers only from a Tier 0 PKI group.
- ESC8: remove HTTP enrollment if unused; otherwise HTTPS only, EPA on, NTLM off on the site.
- Strong certificate mapping (May 2022 update KB5014754, now enforced): DCs require the SID security extension or an explicit strong mapping, which blunts several of these classes, but don't rely on it alone.
- Treat the CA servers as Tier 0: whoever controls the CA's key can sign certificates for any account ("golden certificate"), and a CA backup contains that key.
Pitfalls
- Revoking the bad certificate only. Revocation lists are checked by DCs, but fix the template first, or the next request issues another.
- Password reset as remediation. A certificate-based logon doesn't care about the password; revoke certificates and reset the account.
- Auditing off on the CA, which is the default for several categories.
- Forgetting the newer classes (ESC9 onwards: weak mappings, schema version 1 templates, issuance-policy links). Run a current tool, not only this list.
Practice
1. Which single change makes WebServer-Lab pass the checker, and which change would you also make?
Remove Domain Users from enrollment (only the web-server admin group should enroll), or require manager approval. Also remove the Client Authentication EKU: a web server certificate needs Server Authentication only.
2. Why is Smartcard-Admins flagged even though it requires approval?
Domain Users have write rights on the template object (ESC4): any user can remove the approval requirement and add themselves to enrollment, then request a smart-card logon certificate.
3. In the sandbox session, what would the same certificate look like if it were issued correctly to bob?
The SAN UPN would be bob@corp.lab.test (built from AD, not supplied by the requester), and since 2022 the certificate would also carry the SID security extension (1.3.6.1.4.1.311.25.2) with bob's SID.
Test yourself
Which combination defines ESC1?
- Web enrollment without EPA
- Enrollee-supplied subject, an authentication EKU, low-privileged enrollment, no approval
- A CA with a weak key
- An expired root certificate
Which event on the CA records that a certificate request was approved and issued?
- 4886
- 4887
- 4899
- 4768
What is ESC8?
- A template with no EKU
- NTLM relay to AD CS HTTP enrollment without Extended Protection
- A CA officer from the help desk
- A self-signed root
Why doesn't resetting a user's password undo an ESC1 abuse?
- It does
- The attacker's certificate still authenticates as the user via PKINIT until it is revoked or expires
- Because passwords are stored on the CA
- Because of RC4