diff --git a/documentation/modules/auxiliary/scanner/ssh/ssh_version.md b/documentation/modules/auxiliary/scanner/ssh/ssh_version.md index 6d0e293a35bf..9d1172576c01 100644 --- a/documentation/modules/auxiliary/scanner/ssh/ssh_version.md +++ b/documentation/modules/auxiliary/scanner/ssh/ssh_version.md @@ -1,10 +1,11 @@ -## Description - -SSH, Secure SHell, is an encrypted network protocol used to remotely interact with an Operating System at a command line level. SSH is available on most every system, including Windows, but is mainly used by *nix administrators. +## Vulnerable Application -This module identifies the version of SSH service in use by the server based on the server's banner. Any SSH server should return this information. +SSH, Secure SHell, is an encrypted network protocol used to remotely interact with an Operating System at a command line level. +SSH is available on most every system, including Windows, but is mainly used by *nix administrators. -## Vulnerable Application +This module identifies the version of SSH service in use by the server based on the server's banner. +Any SSH server should return this information. It also identifies the varous cryptographic settings +and vulnerabilities associated with those. This module is tested on several different SSH services, such as: @@ -12,23 +13,248 @@ This module is tested on several different SSH services, such as: - `github.com`: SSH-2.0-babeld-38be96bc - `gitlab.com`: SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.8 +### Vulnerable Ubuntu 14.04.1 + +The following `Dockerfile` can be used to create an Ubuntu 14.04.1 image with SSH running. + +``` +FROM ubuntu:14.04.1 + +RUN apt-get update && apt-get -y install --no-install-recommends openssh-server=1:6.6p1-2ubuntu1 openssh-client=1:6.6p1-2ubuntu1 openssh-sftp-server=1:6.6p1-2ubuntu1 +RUN mkdir /var/run/sshd +EXPOSE 22 + +CMD ["/usr/sbin/sshd","-D"] +``` + ## Verification Steps 1. Do: `use auxiliary/scanner/ssh/ssh_version` 2. Do: `set rhosts [ips]` 3. Do: `run` +## Options + +### EXTENDED_CHECKS + +Check for cryptographic issues. Defaults to `true` + ## Scenarios ### SSH-2.0 on GitHub - ``` -msf5 auxiliary(scanner/ssh/ssh_version) > use auxiliary/scanner/ssh/ssh_version +``` +msf5 > use auxiliary/scanner/ssh/ssh_version msf5 auxiliary(scanner/ssh/ssh_version) > set RHOSTS github.com RHOSTS => github.com msf5 auxiliary(scanner/ssh/ssh_version) > run -[+] 140.82.118.4:22 - SSH server version: SSH-2.0-babeld-38be96bc -[*] github.com:22 - Scanned 1 of 1 hosts (100% complete) +[*] 140.82.113.4 - Key Fingerprint: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIOMqqnkVzrm0SdG6UOoqKLsabgH5C9okWi0dh2l9GKJl +[*] 140.82.113.4 - SSH server version: SSH-2.0-babeld-8405f9f3 +[*] 140.82.113.4 - Server Information and Encryption +================================= + + Type Value Note + ---- ----- ---- + encryption.compression none + encryption.compression zlib@openssh.com + encryption.compression zlib + encryption.encryption chacha20-poly1305@openssh.com + encryption.encryption aes256-gcm@openssh.com + encryption.encryption aes128-gcm@openssh.com + encryption.encryption aes256-ctr + encryption.encryption aes192-ctr + encryption.encryption aes128-ctr + encryption.hmac hmac-sha2-512-etm@openssh.com + encryption.hmac hmac-sha2-256-etm@openssh.com + encryption.hmac hmac-sha2-512 + encryption.hmac hmac-sha2-256 + encryption.host_key ssh-ed25519 + encryption.host_key ecdsa-sha2-nistp256 Weak elliptic curve + encryption.host_key rsa-sha2-512 + encryption.host_key rsa-sha2-256 + encryption.host_key ssh-rsa + encryption.key_exchange curve25519-sha256 + encryption.key_exchange curve25519-sha256@libssh.org + encryption.key_exchange ecdh-sha2-nistp256 + encryption.key_exchange ecdh-sha2-nistp384 + encryption.key_exchange ecdh-sha2-nistp521 + encryption.key_exchange diffie-hellman-group-exchange-sha256 + encryption.key_exchange kex-strict-s-v00@openssh.com + +[*] Scanned 1 of 1 hosts (100% complete) +[*] Auxiliary module execution completed +``` + +### Docker image + +``` +msf5 > use auxiliary/scanner/ssh/ssh_version +msf6 auxiliary(scanner/ssh/ssh_version) > set rhosts 172.17.0.2 +rhosts => 172.17.0.2 +msf6 auxiliary(scanner/ssh/ssh_version) > set verbose true +verbose => true +msf6 auxiliary(scanner/ssh/ssh_version) > run + +[*] 172.17.0.2 - Key Fingerprint: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIG52hWkobwr57akGxiK6eeMN9/M5MH+sQsNPv8Mci049 +[*] 172.17.0.2 - SSH server version: SSH-2.0-OpenSSH_6.6p1 Ubuntu-2ubuntu1 +[+] 172.17.0.2 - Key Exchange (kex) diffie-hellman-group-exchange-sha1 is deprecated and should not be used. +[+] 172.17.0.2 - Key Exchange (kex) diffie-hellman-group1-sha1 is deprecated and should not be used. +[+] 172.17.0.2 - Host Key Encryption ecdsa-sha2-nistp256 uses a weak elliptic curve and should not be used. +[+] 172.17.0.2 - HMAC hmac-md5 is deprecated and should not be used. +[+] 172.17.0.2 - HMAC hmac-ripemd160 is deprecated and should not be used. +[+] 172.17.0.2 - HMAC hmac-sha1-96 is deprecated and should not be used. +[+] 172.17.0.2 - HMAC hmac-md5-96 is deprecated and should not be used. +[+] 172.17.0.2 - Encryption arcfour256 is deprecated and should not be used. +[+] 172.17.0.2 - Encryption arcfour128 is deprecated and should not be used. +[+] 172.17.0.2 - Encryption aes128-cbc is deprecated and should not be used. +[+] 172.17.0.2 - Encryption 3des-cbc is deprecated and should not be used. +[+] 172.17.0.2 - Encryption blowfish-cbc is deprecated and should not be used. +[+] 172.17.0.2 - Encryption cast128-cbc is deprecated and should not be used. +[+] 172.17.0.2 - Encryption aes192-cbc is deprecated and should not be used. +[+] 172.17.0.2 - Encryption aes256-cbc is deprecated and should not be used. +[+] 172.17.0.2 - Encryption arcfour is deprecated and should not be used. +[+] 172.17.0.2 - Encryption rijndael-cbc@lysator.liu.se is deprecated and should not be used. +[*] 172.17.0.2 - Server Information and Encryption +================================= + + Type Value Note + ---- ----- ---- + encryption.compression none + encryption.compression zlib@openssh.com + encryption.encryption aes128-ctr + encryption.encryption aes192-ctr + encryption.encryption aes256-ctr + encryption.encryption arcfour256 Deprecated + encryption.encryption arcfour128 Deprecated + encryption.encryption aes128-gcm@openssh.com + encryption.encryption aes256-gcm@openssh.com + encryption.encryption chacha20-poly1305@openssh.com + encryption.encryption aes128-cbc Deprecated + encryption.encryption 3des-cbc Deprecated + encryption.encryption blowfish-cbc Deprecated + encryption.encryption cast128-cbc Deprecated + encryption.encryption aes192-cbc Deprecated + encryption.encryption aes256-cbc Deprecated + encryption.encryption arcfour Deprecated + encryption.encryption rijndael-cbc@lysator.liu.se Deprecated + encryption.hmac hmac-md5-etm@openssh.com + encryption.hmac hmac-sha1-etm@openssh.com + encryption.hmac umac-64-etm@openssh.com + encryption.hmac umac-128-etm@openssh.com + encryption.hmac hmac-sha2-256-etm@openssh.com + encryption.hmac hmac-sha2-512-etm@openssh.com + encryption.hmac hmac-ripemd160-etm@openssh.com + encryption.hmac hmac-sha1-96-etm@openssh.com + encryption.hmac hmac-md5-96-etm@openssh.com + encryption.hmac hmac-md5 Deprecated + encryption.hmac hmac-sha1 + encryption.hmac umac-64@openssh.com + encryption.hmac umac-128@openssh.com + encryption.hmac hmac-sha2-256 + encryption.hmac hmac-sha2-512 + encryption.hmac hmac-ripemd160 Deprecated + encryption.hmac hmac-ripemd160@openssh.com + encryption.hmac hmac-sha1-96 Deprecated + encryption.hmac hmac-md5-96 Deprecated + encryption.host_key ssh-rsa + encryption.host_key ssh-dss + encryption.host_key ecdsa-sha2-nistp256 Weak elliptic curve + encryption.host_key ssh-ed25519 + encryption.key_exchange curve25519-sha256@libssh.org + encryption.key_exchange ecdh-sha2-nistp256 + encryption.key_exchange ecdh-sha2-nistp384 + encryption.key_exchange ecdh-sha2-nistp521 + encryption.key_exchange diffie-hellman-group-exchange-sha256 + encryption.key_exchange diffie-hellman-group-exchange-sha1 Deprecated + encryption.key_exchange diffie-hellman-group14-sha1 + encryption.key_exchange diffie-hellman-group1-sha1 Deprecated + fingerprint_db ssh.banner + openssh.comment Ubuntu-2ubuntu1 + os.cpe23 cpe:/o:canonical:ubuntu_linux:14.04 + os.family Linux + os.product Linux + os.vendor Ubuntu + os.version 14.04 + service.cpe23 cpe:/a:openbsd:openssh:6.6p1 + service.family OpenSSH + service.product OpenSSH + service.protocol ssh + service.vendor OpenBSD + service.version 6.6p1 + +[*] Scanned 1 of 1 hosts (100% complete) [*] Auxiliary module execution completed - ``` +``` + +## Confirming using NMAP + +Utilizing the [ssh2-enum-algos](https://nmap.org/nsedoc/scripts/ssh2-enum-algos.html) NMAP script. + +``` +Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-01-11 14:55 EST +Nmap scan report for 172.17.0.2 +Host is up (0.000099s latency). + +PORT STATE SERVICE VERSION +22/tcp open ssh OpenSSH 6.6p1 Ubuntu 2ubuntu1 (Ubuntu Linux; protocol 2.0) +| ssh2-enum-algos: +| kex_algorithms: (8) +| curve25519-sha256@libssh.org +| ecdh-sha2-nistp256 +| ecdh-sha2-nistp384 +| ecdh-sha2-nistp521 +| diffie-hellman-group-exchange-sha256 +| diffie-hellman-group-exchange-sha1 +| diffie-hellman-group14-sha1 +| diffie-hellman-group1-sha1 +| server_host_key_algorithms: (4) +| ssh-rsa +| ssh-dss +| ecdsa-sha2-nistp256 +| ssh-ed25519 +| encryption_algorithms: (16) +| aes128-ctr +| aes192-ctr +| aes256-ctr +| arcfour256 +| arcfour128 +| aes128-gcm@openssh.com +| aes256-gcm@openssh.com +| chacha20-poly1305@openssh.com +| aes128-cbc +| 3des-cbc +| blowfish-cbc +| cast128-cbc +| aes192-cbc +| aes256-cbc +| arcfour +| rijndael-cbc@lysator.liu.se +| mac_algorithms: (19) +| hmac-md5-etm@openssh.com +| hmac-sha1-etm@openssh.com +| umac-64-etm@openssh.com +| umac-128-etm@openssh.com +| hmac-sha2-256-etm@openssh.com +| hmac-sha2-512-etm@openssh.com +| hmac-ripemd160-etm@openssh.com +| hmac-sha1-96-etm@openssh.com +| hmac-md5-96-etm@openssh.com +| hmac-md5 +| hmac-sha1 +| umac-64@openssh.com +| umac-128@openssh.com +| hmac-sha2-256 +| hmac-sha2-512 +| hmac-ripemd160 +| hmac-ripemd160@openssh.com +| hmac-sha1-96 +| hmac-md5-96 +| compression_algorithms: (2) +| none +|_ zlib@openssh.com +Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel + +Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . +Nmap done: 1 IP address (1 host up) scanned in 0.22 seconds +``` diff --git a/modules/auxiliary/scanner/ssh/ssh_version.rb b/modules/auxiliary/scanner/ssh/ssh_version.rb index fc4397eb3cbf..368b52365a49 100644 --- a/modules/auxiliary/scanner/ssh/ssh_version.rb +++ b/modules/auxiliary/scanner/ssh/ssh_version.rb @@ -4,96 +4,275 @@ ## require 'recog' +require 'net/ssh/transport/session' class MetasploitModule < Msf::Auxiliary - include Msf::Exploit::Remote::Tcp include Msf::Auxiliary::Scanner include Msf::Auxiliary::Report - # the default timeout (in seconds) to wait, in total, for both a successful - # connection to a given endpoint and for the initial protocol response - # from the supposed SSH endpoint to be returned - DEFAULT_TIMEOUT = 30 - def initialize super( - 'Name' => 'SSH Version Scanner', - 'Description' => 'Detect SSH Version.', - 'References' => - [ - [ 'URL', 'https://en.wikipedia.org/wiki/SecureShell' ] - ], - 'Author' => [ 'Daniel van Eeden ' ], - 'License' => MSF_LICENSE + 'Name' => 'SSH Version Scanner', + 'Description' => 'Detect SSH Version, and the server encryption', + 'References' => [ + ['URL', 'https://en.wikipedia.org/wiki/SecureShell'], # general info + ['URL', 'https://datatracker.ietf.org/doc/html/rfc8732#name-deprecated-algorithms'], # deprecation of kex gss-sha1 stuff + ['URL', 'https://datatracker.ietf.org/doc/html/draft-ietf-curdle-ssh-kex-sha2-20#page-16'], # diffie-hellman-group-exchange-sha1, diffie-hellman-group1-sha1, rsa1024-sha1 + ['URL', 'https://datatracker.ietf.org/doc/html/rfc8758#name-iana-considerations'], # arc4 deprecation + ['URL', 'https://github.com/net-ssh/net-ssh?tab=readme-ov-file#supported-algorithms'], # a bunch of diff removed things from the ruby lib + ['CVE', '2008-5161'] # CBC modes + ], + 'Author' => [ + 'Daniel van Eeden ', # original author + 'h00die' # algorithms enhancements + ], + 'License' => MSF_LICENSE ) register_options( [ Opt::RPORT(22), - OptInt.new('TIMEOUT', [true, 'Timeout for the SSH probe', DEFAULT_TIMEOUT]) + OptInt.new('TIMEOUT', [true, 'Timeout for the SSH probe', 30]), + OptBool.new('EXTENDED_CHECKS', [true, 'Check for cryptographic issues', true]) ], self.class ) end def timeout - datastore['TIMEOUT'] <= 0 ? DEFAULT_TIMEOUT : datastore['TIMEOUT'] + datastore['TIMEOUT'] end - def run_host(target_host) - ::Timeout.timeout(timeout) do - connect + def rport + datastore['RPORT'] + end - resp = sock.get_once(-1, timeout) + def perform_recog(ident) + table = [] + recog_info = [] + if /^SSH-\d+\.\d+-(.*)$/ =~ ident + recog_match = Recog::Nizer.match('ssh.banner', ::Regexp.last_match(1)) + if recog_match + recog_match.each_pair do |k, v| + next if k == 'matched' - if ! resp - vprint_warning("No response") - return Exploit::CheckCode::Unknown + recog_info << "#{k}: #{v}" + end end + end - ident, first_message = resp.split(/[\r\n]+/) - info = "" + return table if recog_info.empty? - if /^SSH-\d+\.\d+-(.*)$/ !~ ident - vprint_warning("Was not SSH -- #{resp.size} bytes beginning with #{resp[0, 12]}") - return Exploit::CheckCode::Safe(details: { ident: ident }) - end + recog_info.each do |info| + info = info.split(': ') + table << [info[0], info[1..].join(': ')] + end + table + end - banner = $1 + def check_host_key(server_data) + table = [] - # Try to match with Recog and show the relevant fields to the user - recog_match = Recog::Nizer.match('ssh.banner', banner) - if recog_match - info << " ( " - recog_match.each_pair do |k,v| - next if k == 'matched' - info << "#{k}=#{v} " + host_key_checks = { + %w[ + ecdsa-sha2-nistp521 ecdsa-sha2-nistp384 + ecdsa-sha2-nistp256 + ] => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#host-keys'] + } + server_data[:host_key].each do |host_key| + note = '' + host_key_checks.each do |host_key_check, refs| + host_key_check.each do |bad_key| + next unless host_key.downcase == bad_key + + vprint_good("#{target_host} - Host Key Encryption #{host_key} uses a weak elliptic curve and should not be used.") + report_vuln( + host: target_host, + port: rport, + proto: 'tcp', + name: name, + info: "Module #{fullname} confirmed SSH Host Key Encryption #{host_key} is available, but should be deprecated", + refs: refs + ) + note = 'Weak elliptic curve' end - info << ")" end + table << ['encryption.host_key', host_key, note] + end + table + end + + def check_encryption(server_data) + table = [] + + encryption_checks = { + 'arcfour' => ['https://datatracker.ietf.org/doc/html/rfc8758#name-iana-considerations'], + 'arcfour128' => ['https://datatracker.ietf.org/doc/html/rfc8758#name-iana-considerations'], + 'arcfour256' => ['https://datatracker.ietf.org/doc/html/rfc8758#name-iana-considerations'], + 'aes256-cbc' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#encryption-algorithms-ciphers', 'CVE-2008-5161'], + 'aes192-cbc' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#encryption-algorithms-ciphers', 'CVE-2008-5161'], + 'aes128-cbc' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#encryption-algorithms-ciphers', 'CVE-2008-5161'], + 'rijndael-cbc@lysator.liu.se' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#encryption-algorithms-ciphers', 'CVE-2008-5161'], + 'blowfish-cbc' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#encryption-algorithms-ciphers', 'CVE-2008-5161'], + 'cast128-cbc' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#encryption-algorithms-ciphers', 'CVE-2008-5161'], + '3des-cbc' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#encryption-algorithms-ciphers', 'CVE-2008-5161'], + 'idea-cbc' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#encryption-algorithms-ciphers', 'CVE-2008-5161'], + 'twofish-cbc' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#encryption-algorithms-ciphers', 'CVE-2008-5161'], + 'twofish128-cbc' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#encryption-algorithms-ciphers', 'CVE-2008-5161'], + 'twofish256-cbc' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#encryption-algorithms-ciphers', 'CVE-2008-5161'], + 'blowfish-ctr' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#encryption-algorithms-ciphers'], + 'cast128-ctr' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#encryption-algorithms-ciphers'], + '3des-ctr' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#encryption-algorithms-ciphers'], + 'none' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#encryption-algorithms-ciphers'] + } + + server_data[:encryption_server].each do |encryption| + note = '' + encryption_checks.each do |bad_enc, refs| + next unless encryption.downcase == bad_enc - # Check to see if this is Kippo, which sends a premature - # key init exchange right on top of the SSH version without - # waiting for the required client identification string. - if first_message && first_message.size >= 5 - extra = first_message.unpack("NCCA*") # sz, pad_sz, code, data - if (extra.last.size + 2 == extra[0]) && extra[2] == 20 - info << " (Kippo Honeypot)" + vprint_good("#{target_host} - Encryption #{encryption} is deprecated and should not be used.") + report_vuln( + host: target_host, + port: rport, + proto: 'tcp', + name: name, + info: "Module #{fullname} confirmed SSH Encryption #{encryption} is available, but should be deprecated", + refs: refs + ) + note = 'Deprecated' + end + table << ['encryption.encryption', encryption, note] + end + table + end + + def check_kex(server_data) + table = [] + kex_checks = { + 'gss-group1-sha1-*' => ['https://datatracker.ietf.org/doc/html/rfc8732#name-deprecated-algorithms'], + 'gss-group14-sha1-gss-gex-sha1-*' => ['https://datatracker.ietf.org/doc/html/rfc8732#name-deprecated-algorithms'], + 'gss-gex-sha1-*' => ['https://datatracker.ietf.org/doc/html/rfc8732#name-deprecated-algorithms'], + 'ecdsa-sha2-nistp521' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#key-exchange'], + 'ecdsa-sha2-nistp384' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#key-exchange'], + 'ecdsa-sha2-nistp256' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#key-exchange'], + 'diffie-hellman-group-exchange-sha1' => ['https://datatracker.ietf.org/doc/html/draft-ietf-curdle-ssh-kex-sha2-20#page-16'], + 'diffie-hellman-group1-sha1' => ['https://datatracker.ietf.org/doc/html/draft-ietf-curdle-ssh-kex-sha2-20#page-16'], + 'rsa1024-sha1' => ['https://datatracker.ietf.org/doc/html/draft-ietf-curdle-ssh-kex-sha2-20#page-16'] + } + server_data[:kex].each do |kex| + note = '' + kex_checks.each do |bad_kex, refs| + if bad_kex.ends_with? '*' + next unless kex.downcase.start_with? bad_kex[0..-2] + else + next unless kex.downcase == bad_kex end + + vprint_good("#{target_host} - Key Exchange (kex) #{kex} is deprecated and should not be used.") + report_vuln( + host: target_host, + port: rport, + proto: 'tcp', + name: name, + info: "Module #{fullname} confirmed SSH Encryption #{kex} is available, but should be deprecated", + refs: refs + ) + note = 'Deprecated' + end + table << ['encryption.key_exchange', kex, note] + end + table + end + + def check_hmac(server_data) + table = [] + + hmac_checks = { + 'hmac-sha2-512-96' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#message-authentication-code-algorithms'], + 'hmac-sha2-256-96' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#message-authentication-code-algorithms'], + 'hmac-sha1-96' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#message-authentication-code-algorithms'], + 'hmac-ripemd160' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#message-authentication-code-algorithms'], + 'hmac-md5' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#message-authentication-code-algorithms'], + 'hmac-md5-96' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#message-authentication-code-algorithms'], + 'none' => ['https://github.com/net-ssh/net-ssh?tab=readme-ov-file#message-authentication-code-algorithms'] + } + + server_data[:hmac_server].each do |hmac| + note = '' + hmac_checks.each do |bad_hmac, refs| + next unless hmac.downcase == bad_hmac + + vprint_good("#{target_host} - HMAC #{hmac} is deprecated and should not be used.") + report_vuln( + host: target_host, + port: rport, + proto: 'tcp', + name: name, + info: "Module #{fullname} confirmed SSH HMAC #{hmac} is available, but should be deprecated", + refs: refs + ) + note = 'Deprecated' + end + table << ['encryption.hmac', hmac, note] + end + table + end + + def run_host(target_host) + ::Timeout.timeout(timeout) do + transport = Net::SSH::Transport::Session.new(target_host, { port: rport }) + + server_data = transport.algorithms.instance_variable_get(:@server_data) + host_keys = transport.algorithms.session.instance_variable_get(:@host_keys).instance_variable_get(:@host_keys) + host_keys.each do |host_key| + print_status("#{target_host} - Key Fingerprint: #{host_key.ssh_type} #{Base64.strict_encode64(host_key.to_blob)}") end - print_good("SSH server version: #{ident}#{info}") - report_service(host: rhost, port: rport, name: 'ssh', proto: 'tcp', info: ident) + ident = transport.server_version.version + + print_status("#{target_host} - SSH server version: #{ident}") + + report_service(host: target_host, port: rport, name: 'ssh', proto: 'tcp', info: ident) + + return unless datastore['EXTENDED_CHECKS'] + + table = Rex::Text::Table.new( + 'Header' => 'Server Information and Encryption', + 'Indent' => 2, + 'SortIndex' => 0, + 'Columns' => %w[Type Value Note] + ) + + # if these ever get expanded to have checks, they should be moved to their own function + server_data[:language_server].each do |language| + table << ['encryption.language', language, ''] + end + + # if these ever get expanded to have checks, they should be moved to their own function + server_data[:compression_server].each do |compression| + table << ['encryption.compression', compression, ''] + end + + table.rows.concat check_kex(server_data) + + table.rows.concat check_host_key(server_data) + + table.rows.concat check_hmac(server_data) + + table.rows.concat check_encryption(server_data) + + table.rows.concat perform_recog(ident) + + # XXX check for host key size? + # h00die - not sure how to get that info from the library. + # https://www.tenable.com/plugins/nessus/153954 - Exploit::CheckCode::Detected(details: { ident: ident, info: info }) + print_status("#{target_host} - #{table}") end rescue EOFError, Rex::ConnectionError => e - vprint_error(e.message) # This may be a little noisy, but it is consistent - Exploit::CheckCode::Unknown + vprint_error("#{target_host} - #{e.message}") # This may be a little noisy, but it is consistent rescue Timeout::Error - vprint_warning("Timed out after #{timeout} seconds. Skipping.") - Exploit::CheckCode::Unknown - ensure - disconnect + vprint_warning("#{target_host} - Timed out after #{timeout} seconds. Skipping.") end end