SSH Public Key Acceptance Scanner - Metasploit


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

Module Overview


Name: SSH Public Key Acceptance Scanner
Module: auxiliary/scanner/ssh/ssh_identify_pubkeys
Source code: modules/auxiliary/scanner/ssh/ssh_identify_pubkeys.rb
Disclosure date: -
Last modification time: 2018-08-15 14:59:52 +0000
Supported architecture(s): -
Supported platform(s): -
Target service / protocol: -
Target network port(s): 22
List of CVEs: -

This module can determine what public keys are configured for key-based authentication across a range of machines, users, and sets of known keys. The SSH protocol indicates whether a particular key is accepted prior to the client performing the actual signed authentication request. To use this module, a text file containing one or more SSH keys should be provided. These can be private or public, so long as no passphrase is set on the private keys. If you have loaded a database plugin and connected to a database this module will record authorized public keys and hosts so you can track your process. Key files may be a single public (unencrypted) key, or several public keys concatenated together as an ASCII text file. Non-key data should be silently ignored. Private keys will only utilize the public key component stored within the key file.

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/ssh_identify_pubkeys
msf auxiliary(ssh_identify_pubkeys) > show options
    ... show and set options ...
msf auxiliary(ssh_identify_pubkeys) > set RHOSTS ip-range
msf auxiliary(ssh_identify_pubkeys) > exploit

Other examples of setting the RHOSTS option:

Example 1:

msf auxiliary(ssh_identify_pubkeys) > set RHOSTS 192.168.1.3-192.168.1.200 

Example 2:

msf auxiliary(ssh_identify_pubkeys) > set RHOSTS 192.168.1.1/24

Example 3:

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

Required Options


  • KEY_FILE: Filename of one or several cleartext public keys.

Go back to menu.

Msfconsole Usage


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

msf6 > use auxiliary/scanner/ssh/ssh_identify_pubkeys

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

       Name: SSH Public Key Acceptance Scanner
     Module: auxiliary/scanner/ssh/ssh_identify_pubkeys
    License: Metasploit Framework License (BSD)
       Rank: Normal

Provided by:
  todb <[email protected]>
  hdm <[email protected]>
  Stuart Morgan <[email protected]>

Check supported:
  No

Basic options:
  Name              Current Setting  Required  Description
  ----              ---------------  --------  -----------
  BRUTEFORCE_SPEED  5                yes       How fast to bruteforce, from 0 to 5
  DB_ALL_USERS      false            no        Add all users in the current database to the list
  KEY_FILE                           yes       Filename of one or several cleartext public keys.
  RPORT             22               yes       The target port
  STOP_ON_SUCCESS   false            yes       Stop guessing when a credential works for a host
  THREADS           1                yes       The number of concurrent threads (max one per host)
  USERNAME                           no        A specific username to authenticate as
  USER_FILE                          no        File containing usernames, one per line
  VERBOSE           true             yes       Whether to print output for all attempts

Description:
  This module can determine what public keys are configured for 
  key-based authentication across a range of machines, users, and sets 
  of known keys. The SSH protocol indicates whether a particular key 
  is accepted prior to the client performing the actual signed 
  authentication request. To use this module, a text file containing 
  one or more SSH keys should be provided. These can be private or 
  public, so long as no passphrase is set on the private keys. If you 
  have loaded a database plugin and connected to a database this 
  module will record authorized public keys and hosts so you can track 
  your process. Key files may be a single public (unencrypted) key, or 
  several public keys concatenated together as an ASCII text file. 
  Non-key data should be silently ignored. Private keys will only 
  utilize the public key component stored within the key file.

Module Options


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

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

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

   Name              Current Setting  Required  Description
   ----              ---------------  --------  -----------
   BRUTEFORCE_SPEED  5                yes       How fast to bruteforce, from 0 to 5
   DB_ALL_USERS      false            no        Add all users in the current database to the list
   KEY_FILE                           yes       Filename of one or several cleartext public keys.
   RPORT             22               yes       The target port
   STOP_ON_SUCCESS   false            yes       Stop guessing when a credential works for a host
   THREADS           1                yes       The number of concurrent threads (max one per host)
   USERNAME                           no        A specific username to authenticate as
   USER_FILE                          no        File containing usernames, one per line
   VERBOSE           true             yes       Whether to print output for all attempts

Advanced Options


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

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

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

   Name                  Current Setting                          Required  Description
   ----                  ---------------                          --------  -----------
   KEY_DIR                                                        no        Directory of several keys. Filenames must not begin with a dot in order to be read.
   MaxGuessesPerService  0                                        no        Maximum number of credentials to try per service instance. If set to zero or a non-number, this option will not be used.
   MaxGuessesPerUser     0                                        no        Maximum guesses for a particular username for the service instance. Note that users are considered unique among different services, so a user at 10.1.1.1:22 is differe
                                                                            nt from one at 10.2.2.2:22, and both will be tried up to the MaxGuessesPerUser limit. If set to zero or a non-number, this option will not be used.
   MaxMinutesPerService  0                                        no        Maximum time in minutes to bruteforce the service instance. If set to zero or a non-number, this option will not be used.
   PASSWORD_SPRAY        false                                    yes       Reverse the credential pairing order. For each password, attempt every possible user.
   REMOVE_PASS_FILE      false                                    yes       Automatically delete the PASS_FILE on module completion
   REMOVE_USERPASS_FILE  false                                    yes       Automatically delete the USERPASS_FILE on module completion
   REMOVE_USER_FILE      false                                    yes       Automatically delete the USER_FILE on module completion
   SSH_BYPASS            false                                    no        Verify that authentication was not bypassed when keys are found
   SSH_DEBUG             false                                    no        Enable SSH debugging output (Extreme verbosity!)
   SSH_IDENT             SSH-2.0-OpenSSH_7.6p1 Ubuntu-4ubuntu0.3  yes       SSH client identification string
   SSH_KEYFILE_B64                                                no        Raw data of an unencrypted SSH public key. This should be used by programmatic interfaces to this module only.
   SSH_TIMEOUT           30                                       no        Specify the maximum time to negotiate a SSH session
   ShowProgress          true                                     yes       Display progress messages during a scan
   ShowProgressPercent   10                                       yes       The interval in percent that progress should be shown
   TRANSITION_DELAY      0                                        no        Amount of time (in minutes) to delay before transitioning to the next user in the array (or password when PASSWORD_SPRAY=true)
   WORKSPACE                                                      no        Specify the workspace for this module

Auxiliary Actions


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

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

Auxiliary actions:

   Name  Description
   ----  -----------

Evasion Options


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

msf6 auxiliary(scanner/ssh/ssh_identify_pubkeys) > 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> SSH - No valid keys found


Here is a relevant code snippet related to the "<IP>:<RPORT> SSH - No valid keys found" error message:

112:	        keys << (this_key.join("\n") + "\n")
113:	        this_key = []
114:	      end
115:	    end
116:	    if keys.empty?
117:	      print_error "#{ip}:#{rport} SSH - No valid keys found"
118:	    end
119:	    return validate_keys(keys)
120:	  end
121:	
122:	  # Validates that the key isn't total garbage, and converts PEM formatted

<IP>:<RPORT> SSH - No valid keys found


Here is a relevant code snippet related to the "<IP>:<RPORT> SSH - No valid keys found" error message:

144:	      next unless key.scan(/[\x00-\x08\x0b\x0c\x0e-\x1f\x80-\xff]/).empty?
145:	      # Add more tests to test
146:	      keepers << { :public => key, :private => "" }
147:	    end
148:	    if keepers.empty?
149:	      print_error "#{ip}:#{rport} SSH - No valid keys found"
150:	    end
151:	    return keepers.uniq
152:	  end
153:	
154:	  def pull_cleartext_keys(keys)

<IP>:<RPORT> SSH - No valid cleartext keys found


Here is a relevant code snippet related to the "<IP>:<RPORT> SSH - No valid cleartext keys found" error message:

159:	      this_key = { :public => key[:public].gsub(/\x0d/,""), :private => key[:private] }
160:	      next if cleartext_keys.include? this_key
161:	      cleartext_keys << this_key
162:	    end
163:	    if cleartext_keys.empty?
164:	      print_error "#{ip}:#{rport} SSH - No valid cleartext keys found"
165:	    end
166:	    return cleartext_keys
167:	  end
168:	
169:	  def do_login(ip, port, user)

User <USER> does not accept key <VALUE> <KEY_INFO>


Here is a relevant code snippet related to the "User <USER> does not accept key <VALUE> <KEY_INFO>" error message:

249:	        return [:fail,nil] # For whatever reason.
250:	      end
251:	
252:	      unless success
253:	        if @key_files
254:	          print_brute :level => :verror, :msg =>  "User #{user} does not accept key #{@key_files[key_idx+1]} #{key_info}"
255:	        else
256:	          print_brute :level => :verror, :msg => "User #{user} does not accept key #{key_idx+1} #{key_info}"
257:	        end
258:	        return [:fail,nil]
259:	      end

User <USER> does not accept key <VALUE> <KEY_INFO>


Here is a relevant code snippet related to the "User <USER> does not accept key <VALUE> <KEY_INFO>" error message:

251:	
252:	      unless success
253:	        if @key_files
254:	          print_brute :level => :verror, :msg =>  "User #{user} does not accept key #{@key_files[key_idx+1]} #{key_info}"
255:	        else
256:	          print_brute :level => :verror, :msg => "User #{user} does not accept key #{key_idx+1} #{key_info}"
257:	        end
258:	        return [:fail,nil]
259:	      end
260:	
261:	      key = verifier.key

<IP>:<RPORT> SSH - Could not connect


Here is a relevant code snippet related to the "<IP>:<RPORT> SSH - Could not connect" error message:

369:	    # for all users.
370:	    each_user_pass do |user,pass|
371:	      ret, _ = do_login(ip, rport, user)
372:	      case ret
373:	      when :connection_error
374:	        vprint_error "#{ip}:#{rport} SSH - Could not connect"
375:	        :abort
376:	      when :connection_disconnect
377:	        vprint_error "#{ip}:#{rport} SSH - Connection timed out"
378:	        :abort
379:	      when :fail

<IP>:<RPORT> SSH - Connection timed out


Here is a relevant code snippet related to the "<IP>:<RPORT> SSH - Connection timed out" error message:

372:	      case ret
373:	      when :connection_error
374:	        vprint_error "#{ip}:#{rport} SSH - Could not connect"
375:	        :abort
376:	      when :connection_disconnect
377:	        vprint_error "#{ip}:#{rport} SSH - Connection timed out"
378:	        :abort
379:	      when :fail
380:	        vprint_error "#{ip}:#{rport} SSH - Failed: '#{user}'"
381:	      when :missing_keyfile
382:	        vprint_error "#{ip}:#{rport} SSH - Cannot read keyfile"

<IP>:<RPORT> SSH - Failed: '<USER>'


Here is a relevant code snippet related to the "<IP>:<RPORT> SSH - Failed: '<USER>'" error message:

375:	        :abort
376:	      when :connection_disconnect
377:	        vprint_error "#{ip}:#{rport} SSH - Connection timed out"
378:	        :abort
379:	      when :fail
380:	        vprint_error "#{ip}:#{rport} SSH - Failed: '#{user}'"
381:	      when :missing_keyfile
382:	        vprint_error "#{ip}:#{rport} SSH - Cannot read keyfile"
383:	      when :no_valid_keys
384:	        vprint_error "#{ip}:#{rport} SSH - No readable keys in keyfile"
385:	      end

<IP>:<RPORT> SSH - Cannot read keyfile


Here is a relevant code snippet related to the "<IP>:<RPORT> SSH - Cannot read keyfile" error message:

377:	        vprint_error "#{ip}:#{rport} SSH - Connection timed out"
378:	        :abort
379:	      when :fail
380:	        vprint_error "#{ip}:#{rport} SSH - Failed: '#{user}'"
381:	      when :missing_keyfile
382:	        vprint_error "#{ip}:#{rport} SSH - Cannot read keyfile"
383:	      when :no_valid_keys
384:	        vprint_error "#{ip}:#{rport} SSH - No readable keys in keyfile"
385:	      end
386:	    end
387:	  end

<IP>:<RPORT> SSH - No readable keys in keyfile


Here is a relevant code snippet related to the "<IP>:<RPORT> SSH - No readable keys in keyfile" error message:

378:	        :abort
379:	      when :fail
380:	        vprint_error "#{ip}:#{rport} SSH - Failed: '#{user}'"
381:	      when :missing_keyfile
382:	        vprint_error "#{ip}:#{rport} SSH - Cannot read keyfile"
383:	      when :no_valid_keys
384:	        vprint_error "#{ip}:#{rport} SSH - No readable keys in keyfile"
385:	      end
386:	    end
387:	  end
388:	end

Go back to menu.


Go back to menu.

See Also


Check also the following modules related to this module:

Authors


  • todb
  • hdm
  • Stuart Morgan <stuart.morgan[at]mwrinfosecurity.com>

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.