ESC2: no patch is coming, so take Any Purpose off the template
The AD CS template that says 'valid for anything' hands any user an enrolment-agent certificate. There is no CVE and no vendor patch: narrow the EKU in both attributes, restrict the agents, and revoke what is already out there.
01 The Big PictureFor leadership · no jargon
Okay, so ESC2 is the awkward one in the Certified Pre-Owned family. There is no CVE, there is no vendor patch, and I would not hold your breath for either, because nothing in Windows is broken. The thing that needs changing is a dropdown on a certificate template that somebody set in 2016 and nobody has looked at since. It is also the finding I keep seeing half-fixed: the obvious repair touches one of the two places the certificate authority actually reads, and the other one carries on doing the damage.
Start with what a certificate template is. Your internal certificate authority is a passport office: it issues documents that say "this person, or this machine, is who they claim to be, and we checked". A template is the form the clerk fills in. Most forms say what the document is for: logging on, proving a website is genuine, signing code. ESC2 is a form that says "valid for anything". That sounds harmless. It is not, because every system that checks a passport accepts a document claiming to be valid for everything, and one of those systems is the counter that issues them. Because the document is valid for anything, it also works as an enrolment agent's licence, the thing that lets an approved clerk apply for a passport on somebody else's behalf. So an ordinary user gets one, walks back to the same counter, and files an application in the CEO's name. The clerk checks the licence, sees "anything", and stamps it.
There is no memory corruption, no relay and no phishing in it. The fix is not a patch, and the severity argument is short: Microsoft treats a misconfigured template as an administrative problem, and the evidence supports that reading. The work comes in two halves. First, say what the certificate is actually for, in both of the attributes the CA consults, and never leave the answer blank. Then take away the ability to ask on somebody else's behalf, and clean up the licences already handed out. The first half is an afternoon of template edits. The second is an ACL and revocation project, and there is no single command for it. Sorry.
02 Technical BreakdownFor engineers
Right, let's get into it. ESC2 is a property of a certificate template, the same way ESC1 is, and the definition is one line: the template defines Any Purpose EKUs, or no EKU at all. SpecterOps' original wording is "The certificate template defines Any Purpose EKUs or no EKU." Everything else it inherits from ESC1: low-privileged users hold enrolment rights, manager approval is off, and no authorised signatures are required.
Any Purpose is OID 2.5.29.37.0, which RFC 5280 calls anyExtendedKeyUsage. An EKU is the "what is this document for" field, so this value is the field saying "all of it". The no-EKU case reaches the same destination by a different road: an empty pKIExtendedKeyUsage means no restriction at all, which is exactly how the built-in SubCA template is built. It carries no EKU, a critical basic constraints extension, and keyCertSign in the key usage, because it exists to sign other certificates.
A correction while we are here, because it is repeated everywhere: 1.3.6.1.4.1.311.20.2.1 is not the SubCA OID. That OID is Certificate Request Agent, the enrolment agent EKU, and the agent leg below depends on it. SubCA is the absence of an EKU, not a magic number. The OID gets mislabelled because the default SubCA template is the canonical example of the blank case, and people reach for the first EKU-shaped string in the room.
On its own, an Any Purpose certificate gets the requester nothing more than being themselves. SpecterOps added that clarification to the paper in June 2021: without the CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT flag, which is ESC1 territory, you cannot request an authentication certificate as another user. You can authenticate as yourself, which you could already do with a password. Plenty of people stop at that line. The enrolment-agent leg is the next paragraph.
The pivot is the enrolment agent leg. A certificate that is valid for any purpose is, by construction, valid for the Certificate Request Agent purpose, which is what an enrolment agent holds. Certipy's wiki puts it plainly: the "Any Purpose" nature implicitly grants the Certificate Request Agent capability. GhostPack's Certify wiki says the same thing from the offensive side: because the certificate can be used for any purpose, it is possible to use it as a Certificate Request Agent and replay the ESC3 abuse. So the holder submits an on-behalf-of request, a CMC or CMS blob that says "issue this to somebody else, and here is my authority to ask".
Whether that lands depends on the target template, and most write-ups skip the schema-version rules. Templates come in schema versions. Version 1 templates have no concept of authorised signatures at all, and Microsoft's processing rules for the signature requirement are scoped explicitly to versions 2, 3 and 4, which is why, in practice, any agent certificate satisfies a v1 target. Version 2 and later targets only accept the agent certificate if msPKI-RA-Application-Policies lists the agent's own EKU, which in our case means 2.5.29.37.0 has to be written there. Certipy encodes exactly this rule: a target is agent-enrollable if it is schema v1, or if it requires signatures and its application policy contains Any Purpose.
The last step turns a certificate into a domain compromise. The CA issues a certificate naming the victim, with the victim's UPN in the subject alternative name and the victim's SID in the security extension. The attacker presents it to the KDC with PKINIT, the public-key initial authentication exchange, and the KDC resolves the account from the certificate. Per MS-PKCA, the KDC looks up the account from the certificate's principal name, and if that fails it uses the explicit mapping fields. The TGT comes back for the victim, with the victim's SID and group membership in the PAC. From there it is a hash and a DCSync. Certipy's output is the shape to look for: Security Extension SID: 'S-1-5-21-...-500', then Got TGT, then Got hash.
The SubCA variant does not get you domain authentication on its own. SpecterOps is clear that if the rogue CA is not trusted by the NTAuthCertificates object, which it will not be by default, certificates it signs do not work for domain logon. The impact moves sideways instead: TLS certificates for any name, code signing, SAML assertions, AD FS tokens, IPsec. That is still very bad. It becomes domain auth only if the attacker can also write NTAuthCertificates, which is ESC5, and at that point they have enough rights to skip the ceremony.
A template stores its EKUs in two attributes, and this is where the fixing goes wrong. pKIExtendedKeyUsage is the obvious one, the one the certificate templates console shows you under the Extensions tab. msPKI-Certificate-Application-Policy is the second, and per SpecterOps, the application policy takes precedence over pKIExtendedKeyUsage unless the template is schema version 1 and pKIExtendedKeyUsage is non-empty.
The console writes both, so a change made by hand is consistent. A change made by a script usually is not, because the script author read one blog post and wrote one Set-ADObject line. Clean pKIExtendedKeyUsage, leave the application policy holding Any Purpose, and the CA carries on issuing Any Purpose certificates while the template looks fixed in the GUI. Most scanners read the same attribute, so the half-fixed template scans clean. In Certipy's current find.py, the ESC2 predicate is computed from pKIExtendedKeyUsage alone:
any_purpose = "Any Purpose" in extended_key_usage or not extended_key_usageSo a scripted half-fix can produce a template that Certipy reports clean and the CA still treats as Any Purpose. If that has been patched upstream by the time you read this, good, and the lesson still applies to every other tool and every other script you point at the problem. BloodHound's own ESC4 instructions add and remove the EKU in both attributes explicitly, so the trap is common enough that other tooling designs around it.
The second trap is emptying the EKU list instead. That does not remove the capability; it moves it into the request. A template with no EKU and a requester-supplied subject lets the requester define the application policy, on any schema version. That is the root of ESC15, CVE-2024-49019, and a worse posture than the one you started with. Set a specific EKU list, never an empty one.
So what does an attacker need? None of it is exotic.
- An enterprise CA that lets the principal request certificates at all. That is a CA-level setting, separate from the template.
- Read plus Enroll on the template, granted directly or through nested group membership. Domain Users, Authenticated Users and Everyone are the usual suspects; custom groups with three hundred members count too.
- The template published on at least one enterprise CA. Certipy's
enabledfield just means "at least one CA lists this template", and a template that is not published cannot be requested. - Manager approval off, and no authorised signatures required.
- An EKU list that is Any Purpose, or empty.
- A target template for the agent leg: client-auth capable, agent-enrollable, the victim can enrol in it, and approval is off there too.
- No enrolment agent restrictions on the CA blocking the agent-template-victim triple. The default is unrestricted.
- PKINIT on a domain controller, which is the default, and the issuing CA trusted for NTAuth, which it is by default if it is an enterprise CA.
Your domain does not need to be at any particular functional level and your servers do not need to be missing an update. This is true of every Windows Server build that has run AD CS.
People keep looking for the advisory. There isn't one, and I would be surprised if there ever is. MSRC's servicing test is two questions: does the finding violate the security boundary or the intent of a security feature, and does its severity meet the bar. If either answer is no, by default it does not get a security update. A template an administrator configured to trust everything is a configuration state, not a defect in shipped code.
Microsoft has crossed that line once in this same area. When ESC15 turned out to be a code-level flaw, schema v1 templates accepting arbitrary application policies, it got CVE-2024-49019 at CVSS 7.8. Same family, same outcome for the attacker, different layer of the stack, and therefore an actual CVE. Keep that contrast for the next person who asks why there is no patch. There is no patch because there is no bug in the product; the remediation is yours to own.
One piece of folklore to drop while we are here. The SpecterOps quote everyone repeats, "we determined your finding is valid but does not meet our bar for a security update release", came out of the ESC8 relay discussion, not an ESC2 ruling. It fairly describes Microsoft's general posture. It is not an ESC2-specific statement from MSRC, and I have not found one of those.
It also arrives because a vendor told somebody to make it. Integration guides exist that list "Add both Any Purpose (2.5.29.37.0) (optional) and Client Authentication" as a setup step, and that is how an OID ends up sprinkled into a template "just in case". The pattern behind that instruction is usually a support case where a certificate was rejected for an unknown reason, somebody added Any Purpose, it started working, and the reason was never established.
The trouble is that nobody can tell you which check Any Purpose was satisfying, including the team that asked for it. Teams that originally asked for Any Purpose because they didn't know what they'd need still can't say which check it satisfies, so err toward fewer EKUs and add capability only when something specific breaks. That is the correct procedure, and it is subtractive: take it off, add back the minimum, let breakage tell you what the real requirement was.
Some products reject Any Purpose outright. Cisco ISE treats such a certificate as invalid, and Microsoft's own Cloud PKI in Intune refuses the EKU as "overly permissive and a potential security risk". So in some estates the template has been failing its intended job for years. Removing Any Purpose fixes a latent problem.
03 Affected
Any AD CS enterprise CA, on any supported Windows Server version, publishing a template with Any Purpose or no EKU, where a non-Tier-0 principal holds Enroll and the approval and signature requirements are off. There are no build numbers to check because there is no patched build. Either the template is configured that way or it isn't.
In practice the vulnerable templates arrive in four shapes:
- A duplicated SubCA or "Subordinate Certification Authority" template, published because somebody needed to issue intermediate certificates and did not think about who else could ask.
- A vendor-instructed template with Any Purpose added "optionally", usually alongside Client Authentication, usually with Domain Users still holding Enroll from the template it was duplicated from.
- A legacy appliance template, created years ago for a device that needed "a certificate", with no EKU and no owner.
- A template whose EKU list somebody emptied by hand, believing that was the safe direction. That one is now an EKU-injection template, and it is worse.
I have no credible prevalence number for ESC2 and I am not going to invent one. The ESC1 guides quote vendor telemetry because somebody published it; there is no equivalent survey here. What I can say is that the shapes above are common enough that "we do not use Any Purpose" is a claim to test.
Things that do not help, and get suggested anyway:
- KB5014754 full enforcement. Strong certificate mapping does not stop this chain. The agent-issued certificate carries the victim's SID in the
1.3.6.1.4.1.311.25.2extension, so it satisfies strong mapping and PKINIT still returns a TGT for the victim. The one config where enforcement bites is a template that sets the0x00080000bit to suppress the SID extension, where mapping falls back to the weak SAN UPN. That is my inference from the KB text and MS-PKCA; I have not found a Microsoft statement about ESC2 that says so, so treat it as a bonus rather than a control. - Protected Users, and "account is sensitive and cannot be delegated". No delegation is involved. The KDC is not being asked to forward anything; it is being handed a certificate with the victim's name on it.
- Unpublishing the template. It closes the attack path, and it does not remove the object or the finding. The template is one
Add-CATemplateaway from being live again, and anyone holding Manage CA can do that. - Deleting the template object. If the CA still lists it, you have an orphan publication, and it becomes security-relevant again the moment somebody with delegated rights can recreate the object. Unpublish first, delete later.
04 Detection
Before we change anything, let's see what we are dealing with. Most teams run one scanner and stop. There are four questions to answer: what is vulnerable, who can reach it, who already holds a certificate, and what the logs would have told you.
01 The attacker's-eye scan
certipy find -u '<user>@<domain>' -p '<password>' -dc-ip <DC_IP> -vulnerable -stdout An ordinary user's credentials will do; that is rather the point. Look for Any Purpose : True, Extended Key Usage : Any Purpose, and a [!] Vulnerabilities block reading ESC2 : Template can be used for any purpose.
Expect the same template to show up as ESC3 as well. Certipy treats Any Purpose as an enrolment-agent capability by definition, so the pair is one finding seen through two doors, not two findings. A blank EKU list is caught by the same predicate, which is your SubCA-shaped case.
If you are reading the JSON output, mind the key:
jq -r '."Certificate Templates"[] | select(."[!] Vulnerabilities".ESC2)
| ."Template Name", ."Certificate Authorities"' 20261125120000_Certipy.json The key is literally [!] Vulnerabilities, brackets included. Most snippets online write Vulnerabilities, return null, and the null result then gets read as a clean estate. Check that before you trust a quiet jq output.
From the defensive side, PSPKIAudit does a forest scan and Locksmith gives you a revert script:
Import-Module .\PSPKIAudit.psd1
Invoke-PKIAudit
Invoke-Locksmith -Mode 0 -Scans ESC2 PSPKIAudit's ESC2 predicate is no manager approval, zero authorised signatures, low-privilege enrolment, and a dangerous EKU, where dangerous means Any Purpose or no EKU at all. Locksmith titles the finding ESC2 - Vulnerable Certificate Template - Subordinate CA/Any Purpose and checks the same shape. Certify still works, but the verb changed: current builds want enum-templates --filter-vulnerable, and the find /vulnerable syntax in older write-ups is legacy.
02 The query that does not depend on a tool
Tools disagree about edge cases, and you want your own answer anyway. This finds every template in the forest with an unrestricted EKU and no approval gate:
$pks = "CN=Public Key Services,CN=Services,$((Get-ADRootDSE).configurationNamingContext)"
Get-ADObject -SearchBase "CN=Certificate Templates,$pks" `
-LDAPFilter '(objectClass=pKICertificateTemplate)' `
-Properties pKIExtendedKeyUsage, 'msPKI-Certificate-Application-Policy',
'msPKI-Enrollment-Flag', 'msPKI-RA-Signature' |
Where-Object {
$ekus = @($_.pKIExtendedKeyUsage) +
@($_.'msPKI-Certificate-Application-Policy') |
Where-Object { $_ }
(-not $ekus -or $ekus -contains '2.5.29.37.0') -and
-not ($_.'msPKI-Enrollment-Flag' -band 2) -and
-not $_.'msPKI-RA-Signature'
} |
Select-Object Name, pKIExtendedKeyUsage,
'msPKI-Certificate-Application-Policy' Note the union at the top. It reads both EKU attributes and de-duplicates, because the second one wins on schema v2 and later. A script that reads only pKIExtendedKeyUsage will miss the half-fixed template, and that includes some scanners.
The same thing as a single LDAP filter, if you would rather hand it to your own tooling:
(&(objectclass=pkicertificatetemplate)
(!(mspki-enrollment-flag:1.2.840.113556.1.4.804:=2))
(|(mspki-ra-signature=0)(!(mspki-ra-signature=*)))
(|(pkiextendedkeyusage=2.5.29.37.0)(!(pkiextendedkeyusage=*)))) 1.2.840.113556.1.4.804 is the bitwise-AND matching rule, so !(...:=2) means the manager-approval bit is not set. (!(attr=*)) means the attribute is absent, which is the no-EKU case. This filter still only reads one EKU attribute, which is the next paragraph's problem, not its own.
03 Publication, and who can actually enrol
A template nobody publishes is not exploitable yet. Cross-check the CA's published list, then read the rights on the survivors:
Get-ADObject -SearchBase "CN=Enrollment Services,$pks" `
-LDAPFilter '(objectClass=pKIEnrollmentService)' `
-Properties certificateTemplates, dNSHostName |
Select-Object Name, dNSHostName, certificateTemplates certificateTemplates holds the template's internal name, not its display name, and it is per CA. A multi-CA forest needs this run against every one of them.
$enroll = [guid]'0e10c968-78fb-11d2-90d4-00c04f79dc55'
$t = Get-ADObject "CN=<template>,CN=Certificate Templates,$pks" `
-Properties nTSecurityDescriptor
$t.nTSecurityDescriptor.GetAccessRules($true, $true,
[System.Security.Principal.SecurityIdentifier]) |
Where-Object {
$_.AccessControlType -eq 'Allow' -and
($_.ObjectType -eq $enroll -or $_.ObjectType -eq [guid]::Empty)
} |
ForEach-Object {
try { $_.IdentityReference.Translate(
[System.Security.Principal.NTAccount]).Value }
catch { $_.IdentityReference.Value }
} A row naming Domain Users, Authenticated Users, Everyone, or a custom group with a large membership is the finding. A row naming only Domain Admins or Enterprise Admins is the expected built-in SubCA template and is not. Expand nested groups before you conclude anything, because the ACE you removed is not always the ACE that grants the right.
04 Who already has one
The answer decides whether you revoke or just fix, and almost nobody asks it before the change window. Ask the CA database which certificates it has already issued from the template:
certutil -view -restrict "CertificateTemplate=<template OID>" ^
-out "RequestID,RequesterName,CommonName,NotBefore,NotAfter,Disposition" csv The restriction takes the template's msPKI-Cert-Template-OID, not its name. If the OID returns nothing, try the display name; CA database fields are fussy. The rows that matter are certificates sitting on accounts that should not have had one, and anything still inside its validity period.
05 The logs
CA auditing is off by default, in the way that security tooling usually is: technically available, practically never on. Trimarc's Jake Hildreth, who wrote Locksmith, put it about as plainly as it can be put: in the nearly 20 environments they had looked at, exactly zero had auditing properly enabled.
Turn it on before you need it:
certutil -setreg CA\AuditFilter 127
certutil -setreg policy\EditFlags +EDITF_AUDITCERTTEMPLATELOAD
auditpol /set /subcategory:"Certification Services" /success:enable /failure:enable
net stop certsvc && net start certsvc AuditFilter 127 turns on all seven CA categories; the EditFlags bit is separate, lives in a different registry location, and without it you get no template load or update events at all. Both need the service restart, and restarting the service stops issuance while it happens.
Then add a SACL to the templates container, because 5136 needs one and the subcategory alone audits nothing:
- Object:
CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=<domain> - Principal:
Everyone, type Success - Applies to: this object and all descendant objects
- Access: Write all properties, Create/Delete objects, Write permissions
The events to wire up:
- 4887 on the CA, where the requester and the certificate subject differ. This is the on-behalf-of request, the moment the enrolment-agent leg fires, and the highest-fidelity single event in AD CS. It is also exactly what an ESC1 request looks like, so the discriminator is which template was used, and that lives in the
CertificateTemplateattribute, not in a dedicated field. - 4886 and 4887 on the CA, where the requester enrolled in the Any Purpose template as themselves. Boring on its own, but it is step one of the chain. Baseline the template OID and alert on new requesters.
- 4768 on a DC, with
CertIssuerName,CertSerialNumberandCertThumbprintpopulated. Since the January 2025 update the event is version 2 and carries those fields, which are empty for a password logon and filled for PKINIT. That is a cleaner discriminator than any pre-auth value. - 5136 on a DC, on the template object, for the change itself. Its value is timing: it fires when the change happens, not when somebody next enrols.
- 4899 and 4900 on the CA, which read like template change alerts and are not. Microsoft is explicit: 4899 fires when a loaded template has an attribute updated and an enrolment is attempted, and 4900 when the security descriptor changes and an enrolment event occurs. Change a template and revert it without enrolling, and both stay silent. 5136 is your only at-the-time signal.
A word on 4768, because there is a myth with legs. People alert on pre-auth type 0x11 and call it PKINIT. 0x11 is 17 decimal, which Microsoft documents as PA-PK-AS-REP and notes is never seen in some environments at all; the smart card types you will actually see are 15 (PA-PK-AS-REP_OLD, documented as "used for Smart Card logon") and 16 (PA-PK-AS-REQ). 0x11 also appears in that event as a ticket encryption type, meaning AES128, which is where the confusion comes from. Alert on 15 and 16, or better, on the certificate fields being populated.
Do not build on 4624. It has logon type 2 for interactive and 10 for remote interactive, and Microsoft's field list for the event contains no certificate, thumbprint or smart-card field at all. It cannot tell a certificate logon from a password logon, whatever a detection blog tells you.
06 What the tooling does not give you
Two gaps in the tooling, both still open in November 2026.
BloodHound has no ADCSESC2 edge. The analysis package ships ESC1, ESC3, ESC4, ESC6, ESC9, ESC10, ESC13 and ESC16. ESC2 survives only as a template property, so you write the path yourself:
MATCH p = (n)-[:Enroll|AllExtendedRights|GenericAll]->(ct:CertTemplate)
-[:PublishedTo]->(eca:EnterpriseCA)
WHERE (ct.effectiveekus = '' OR ct.effectiveekus CONTAINS '2.5.29.37.0')
AND ct.requiresmanagerapproval = false
AND (ct.authorizedsignatures = 0 OR ct.schemaversion = 1)
RETURN p
LIMIT 1000 If that returns nothing, drop the effectiveekus clause and read the Effective EKUs field on the node by hand; I could not confirm how every BloodHound CE build serialises the empty list.
And there is no off-the-shelf SIEM rule for pure ESC2. Sigma's nearest rule requires the ENROLLEE_SUPPLIES_SUBJECT flag, so it catches ESC1-with-Any-Purpose and misses the template that is only ESC2. Splunk Security Content has ESC1 abuse and ESC1 authentication analytics and nothing for ESC2. Elastic's only AD CS rule is for CVE-2026-54121. Sentinel's built-in gallery has no ESC2 template as far as I can tell, so it is custom KQL. The Splunk ESC1 pair is a usable starting shape, because the requester-versus-subject mismatch and the 4887-to-4768 correlation are the same mechanics, but you are porting it, not importing it.
05 Remediation
Order matters here, and only the revocations are hard to undo, so they go last. The rest is reversible, provided you take the backup in step one.
01 Write down what you have, and back up the ACLs
Inventory every template the queries above returned, with an owner, a purpose and a consumer list. Anything published without a documented owner is either an unpublishing candidate or a documentation finding, and the difference is one conversation. While you are in there, export the security descriptor for every template you plan to touch:
$t = Get-ADObject "CN=<template>,CN=Certificate Templates,$pks" `
-Properties nTSecurityDescriptor
$t.nTSecurityDescriptor.Sddl | Set-Content ".\<template>-acl-backup.txt"That file is the rollback for every rights change in this guide. Keep it with the change record, not on the engineer's laptop.
This register is also the thing that lets you have the EKU conversation at all. The alternative is asking a team that chose Any Purpose in 2016 to name the EKUs they need, and the usual answer is "we don't know".
02 Unpublish the templates nobody uses
Check the CA database for issuance first, then unpublish from the CA's list:
certutil -SetCATemplates -<templateInternalName> The verb is case-sensitive and takes the template's internal cn, not its display name. Use + to republish. Do this on every CA, because the published list is per CA, and remember that an AD replication delay can make it look like nothing happened.
The breakage here is delayed, and that is what makes it dangerous. Existing certificates stay valid until they expire or are revoked; only future requests fail. Renewal windows are measured in weeks, so an unpublish that breaks something looks fine for a month and then takes out a fleet. Treat the waiting period as the point: wait a week at minimum, a month if you can, because that is the step that surfaces the enrolment you failed to find.
Two more things to expect. Certipy will keep reporting the template, because Enabled: False means no CA publishes it, not that the template is disabled; there is no disabled state for a template. And if you delete the AD object while the CA still lists it, you get an orphan publication that becomes exploitable again if anyone with delegated rights can recreate the object. Unpublish first, delete later, and write down why the scanner still complains so the next person does not reopen it.
03 Replace Any Purpose with the narrowest EKU, in both attributes
The rules for the core fix are short. Set a specific list. Never empty, because empty plus a requester-supplied subject is the ESC15 EKU-injection shape. Never Any Purpose. Write the same list to both pKIExtendedKeyUsage and msPKI-Certificate-Application-Policy, because the second wins on v2 and later and a script that writes one has not fixed anything. Then check the Subject Name tab before you walk away. If the template allows "Supply in the request" and you have just added Client Authentication, you have converted an ESC2 into an ESC1. Same severity, different name, and the scanner will happily report the new one. If it allows supply-in-the-request and you need Server Authentication instead, you are looking at ESC17. The template console does warn about the combination, in the driest possible Microsoft wording: combining these certificate options may create a cert security risk and is not recommended.
Which EKUs to use is a question about the application, not about AD CS, so I am not going to hand you a table of guesses. The ones I could verify: Always On VPN server certificates need Server Authentication (1.3.6.1.5.5.7.3.1) plus IP security IKE intermediate (1.3.6.1.5.5.8.2.2), and the AOVPN device tunnel needs Client Authentication. NPS is the interesting one, because Microsoft's own documentation says a blank or "All" EKU cannot substitute for Client Authentication or Server Authentication there, so a no-EKU template was never doing the job properly in the first place.
There is no trustworthy breakage map, and I looked. I could not find a single first-hand public account of the form "we removed Any Purpose and product X stopped working". The absence is the useful part: Any Purpose satisfied every EKU check the application made, so nobody ever learned which check it was. The procedure that follows is subtractive and iterative. Remove it, add the minimum, watch what breaks, add one EKU back. Change one thing, verify, then move on, so that when enrolment breaks you know which change did it.
Two mechanical notes. If you want the fleet to actually move onto the corrected template, the lever is the major revision, by right-clicking the template and choosing Reenroll All Certificate Holders; the minor revision bumps on any GUI edit and does nothing immediate. And if you edit the attributes with a script rather than the console, you own that bookkeeping yourself.
The CA does not see your change instantly. Enterprise CAs poll Active Directory for template changes, and per Certipy's wiki it can take a few minutes and, depending on configuration and replication, several hours. Restarting Certificate Services forces a reload, at the cost of issuance while it restarts. If you skip this, you get the confusing hour where the console says fixed and the CA still issues the old template.
And if you narrow to an EKU the KDC will not accept for PKINIT, the failure is a Kerberos error at logon, KDC_ERR_INCONSISTENT_KEY_PURPOSE. That sends everyone looking at the domain controller instead of the template, so know it before you spend the evening on the wrong server.
04 Keep the CA able to read the template
Removing Read from a template is the most common way a careful ACL cleanup becomes an outage, and the error message points at the wrong thing. If you remove Authenticated Users: Read while narrowing a template, the CA itself may no longer be able to read it. Every request then fails with 0x80094800 CERTSRV_E_UNSUPPORTED_CERT_TYPE, and the CA logs event 77 saying the template could not be loaded.
The error points at publishing; the fault is on the template's permissions. Either keep Authenticated Users: Read (the usual advice, and the least surprising), or grant Read explicitly to each CA's computer account. Do not remove Read while you are removing Enroll.
05 Take Enroll off everyone below Tier 0
Remove the Enroll and AutoEnroll ACEs, and any "Create all child objects" style delegation that implies them, from every principal that is not Tier 0. Keep the right with the identity team on a small number of dedicated OUs, and log every use. There is no tidy one-liner; it is an ACL review, and BloodHound, PingCastle or your IAM tooling will get you the list.
Two things people miss. Nested group membership means the ACE you deleted is not always the ACE that grants the right, and scanners differ in whether they expand groups, so a clean scan is not proof. And the CA object itself has an Enroll right which is separate from the template's; a principal needs both to get a certificate, so scoping only the template leaves half the job done.
06 Do not reach for manager approval first
Locksmith's default fix for ESC2 is to set msPKI-Enrollment-Flag to 2, which is CT_FLAG_PEND_ALL_REQUESTS, and it warns you before it does it: this change could cause some services to stop working until certificates are approved. Its author is blunter in the walkthrough, and right: on a template that gets certificates created from it frequently, you are going to break stuff, and it is much better to tightly scope who can actually request that certificate.
The worst field report I have is a template set to require manager approval, discovered not to be handing out certificates to users on mobile devices, and fixed. By then there were 140,000 pending requests on the intermediate CA. The cleanup was a database backup, certutil -deleterow for the denied and expired rows, and esentutl /d to defragment: the EDB went from 1.2GB to 33MB, and C:\Windows\System32\CertLog from 12,000 log files to 240.
There are two reasons a pending queue strands. Autoenrollment is poll-based, and retrieving an approved request depends on a GPO option that is easy to leave off, "Renew expired certificates, update pending certificates, and remove revoked certificates" under Certificate Services Client. And if you try to exempt renewals by setting "Valid existing certificate" so they skip approval, it does not work for computer templates: Crypt32 documented that the CA fails with a bad renewal name because the UPN is not available for a machine account, falls back to an initial request, and puts it in pending. No workaround.
Use approval on low-volume templates where a human reviews the request, and tight ACLs on anything autoenrolled at scale. Microsoft's own guidance starts with restricting the template's permissions and treats approval as an extra mitigation, which is the right order. Locksmith starts with approval, which is the pragmatic order for a scanner that cannot know your enrolment volume. Know which one you are following and why.
07 Restrict the agents, then revoke the licences already out there
The CA-level control neuters the second half of the chain, and its default is unrestricted. In the Certification Authority console, right-click the CA, Properties, Enrollment Agents tab, "Restrict enrollment agents", then scope the agents to specific templates and specific target principals. It is available from Windows Server 2008 onward and under-used, because it is buried and nothing breaks until an agent needs to enrol outside its scope.
Then deal with what you have already issued. Any agent certificate issued from the Any Purpose template before the fix is still valid, and the CA default will still accept it. Fixing the template does not recall the licence.
certutil -revoke <serial>
certutil -crl Then force the domain controllers off their cached CRL with certutil -setreg chain\ChainCacheResyncFiletime @now on each DC, or you are waiting on cache expiry rather than on the CRL.
Be careful about how much containment you claim from that. I have seen it stated on both the offensive and defensive side that the KDC does not check revocation during PKINIT by default, so revoking a stolen authentication certificate does little; the Certipy wiki says something narrower, that the KDC typically checks for the presence of a CDP but may not validate the CRL at initial TGT issuance. I could not find a Microsoft statement either way. The defensible position is that revocation is not reliable containment for a stolen authentication certificate, so treat any agent certificate you cannot account for as a compromised identity: reset the account, disable it where you can, and rotate what it could reach.
08 Force the fleet off the old template
If the template is still in use, get the estate onto the corrected version deliberately rather than waiting for renewal: Reenroll All Certificate Holders on the template, or delete the old certificates and let autoenrollment replace them. Watch the CA's 4887 volume while it happens, because a reissue wave is exactly when a broken EKU shows up as a support queue.
KB5014754 taught the same lesson the hard way. Short validity plus working autoenrollment turns a two-year problem into a six-week one, and nothing else in the design makes the next certificate incident that cheap.
09 Turn on the telemetry you will need next time
The commands are in Detection: CA\AuditFilter at 127, EDITF_AUDITCERTTEMPLATELOAD, the Certification Services subcategory, and a SACL on the templates container. None of it stops the attack. All of it is what tells you it happened, and the audit gap is the most common finding in this area by a wide margin.
The other three habits are what separates the estates that have no fire from the ones that do. A template register with an owner and a consumer list. A duplicate of the template to test on before you change the live one, because a published template change takes effect for new requests across the forest after replication. And a deliberately small published list, since default templates sit in the configuration partition because AD CS installed them, not because anybody asked, and anyone who can add a template to a CA's issued list can publish one in two clicks.
06 Verification
Fixed? Let's prove it rather than assume it. Start with the attacker's check:
certipy find -u '<user>@<domain>' -p '<password>' -dc-ip <DC_IP> -vulnerable -stdoutESC2 should be gone. ESC3 may still appear if you kept a legitimate Certificate Request Agent template, which is fine and expected; an agent template that is properly scoped, approved and restricted is not a finding. What you are looking for is the absence of Any Purpose on a template low-privileged users can enrol in.
Then your own query from Detection, because it reads both attributes:
@($t.pKIExtendedKeyUsage) + @($t.'msPKI-Certificate-Application-Policy') |
Select-Object -Unique Expect the narrow list you set, in both attributes, with no 2.5.29.37.0 anywhere. If the two attributes disagree, your fix has not landed, whatever the console shows.
The lab test, if you want to prove the chain is broken end to end: take a sacrificial agent certificate from before the fix, or issue one in a lab from the old template, and try the on-behalf-of request against the target template you identified.
certipy req -u '<user>' -p '<password>' -ca '<CA>' -template '<target>' \
-on-behalf-of '<domain>\Administrator' -pfx agent.pfxPost-fix, the request should be denied, or the CA should refuse the agent signature. Pre-fix, you get a certificate naming the target, which is the punchline you do not want on a Friday. Do this in a lab.
Then look backwards for a week. On the CA, 4887 rows where the requester and the certificate subject differ; on the DCs, 4768 rows with a populated certificate issuer and a target user you would not expect to be logging on with a certificate. And on every CA, the published list, because step two changed it and replication is not instant.
Get-WinEvent -FilterHashtable @{LogName='Security'; Id=4768; StartTime=(Get-Date).AddDays(-7)} |
Where-Object { $_.ToXml() -match '<Data Name="CertIssuerName">[^<]+' } |
Select-Object TimeCreated, MessageEmpty fields mean a password logon. Anything with an issuer and a serial, from an account that does not normally use a certificate, needs a name and a ticket number.
07 Rollback
The realistic rollback is "the VPN broke", not "the patch broke", because there is no patch to uninstall. Work out which change caused it before undoing anything, and undo one thing.
If you narrowed an EKU and an application stopped, add the specific EKU the application needs. Do not restore Any Purpose. If the application genuinely needs to be valid for everything, that is a conversation with the vendor and an entry in the risk register, not a configuration to put back at 2am.
$t = Get-ADObject "CN=<template>,CN=Certificate Templates,$pks" `
-Properties nTSecurityDescriptor
$acl = Get-Acl "AD:\CN=<template>,CN=Certificate Templates,$pks"
$acl.SetSecurityDescriptorSddlForm((Get-Content ".\<template>-acl-backup.txt"))
Set-Acl "AD:\CN=<template>,CN=Certificate Templates,$pks" $aclThat restores the rights you exported in step one. Re-run the scans afterwards, because the exposure comes straight back and you want it in the change record, not in a surprise.
Republishing is one flag:
certutil -SetCATemplates +<templateInternalName>Wait for the poll window or restart Certificate Services. Enrollment may not resume immediately; replication, service state and the template's permissions all have a say.
If you enabled manager approval and stranded a queue, the recovery is not to turn it off and forget it. Check the autoenrollment GPO option for pending certificate retrieval, use certreq -retrieve for the requests that matter, and then clean the database; a hundred thousand rows will grow the EDB. If the queue is large, do the backup and esentutl /d dance in a maintenance window, and tell the service desk what the approval prompts are for before they start arriving.
If you revoked a certificate that turned out to be legitimate, you cannot un-revoke it. Reissue from the corrected template, scoped to the account that needs it, and treat the incident as a lesson in why the agent inventory should have existed first. And if you deleted a template object that was in use, restore it from the AD Recycle Bin if it is enabled, republish, and check the CA's published list for an orphan entry.
08 References
- SpecterOps: Certified Pre-Owned, Abusing Active Directory Certificate Services
- SpecterOps: Certified Pre-Owned whitepaper
- SpecterOps: AD CS attack paths in BloodHound, part 1 (EKU precedence)
- SpecterOps: AD CS attack paths in BloodHound, part 2
- ly4k: Certipy privilege escalation wiki
- ly4k: Certipy, find.py
- ly4k: Certipy issue 178, Enabled: False
- ly4k: Certipy issue 92, KDC_ERR_INCONSISTENT_KEY_PURPOSE
- GhostPack: Certify escalation techniques
- GhostPack: PSPKIAudit
- Trimarc: Locksmith
- Microsoft: Defender for Identity certificate posture assessments
- Microsoft: manage certificate templates
- Microsoft: KB5014754, certificate-based authentication changes on domain controllers
- Microsoft: strong certificate name mapping in Active Directory
- Microsoft: MS-CRTD, certificate template attributes
- Microsoft: MS-WCCE, certificate request processing
- Microsoft: MS-PKCA, PKINIT certificate mapping
- Microsoft: event 4768
- Microsoft: event 4624
- Microsoft: event 5136
- Microsoft: Audit Certification Services
- Microsoft: Securing PKI, monitoring public key infrastructure)
- Microsoft: Securing PKI appendix B, CA audit filter)
- Microsoft: certutil reference
- Microsoft: NPS and certificate EKU requirements)
- Microsoft: Cloud PKI certificate authority configuration
- Cisco: ISE SAML certificate requirements
- Richard Hicks: Always On VPN certificate requirements for IKEv2
- Richard Hicks: strong certificate mapping enforcement, February 2025
- insightrecon: AD CS ESC2
- truvald: ESC2 detection, a defender's guide
- Active Directory Hardening: AD CS template audit
- The Backroom Tech: auditing AD CS certificate templates (ESC1 to ESC8)
- Tenaka: AD CS says certificate template not supported
- d4ni: AD CS orphans
- Chrisse: EKUs supplied in the request
- Byron Wright: certificate template versions
- Antisyphon: AD CS issues with Locksmith
- ServerFault: autoenrollment with manager approval for re-enrollment
- r/PKI: ADCS, deny all pending
- r/sysadmin: certificate revocation, ADCS
- r/sysadmin: AD CS certificate template security
- Sigma: ADCS certificate template configuration vulnerability, risky EKU
- Splunk Security Content: Windows Steal Authentication Certificates, ESC1 abuse
- BloodHound: ADCS ESC4 edge
If I've got anything wrong here, or you've hit an edge case I haven't covered, do say, corrections and questions are always welcome :) The EKU precedence trap in particular is the kind of thing that changes upstream, so if a scanner has fixed it, I would love to know.
Ship the fix. Prove it’s closed.
If this runbook doesn’t fit your stack, send the CVE — an operator writes a verified path, usually within a business day. Or contribute your own and get co-authored credit.