Skip to content

Commit de07ca5

Browse files
committed
Merge branch 'bug/wrong-file_changed-argument' of github.com:/rapid7/metasploit-framework into bug/wrong-file_changed-argument
2 parents 471ac6d + 4073bec commit de07ca5

File tree

56 files changed

+1092
-133
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1092
-133
lines changed

lib/msf/core/db_manager.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,8 +588,8 @@ def search_modules(search_string, inclusive=false)
588588
where_v << [ xv, xv ]
589589
when 'os','platform'
590590
xv = "%#{kv}%"
591-
where_q << ' ( module_targets.name ILIKE ? ) '
592-
where_v << [ xv ]
591+
where_q << ' ( module_platforms.name ILIKE ? OR module_targets.name ILIKE ? ) '
592+
where_v << [ xv, xv ]
593593
when 'port'
594594
# TODO
595595
when 'type'

lib/msf/core/exploit/winrm.rb

Lines changed: 17 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,24 @@
88

99
module Msf
1010
module Exploit::Remote::WinRM
11-
1211
include Exploit::Remote::NTLM::Client
1312
include Exploit::Remote::HttpClient
14-
1513
#
1614
# Constants
1715
#
1816
NTLM_CRYPT ||= Rex::Proto::NTLM::Crypt
1917
NTLM_CONST ||= Rex::Proto::NTLM::Constants
2018
NTLM_UTILS ||= Rex::Proto::NTLM::Utils
2119
NTLM_XCEPT ||= Rex::Proto::NTLM::Exceptions
22-
2320
def initialize(info = {})
2421
super
2522
register_options(
2623
[
27-
Opt::RHOST,
2824
Opt::RPORT(5985),
29-
OptString.new('VHOST', [ false, "HTTP server virtual host" ]),
30-
OptBool.new('SSL', [ false, 'Negotiate SSL for outgoing connections', false]),
31-
OptEnum.new('SSLVersion', [ false, 'Specify the version of SSL that should be used', 'SSL3', ['SSL2', 'SSL3', 'TLS1']]),
3225
OptString.new('DOMAIN', [ true, 'The domain to use for Windows authentification', 'WORKSTATION']),
3326
OptString.new('URI', [ true, "The URI of the WinRM service", "/wsman" ]),
3427
OptString.new('USERNAME', [ false, 'A specific username to authenticate as' ]),
35-
OptString.new('PASSWORD', [ false, 'A specific password to authenticate with' ])
28+
OptString.new('PASSWORD', [ false, 'A specific password to authenticate with' ]),
3629
], self.class
3730
)
3831

@@ -45,18 +38,15 @@ def winrm_poke(timeout = 20)
4538
'uri' => datastore['URI'],
4639
'data' => Rex::Text.rand_text_alpha(8)
4740
}
48-
49-
c = connect(opts)
50-
to = opts[:timeout] || timeout
41+
c = connect(opts)
42+
to = opts[:timeout] || timeout
5143
ctype = "application/soap+xml;charset=UTF-8"
52-
5344
resp, c = send_request_cgi(opts.merge({
54-
'uri' => opts['uri'],
45+
'uri' => opts['uri'],
5546
'method' => 'POST',
56-
'ctype' => ctype,
57-
'data' => opts['data']
47+
'ctype' => ctype,
48+
'data' => opts['data']
5849
}), to)
59-
6050
return resp
6151
end
6252

@@ -71,34 +61,29 @@ def parse_auth_methods(resp)
7161

7262
def winrm_run_cmd(cmd, timeout=20)
7363
resp,c = send_request_ntlm(winrm_open_shell_msg,timeout)
74-
7564
if resp.code == 401
7665
print_error "Login failure! Recheck supplied credentials."
7766
return resp .code
7867
end
79-
8068
unless resp.code == 200
8169
print_error "Got unexpected response: \n #{resp.to_s}"
8270
retval == resp.code || 0
8371
return retval
8472
end
85-
8673
shell_id = winrm_get_shell_id(resp)
8774
resp,c = send_request_ntlm(winrm_cmd_msg(cmd, shell_id),timeout)
8875
cmd_id = winrm_get_cmd_id(resp)
8976
resp,c = send_request_ntlm(winrm_cmd_recv_msg(shell_id,cmd_id),timeout)
9077
streams = winrm_get_cmd_streams(resp)
9178
resp,c = send_request_ntlm(winrm_terminate_cmd_msg(shell_id,cmd_id),timeout)
9279
resp,c = send_request_ntlm(winrm_delete_shell_msg(shell_id))
93-
9480
return streams
9581
end
9682

9783
def winrm_wql_msg(wql)
9884
action = winrm_uri_action("wql")
9985
contents = winrm_header(action) + winrm_wql_body(wql)
10086
msg = winrm_envelope(contents)
101-
10287
return msg
10388
end
10489

@@ -108,7 +93,6 @@ def winrm_open_shell_msg
10893
header_data = action + options
10994
contents = winrm_header(header_data) + winrm_open_shell_body
11095
msg = winrm_envelope(contents)
111-
11296
return msg
11397
end
11498

@@ -119,7 +103,6 @@ def winrm_cmd_msg(cmd,shell_id)
119103
header_data = action + options + selectors
120104
contents = winrm_header(header_data) + winrm_cmd_body(cmd)
121105
msg = winrm_envelope(contents)
122-
123106
return msg
124107
end
125108

@@ -129,7 +112,6 @@ def winrm_cmd_recv_msg(shell_id,cmd_id)
129112
header_data = action + selectors
130113
contents = winrm_header(header_data) + winrm_cmd_recv_body(cmd_id)
131114
msg = winrm_envelope(contents)
132-
133115
return msg
134116
end
135117

@@ -139,7 +121,6 @@ def winrm_terminate_cmd_msg(shell_id,cmd_id)
139121
header_data = action + selectors
140122
contents = winrm_header(header_data) + winrm_terminate_cmd_body(cmd_id)
141123
msg = winrm_envelope(contents)
142-
143124
return msg
144125
end
145126

@@ -149,7 +130,6 @@ def winrm_delete_shell_msg(shell_id)
149130
header_data = action + selectors
150131
contents = winrm_header(header_data) + winrm_empty_body
151132
msg = winrm_envelope(contents)
152-
153133
return msg
154134
end
155135

@@ -159,28 +139,23 @@ def parse_wql_response(response)
159139
rows =[]
160140
rxml = REXML::Document.new(xml).root
161141
items = rxml.elements["///w:Items"]
162-
163142
items.elements.to_a("///w:XmlFragment").each do |node|
164143
row_data = []
165-
166144
node.elements.to_a.each do |sub_node|
167145
columns << sub_node.name
168146
row_data << sub_node.text
169147
end
170-
171148
rows << row_data
172149
end
173-
150+
columns.uniq!
174151
response_data = Rex::Ui::Text::Table.new(
175152
'Header' => "#{datastore['WQL']} (#{rhost})",
176153
'Indent' => 1,
177-
'Columns' => columns.uniq!
154+
'Columns' => columns
178155
)
179-
180156
rows.each do |row|
181157
response_data << row
182158
end
183-
184159
return response_data
185160
end
186161

@@ -197,17 +172,14 @@ def winrm_get_cmd_id(response)
197172
def winrm_get_cmd_streams(response)
198173
streams = {
199174
'stdout' => '',
200-
'stderr' => '',
175+
'stderr' => '',
201176
}
202-
203177
xml = response.body
204178
rxml = REXML::Document.new(xml).root
205-
206179
rxml.elements.to_a("//rsp:Stream").each do |node|
207180
next if node.text.nil?
208181
streams[node.attributes['Name']] << Rex::Text.base64_decode(node.text)
209182
end
210-
211183
return streams
212184
end
213185

@@ -222,25 +194,20 @@ def send_request_ntlm(data, timeout = 20)
222194
'username' => datastore['USERNAME'],
223195
'password' => datastore['PASSWORD']
224196
}
225-
226-
ntlm_options =
227-
{
228-
:signing => false,
229-
:usentlm2_session => datastore['NTLM::UseNTLM2_session'],
230-
:use_ntlmv2 => datastore['NTLM::UseNTLMv2'],
231-
:send_lm => datastore['NTLM::SendLM'],
232-
:send_ntlm => datastore['NTLM::SendNTLM']
233-
}
234-
197+
ntlm_options = {
198+
:signing => false,
199+
:usentlm2_session => datastore['NTLM::UseNTLM2_session'],
200+
:use_ntlmv2 => datastore['NTLM::UseNTLMv2'],
201+
:send_lm => datastore['NTLM::SendLM'],
202+
:send_ntlm => datastore['NTLM::SendNTLM']
203+
}
235204
ntlmssp_flags = NTLM_UTILS.make_ntlm_flags(ntlm_options)
236205
workstation_name = Rex::Text.rand_text_alpha(rand(8)+1)
237206
domain_name = datastore['DOMAIN']
238207
ntlm_message_1 = "NEGOTIATE " + Rex::Text::encode_base64(NTLM_UTILS::make_ntlmssp_blob_init( domain_name,
239208
workstation_name,
240209
ntlmssp_flags))
241-
242210
to = opts[:timeout] || timeout
243-
244211
begin
245212
c = connect(opts)
246213
ctype = "application/soap+xml;charset=UTF-8"
@@ -251,14 +218,11 @@ def send_request_ntlm(data, timeout = 20)
251218
'ctype' => ctype,
252219
'headers' => { 'Authorization' => ntlm_message_1},
253220
'data' => opts['data']
254-
}))
255-
221+
}))
256222
resp = c.send_recv(r, to)
257-
258223
unless resp.kind_of? Rex::Proto::Http::Response
259224
return [nil,nil]
260225
end
261-
262226
return [nil,nil] if resp.code == 404
263227
return [nil,nil] unless resp.code == 401 && resp.headers['WWW-Authenticate']
264228
# Get the challenge and craft the response
@@ -293,7 +257,6 @@ def send_request_ntlm(data, timeout = 20)
293257
ntlm_message_3 = NTLM_UTILS.make_ntlmssp_blob_auth(domain_name, workstation_name, opts['username'],
294258
resp_lm, resp_ntlm, '', ntlmssp_flags)
295259
ntlm_message_3 = Rex::Text::encode_base64(ntlm_message_3)
296-
297260
# Send the response
298261
r = c.request_cgi(opts.merge({
299262
'uri' => opts['uri'],
@@ -302,13 +265,10 @@ def send_request_ntlm(data, timeout = 20)
302265
'headers' => { 'Authorization' => "NEGOTIATE #{ntlm_message_3}"},
303266
'data' => opts['data']
304267
}))
305-
306268
resp = c.send_recv(r, to, true)
307-
308269
unless resp.kind_of? Rex::Proto::Http::Response
309270
return [nil,nil]
310271
end
311-
312272
return [nil,nil] if resp.code == 404
313273
return [resp,c]
314274
rescue ::Errno::EPIPE, ::Timeout::Error
@@ -324,25 +284,20 @@ def target_url
324284
if rport == 5986 or datastore['SSL']
325285
proto = "https"
326286
end
327-
328287
if datastore['VHOST']
329288
return "#{proto}://#{datastore ['VHOST']}:#{rport}#{@uri.to_s}"
330289
else
331290
return "#{proto}://#{rhost}:#{rport}#{@uri.to_s}"
332291
end
333292
end
334293

335-
336-
337294
private
338295

339296
def winrm_option_set(options)
340297
xml = "<w:OptionSet>"
341-
342298
options.each do |option_pair|
343299
xml << winrm_option(*option_pair)
344300
end
345-
346301
xml << "</w:OptionSet>"
347302
return xml
348303
end
@@ -353,11 +308,9 @@ def winrm_option(name,value)
353308

354309
def winrm_selector_set(selectors)
355310
xml = "<w:SelectorSet>"
356-
357311
selectors.each do |selector_pair|
358312
xml << winrm_selector(*selector_pair)
359313
end
360-
361314
xml << "</w:SelectorSet>"
362315
return xml
363316
end

lib/rex/text.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# -*- coding: binary -*-
22
require 'digest/md5'
3+
require 'digest/sha1'
34
require 'stringio'
45

56
begin
@@ -812,6 +813,20 @@ def self.md5(str)
812813
Digest::MD5.hexdigest(str)
813814
end
814815

816+
#
817+
# Raw SHA1 digest of the supplied string
818+
#
819+
def self.sha1_raw(str)
820+
Digest::SHA1.digest(str)
821+
end
822+
823+
#
824+
# Hexidecimal SHA1 digest of the supplied string
825+
#
826+
def self.sha1(str)
827+
Digest::SHA1.hexdigest(str)
828+
end
829+
815830
#
816831
# Convert hex-encoded characters to literals.
817832
# Example: "AA\\x42CC" becomes "AABCC"

modules/auxiliary/admin/sunrpc/solaris_kcms_readfile.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ def run
135135
sunrpc_destroy
136136

137137
rescue ::Rex::Proto::SunRPC::RPCTimeout
138-
print_status 'Warning: ' + $!
139-
print_status 'Exploit may or may not have succeeded.'
138+
print_warning 'Warning: ' + $!
139+
print_warning 'Exploit may or may not have succeeded.'
140140
end
141141

142142

0 commit comments

Comments
 (0)