Skip to content

Commit 86957d9

Browse files
committed
Merge branch 'upstream/master' into connection-recovery
2 parents 19f8a76 + 8aca453 commit 86957d9

File tree

80 files changed

+3244
-805
lines changed

Some content is hidden

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

80 files changed

+3244
-805
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ GEM
177177
json (~> 1.4)
178178
recog (1.0.27)
179179
nokogiri
180-
redcarpet (3.1.2)
180+
redcarpet (3.2.3)
181181
rkelly-remix (0.0.6)
182182
robots (0.10.1)
183183
rspec (2.99.0)

data/meterpreter/meterpreter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ def create_response(self, request):
749749
resp = struct.pack('>I', len(resp) + 4) + resp
750750
return resp
751751

752-
if not hasattr(os, 'fork') or (hasattr(os, 'fork') and os.fork() == 0):
752+
if not hasattr(os, 'fork') or has_osxsc or (hasattr(os, 'fork') and os.fork() == 0):
753753
if hasattr(os, 'setsid'):
754754
try:
755755
os.setsid()

lib/metasploit/framework/login_scanner/http.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def send_request(opts)
224224
configure_http_client(cli)
225225

226226
if realm
227-
cli.set_config('domain' => credential.realm)
227+
cli.set_config('domain' => realm)
228228
end
229229

230230
begin

lib/msf/core/db_manager/import/nmap.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ def import_nmap_xml(args={}, &block)
164164
data[:host] = hobj || addr
165165
data[:info] = extra if not extra.empty?
166166
data[:task] = args[:task]
167-
if p["name"] != "unknown"
168-
data[:name] = p["name"]
169-
end
167+
data[:name] = p['tunnel'] ? "#{p['tunnel']}/#{p['name'] || 'unknown'}" : p['name']
170168
report_service(data)
171169
}
172170
#Parse the scripts output

lib/msf/core/exploit.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,10 +1218,31 @@ def reset_session_counts
12181218
# Failure tracking
12191219
##
12201220

1221+
# Raises a Msf::Exploit::Failed exception. It overrides the fail_with method
1222+
# in lib/msf/core/module.rb
1223+
#
1224+
# @param reason [String] A constant from Msf::Module::Failure.
1225+
# If the reason does not come from there, then it will default to
1226+
# Msf::Module::Failure::Unknown.
1227+
# @param msg [String] (Optional) A message about the failure.
1228+
# @raise [Msf::Exploit::Failed] A custom Msf::Exploit::Failed exception.
1229+
# @return [void]
1230+
# @see Msf::Module::Failure
1231+
# @see Msf::Module#fail_with
1232+
# @example
1233+
# fail_with(Msf::Module::Failure::NoAccess, 'Unable to login to upload payload')
12211234
def fail_with(reason,msg=nil)
1222-
self.fail_reason = reason
1235+
# The reason being registered here will be used later on, so it's important we don't actually
1236+
# provide a made-up one.
1237+
allowed_values = Msf::Module::Failure.constants.collect {|e| Msf::Module::Failure.const_get(e)}
1238+
if allowed_values.include?(reason)
1239+
self.fail_reason = reason
1240+
else
1241+
self.fail_reason = Msf::Module::Failure::Unknown
1242+
end
1243+
12231244
self.fail_detail = msg
1224-
raise Msf::Exploit::Failed, (msg || "No reason given")
1245+
raise Msf::Exploit::Failed, (msg || "No failure message given")
12251246
end
12261247

12271248
def report_failure

lib/msf/core/handler/reverse_http.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,9 @@ def setup_handler
163163
def stop_handler
164164
if self.service
165165
self.service.remove_resource("/")
166-
Rex::ServiceManager.stop_service(self.service) if self.sessions == 0
166+
if self.service.resources.empty? && self.sessions == 0
167+
Rex::ServiceManager.stop_service(self.service)
168+
end
167169
end
168170
end
169171

lib/msf/core/module.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
module Msf
55

6+
autoload :OptionContainer, 'msf/core/option_container'
7+
68
###
79
#
810
# The module base class is responsible for providing the common interface
@@ -276,7 +278,18 @@ def debugging?
276278
end
277279

278280
#
279-
# Support fail_with for all module types, allow specific classes to override
281+
# Raises a RuntimeError failure message. This is meant to be used for all non-exploits,
282+
# and allows specific classes to override.
283+
#
284+
# @param reason [String] A reason about the failure.
285+
# @param msg [String] (Optional) A message about the failure.
286+
# @raise [RuntimeError]
287+
# @return [void]
288+
# @note If you are writing an exploit, you don't use this API. Instead, please refer to the
289+
# API documentation from lib/msf/core/exploit.rb.
290+
# @see Msf::Exploit#fail_with
291+
# @example
292+
# fail_with('No Access', 'Unable to login')
280293
#
281294
def fail_with(reason, msg=nil)
282295
raise RuntimeError, "#{reason.to_s}: #{msg}"

lib/msf/core/opt.rb

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# -*- coding: binary -*-
2+
3+
module Msf
4+
5+
#
6+
# Builtin framework options with shortcut methods
7+
#
8+
# @example
9+
# register_options(
10+
# [
11+
# Opt::RHOST,
12+
# Opt::RPORT(21),
13+
# ]
14+
# )
15+
# register_advanced_options([Opt::Proxies])
16+
#
17+
module Opt
18+
19+
# @return [OptAddress]
20+
def self.CHOST(default=nil, required=false, desc="The local client address")
21+
Msf::OptAddress.new(__method__.to_s, [ required, desc, default ])
22+
end
23+
24+
# @return [OptPort]
25+
def self.CPORT(default=nil, required=false, desc="The local client port")
26+
Msf::OptPort.new(__method__.to_s, [ required, desc, default ])
27+
end
28+
29+
# @return [OptAddress]
30+
def self.LHOST(default=nil, required=true, desc="The listen address")
31+
Msf::OptAddress.new(__method__.to_s, [ required, desc, default ])
32+
end
33+
34+
# @return [OptPort]
35+
def self.LPORT(default=nil, required=true, desc="The listen port")
36+
Msf::OptPort.new(__method__.to_s, [ required, desc, default ])
37+
end
38+
39+
# @return [OptString]
40+
def self.Proxies(default=nil, required=false, desc="A proxy chain of format type:host:port[,type:host:port][...]")
41+
Msf::OptString.new(__method__.to_s, [ required, desc, default ])
42+
end
43+
44+
# @return [OptAddress]
45+
def self.RHOST(default=nil, required=true, desc="The target address")
46+
Msf::OptAddress.new(__method__.to_s, [ required, desc, default ])
47+
end
48+
49+
# @return [OptPort]
50+
def self.RPORT(default=nil, required=true, desc="The target port")
51+
Msf::OptPort.new(__method__.to_s, [ required, desc, default ])
52+
end
53+
54+
# These are unused but remain for historical reasons
55+
class << self
56+
alias builtin_chost CHOST
57+
alias builtin_cport CPORT
58+
alias builtin_lhost LHOST
59+
alias builtin_lport LPORT
60+
alias builtin_proxies Proxies
61+
alias builtin_rhost RHOST
62+
alias builtin_rport RPORT
63+
end
64+
65+
CHOST = CHOST()
66+
CPORT = CPORT()
67+
LHOST = LHOST()
68+
LPORT = LPORT()
69+
Proxies = Proxies()
70+
RHOST = RHOST()
71+
RPORT = RPORT()
72+
end
73+
74+
end

lib/msf/core/opt_address.rb

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: binary -*-
2+
3+
module Msf
4+
5+
###
6+
#
7+
# Network address option.
8+
#
9+
###
10+
class OptAddress < OptBase
11+
def type
12+
return 'address'
13+
end
14+
15+
def valid?(value)
16+
return false if empty_required_value?(value)
17+
return false unless value.kind_of?(String) or value.kind_of?(NilClass)
18+
19+
if (value != nil and value.empty? == false)
20+
begin
21+
getaddr_result = ::Rex::Socket.getaddress(value, true)
22+
# Covers a wierdcase where an incomplete ipv4 address will have it's
23+
# missing octets filled in with 0's. (e.g 192.168 become 192.0.0.168)
24+
# which does not feel like a legit behaviour
25+
if value =~ /^\d{1,3}(\.\d{1,3}){1,3}$/
26+
return false unless value =~ Rex::Socket::MATCH_IPV4
27+
end
28+
rescue
29+
return false
30+
end
31+
end
32+
33+
return super
34+
end
35+
end
36+
37+
end

lib/msf/core/opt_address_range.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# -*- coding: binary -*-
2+
3+
module Msf
4+
5+
###
6+
#
7+
# Network address range option.
8+
#
9+
###
10+
class OptAddressRange < OptBase
11+
def type
12+
return 'addressrange'
13+
end
14+
15+
def normalize(value)
16+
return nil unless value.kind_of?(String)
17+
if (value =~ /^file:(.*)/)
18+
path = $1
19+
return false if not File.exists?(path) or File.directory?(path)
20+
return File.readlines(path).map{ |s| s.strip}.join(" ")
21+
elsif (value =~ /^rand:(.*)/)
22+
count = $1.to_i
23+
return false if count < 1
24+
ret = ''
25+
count.times {
26+
ret << " " if not ret.empty?
27+
ret << [ rand(0x100000000) ].pack("N").unpack("C*").map{|x| x.to_s }.join(".")
28+
}
29+
return ret
30+
end
31+
return value
32+
end
33+
34+
def valid?(value)
35+
return false if empty_required_value?(value)
36+
return false unless value.kind_of?(String) or value.kind_of?(NilClass)
37+
38+
if (value != nil and value.empty? == false)
39+
normalized = normalize(value)
40+
return false if normalized.nil?
41+
walker = Rex::Socket::RangeWalker.new(normalized)
42+
if (not walker or not walker.valid?)
43+
return false
44+
end
45+
end
46+
47+
return super
48+
end
49+
end
50+
51+
end

0 commit comments

Comments
 (0)