ADCS-007: ESC4 - Vulnerable Certificate Template Ownership
- Platform
- Active Directory
- Category
- AD Certificate Services
- Severity
- Critical
- Zero Trust pillar
- Identity (weight 3)
- Golden fixtures
- 3
- Branch coverage
- Observed: fixtures prove the verdicts they exercise
- Provenance
- baseline
What it checks
For every pKICertificateTemplate object under CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=forestRoot, the check reads the nTSecurityDescriptor attribute via LDAP and inspects the Owner field of the security descriptor. The Owner is resolved to an NTAccount and compared against an allowlist of accepted Tier 0 / PKI principals: - Enterprise Admins (S-1-5-21-<forestRoot>-519) - Domain Admins of the forest root (S-1-5-21-<forestRoot>-512) - BUILTIN\Administrators (S-1-5-32-544) - SYSTEM (S-1-5-18) - A configurable PKI administration group passed via -PkiAdminGroup Any template whose Owner SID falls outside that set is reported as a finding. The check also captures the OID, displayName, msPKI-Certificate-Name-Flag, msPKI-Enrollment-Flag, pKIExtendedKeyUsage, and the list of CAs that currently publish the template (read from the certificateTemplates attribute on each CN=<CA>,CN=Enrollment Services object) so triage can assess whether the template is published and therefore live-exploitable.
Why it matters
In Active Directory, the Owner of an object can modify its DACL at any time via the implicit WriteDacl + WriteOwner rights granted to owners. That means template ownership is functionally equivalent to GenericAll on the template. A non-admin owner can, in a single session, add an Allow-FullControl ACE for themselves, flip the template to mark CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT, add the Client Authentication EKU, lower the enrollment requirement so that Authenticated Users or a low-privileged group can enroll, and remove the manager-approval flag. The template is now an ESC1 primitive: the attacker requests a certificate, supplies an arbitrary Subject Alternative Name such as the UPN of a Domain Admin, and uses the resulting certificate to obtain a Kerberos TGT for that account via PKINIT. Because the rogue template is published forest-wide through the Configuration NC, the primitive works against every domain in the forest, not just the domain where the attacker started. Ownership drift on a single template is therefore a forest-takeover primitive that survives password resets of the compromised principal.
Attack path
1. Discovery: the attacker runs certipy find -u user@corp.local -p Pass -dc-ip 10.0.0.10 -vulnerable, or Certify.exe find /vulnerable, which enumerates every template, resolves the Owner SID, and reports ESC4 candidates where the current principal owns a template. 2. ACL pivot: with ownership, the attacker grants themselves FullControl on the template object: certipy template -u user@corp.local -p Pass -template VulnTemplate -save-old (Certipy serializes the original config so it can restore it later). 3. Template weaponization: certipy template -template VulnTemplate -write-default-configuration. This rewrites the template to a known ESC1 shape: msPKI-Certificate-Name-Flag includes CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT (0x1), msPKI-Enrollment-Flag clears CT_FLAG_PEND_ALL_REQUESTS, pKIExtendedKeyUsage includes 1.3.6.1.5.5.7.3.2 (Client Authentication), and the template DACL grants Enroll to Authenticated Users. 4. Enrollment: certipy req -u user@corp.local -p Pass -ca CORP-CA -template VulnTemplate -upn administrator@corp.local. The CA issues a certificate whose SAN claims administrator@corp.local. 5. Authentication: certipy auth -pfx administrator.pfx -domain corp.local. The attacker performs PKINIT, receives a TGT for administrator, and dumps the NTLM hash from the PAC (PKINIT returns the NT hash in the PAC_CREDENTIAL_INFO buffer on patched DCs that did not receive the May 2022 / KB5014754 hardening configuration). 6. Persistence and cleanup: certipy template -template VulnTemplate -configuration old-config.json restores the original template definition so a casual diff against a baseline shows no change. The attacker retains the issued certificate, which remains valid for the template lifetime (typically one year) regardless of the password the targeted account uses.
How Guerrilla assesses it
Guerrilla binds to the forest RootDSE, resolves the configurationNamingContext, and enumerates pKICertificateTemplate objects under CN=Certificate Templates,CN=Public Key Services,CN=Services,<configNC>. For each template it requests the nTSecurityDescriptor with the OWNER_SECURITY_INFORMATION control bit set, then reads the OwnerSid from the resulting RawSecurityDescriptor. The SID is translated to an NTAccount via the local DC, and templates whose owner is not in the Tier 0 allowlist are reported. The check also walks the DACL for any ACE granting WriteDacl, WriteOwner, WriteProperty, or GenericAll / GenericWrite to non-Tier 0 principals (the ACL surface of ESC4 is broader than ownership alone), and cross-references the template name against the certificateTemplates multi-valued attribute on each CN=<CA>,CN=Enrollment Services,CN=Public Key Services,CN=Services,<configNC> object so the report indicates whether the template is currently published.
Recommended value
All certificate template objects owned by Enterprise Admins or designated PKI administrators
Remediation
Check the Owner field on every certificate template object in CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration. Transfer ownership of any incorrectly owned templates to Enterprise Admins using Set-Acl or the Security tab in adsiedit.msc. Investigate how non-admin accounts became owners to prevent recurrence.
Fixture-proven verdicts
Every verdict below is proven by a golden fixture in the module's gating test suite. This table derives from the last green run; it cannot be edited by hand.
| Scenario | Expected verdict |
|---|---|
| clean | PASS |
| known-bad | FAIL |
| throttled | Not Assessed |
Framework mappings
- NIST SP 800-53
- AC-6, AC-3
- ANSSI
- vuln_adcs_esc4
- MITRE ATT&CK
- T1649, T1222.001