Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/metasploit/framework/ssh/platform.rb
Views: 11784
module Metasploit1module Framework2module Ssh3module Platform4def self.get_platform(ssh_socket)5info = get_platform_info(ssh_socket, timeout: 10)6get_platform_from_info(info)7end89def self.get_platform_info(ssh_socket, timeout: 10)10info = ''11begin12Timeout.timeout(timeout) do13info = ssh_socket.exec!("id\n").to_s14if (info =~ /id=/)15info << ssh_socket.exec!("uname -a\n").to_s16if (info =~ /JUNOS /)17# We're in the SSH shell for a Juniper JunOS, we can pull the version from the cli18# line 2 is hostname, 3 is model, 4 is the Base OS version19info = ssh_socket.exec!("cli show version\n").split("\n")[2..4].join(', ').to_s20elsif (info =~ /Linux USG /)21# Ubiquiti Unifi USG22info << ssh_socket.exec!("cat /etc/version\n").to_s.rstrip23end24temp_proof = ssh_socket.exec!("grep unifi.version /tmp/system.cfg\n").to_s.rstrip25if (temp_proof =~ /unifi\.version/)26info << temp_proof27# Ubiquiti Unifi device (non-USG), possibly a switch. Tested on US-24, UAP-nanoHD28# The /tmp/*.cfg files don't give us device info, however the info command does29# we dont call it originally since it doesnt say unifi/ubiquiti in it and info30# is a linux command as well31info << ssh_socket.exec!("grep board.name /etc/board.info\n").to_s.rstrip32end33elsif info =~ /Unknown command or computer name/34# Cisco IOS35info = ssh_socket.exec!("ver\n").to_s36# Juniper ScreenOS37elsif info =~ /unknown keyword/38info = ssh_socket.exec!("get chassis\n").to_s39# Juniper JunOS CLI40elsif info =~ /unknown command: id/41info = ssh_socket.exec!("show version\n").split("\n")[2..4].join(', ').to_s42# Brocade CLI43elsif info =~ /Invalid input -> id/ || info =~ /Protocol error, doesn't start with scp!/44info = ssh_socket.exec!("show version\n").to_s45if info =~ /Version:(?<os_version>.+).+HW: (?<hardware>)/mi46info = "Model: #{hardware}, OS: #{os_version}"47end48# Arista49elsif info =~ /% Invalid input at line 1/50info = ssh_socket.exec!("show version\n").split("\n")[0..1]51info = info.map { |item| item.strip }52info = info.join(', ').to_s53# Windows54elsif info =~ /command not found|is not recognized as an internal or external command/55info = ssh_socket.exec!("systeminfo\n").to_s56/OS Name:\s+(?<os_name>.+)$/ =~ info57/OS Version:\s+(?<os_num>.+)$/ =~ info58if os_num.present? && os_name.present?59info = "#{os_name.strip} #{os_num.strip}"60else61info = ssh_socket.exec!("ver\n").to_s.strip62end63# mikrotik64elsif info =~ /bad command name id \(line 1 column 1\)/65info = ssh_socket.exec!("/ system resource print\n").to_s66/platform:\s+(?<platform>.+)$/ =~ info67/board-name:\s+(?<board>.+)$/ =~ info68/version:\s+(?<version>.+)$/ =~ info69if version && platform && board70info = "#{platform.strip} #{board.strip} #{version.strip}"71end72# esxi 6.773elsif info =~ /sh: id: not found/74info = ssh_socket.exec!("vmware -v\n").to_s75else76info << ssh_socket.exec!("help\n?\n\n\n").to_s77end78end79rescue Timeout::Error80end8182info83end8485def self.get_platform_from_info(info)86case info87when /unifi\.version|UniFiSecurityGateway/i # Ubiquiti Unifi. uname -a is left in, so we got to pull before Linux88'unifi'89when /Linux/i90'linux'91when /VMware ESXi/i92'linux'93when /Darwin/i94'osx'95when /SunOS/i96'solaris'97when /BSD/i98'bsd'99when /HP-UX/i100'hpux'101when /AIX/i102'aix'103when /MSYS_NT|cygwin|Win32|Windows|Microsoft/i104'windows'105when /Unknown command or computer name|Line has invalid autocommand/i106'cisco-ios'107when /unknown keyword/i # ScreenOS108'juniper'109when /JUNOS Base OS/i # JunOS110'juniper'111when /MikroTik/i112'mikrotik'113when /Arista/i114'arista'115else116'unknown'117end118end119end120end121end122end123124125