Skip to content

Commit 38b03fd

Browse files
committed
Merge branch 'upstream-master' into land-9539-
2 parents bad1429 + c4c864f commit 38b03fd

File tree

93 files changed

+1663
-966
lines changed

Some content is hidden

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

93 files changed

+1663
-966
lines changed

Gemfile.lock

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ PATH
3838
pg (= 0.20.0)
3939
railties
4040
rb-readline
41-
rbnacl (< 5.0.0)
4241
recog
4342
redcarpet
4443
rex-arch
@@ -73,7 +72,7 @@ PATH
7372
GEM
7473
remote: https://rubygems.org/
7574
specs:
76-
Ascii85 (1.0.2)
75+
Ascii85 (1.0.3)
7776
actionpack (4.2.10)
7877
actionview (= 4.2.10)
7978
activesupport (= 4.2.10)
@@ -103,12 +102,12 @@ GEM
103102
public_suffix (>= 2.0.2, < 4.0)
104103
afm (0.2.2)
105104
arel (6.0.4)
106-
arel-helpers (2.5.0)
105+
arel-helpers (2.6.1)
107106
activerecord (>= 3.1.0, < 6)
108-
backports (3.11.0)
107+
backports (3.11.1)
109108
bcrypt (3.1.11)
110109
bcrypt_pbkdf (1.0.0)
111-
bindata (2.4.1)
110+
bindata (2.4.2)
112111
bit-struct (0.16)
113112
builder (3.2.3)
114113
coderay (1.1.2)
@@ -127,7 +126,6 @@ GEM
127126
i18n (>= 0.7)
128127
faraday (0.13.1)
129128
multipart-post (>= 1.2, < 3)
130-
ffi (1.9.18)
131129
filesize (0.1.1)
132130
fivemat (1.3.5)
133131
google-protobuf (3.5.1)
@@ -249,8 +247,6 @@ GEM
249247
thor (>= 0.18.1, < 2.0)
250248
rake (12.3.0)
251249
rb-readline (0.5.5)
252-
rbnacl (4.0.2)
253-
ffi
254250
recog (2.1.17)
255251
nokogiri
256252
redcarpet (3.4.0)
@@ -352,7 +348,7 @@ GEM
352348
ttfunk (1.5.1)
353349
tzinfo (1.2.4)
354350
thread_safe (~> 0.1)
355-
tzinfo-data (1.2017.3)
351+
tzinfo-data (1.2018.3)
356352
tzinfo (>= 1.0.0)
357353
windows_error (0.1.2)
358354
xdr (2.0.0)

lib/metasploit/framework/login_scanner/bavision_cameras.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ module Metasploit
55
module Framework
66
module LoginScanner
77

8+
class BavisionCamerasException < Exception; end
9+
810
class BavisionCameras < HTTP
911

1012
DEFAULT_PORT = 80
@@ -59,7 +61,13 @@ def digest_auth(user, password, response)
5961
nonce_count = 1
6062
cnonce = Digest::MD5.hexdigest("%x" % (Time.now.to_i + rand(65535)))
6163

62-
response['www-authenticate'] =~ /^(\w+) (.*)/
64+
i = (response['www-authenticate'] =~ /^(\w+) (.*)/)
65+
66+
# The www-authenticate header does not return in the format we like,
67+
# so let's bail.
68+
unless i
69+
raise BavisionCamerasException, 'www-authenticate header is not in the right format'
70+
end
6371

6472
params = {}
6573
$2.gsub(/(\w+)="(.*?)"/) { params[$1] = $2 }
@@ -104,7 +112,7 @@ def attempt_login(credential)
104112

105113
begin
106114
result_opts.merge!(try_digest_auth(credential))
107-
rescue ::Rex::ConnectionError => e
115+
rescue ::Rex::ConnectionError, BavisionCamerasException => e
108116
# Something went wrong during login. 'e' knows what's up.
109117
result_opts.merge!(status: LOGIN_STATUS::UNABLE_TO_CONNECT, proof: e.message)
110118
end

lib/msf/core/handler/bind_udp.rb

Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
# -*- coding: binary -*-
2+
module Msf
3+
module Handler
4+
5+
###
6+
#
7+
# This module implements the Bind TCP handler. This means that
8+
# it will attempt to connect to a remote host on a given port for a period of
9+
# time (typically the duration of an exploit) to see if a the payload has
10+
# started listening. This can tend to be rather verbose in terms of traffic
11+
# and in general it is preferable to use reverse payloads.
12+
#
13+
###
14+
module BindUdp
15+
16+
include Msf::Handler
17+
18+
#
19+
# Returns the handler specific string representation, in this case
20+
# 'bind_tcp'.
21+
#
22+
def self.handler_type
23+
return "bind_udp"
24+
end
25+
26+
#
27+
# Returns the connection oriented general handler type, in this case bind.
28+
#
29+
def self.general_handler_type
30+
"bind"
31+
end
32+
33+
#
34+
# Initializes a bind handler and adds the options common to all bind
35+
# payloads, such as local port.
36+
#
37+
def initialize(info = {})
38+
super
39+
40+
register_options(
41+
[
42+
Opt::LPORT(4444),
43+
OptAddress.new('RHOST', [false, 'The target address', '']),
44+
], Msf::Handler::BindUdp)
45+
46+
self.conn_threads = []
47+
self.listener_threads = []
48+
self.listener_pairs = {}
49+
end
50+
51+
#
52+
# Kills off the connection threads if there are any hanging around.
53+
#
54+
def cleanup_handler
55+
# Kill any remaining handle_connection threads that might
56+
# be hanging around
57+
conn_threads.each { |thr|
58+
thr.kill
59+
}
60+
end
61+
62+
#
63+
# Starts a new connecting thread
64+
#
65+
def add_handler(opts={})
66+
67+
# Merge the updated datastore values
68+
opts.each_pair do |k,v|
69+
datastore[k] = v
70+
end
71+
72+
# Start a new handler
73+
start_handler
74+
end
75+
76+
#
77+
# Starts monitoring for an outbound connection to become established.
78+
#
79+
def start_handler
80+
81+
# Maximum number of seconds to run the handler
82+
ctimeout = 150
83+
84+
# Maximum number of seconds to await initial udp response
85+
rtimeout = 5
86+
87+
if (exploit_config and exploit_config['active_timeout'])
88+
ctimeout = exploit_config['active_timeout'].to_i
89+
end
90+
91+
# Take a copy of the datastore options
92+
rhost = datastore['RHOST']
93+
lport = datastore['LPORT']
94+
95+
# Ignore this if one of the required options is missing
96+
return if not rhost
97+
return if not lport
98+
99+
# Only try the same host/port combination once
100+
phash = rhost + ':' + lport.to_s
101+
return if self.listener_pairs[phash]
102+
self.listener_pairs[phash] = true
103+
104+
# Start a new handling thread
105+
self.listener_threads << framework.threads.spawn("BindUdpHandlerListener-#{lport}", false) {
106+
client = nil
107+
108+
print_status("Started bind handler")
109+
110+
if (rhost == nil)
111+
raise ArgumentError,
112+
"RHOST is not defined; bind stager cannot function.",
113+
caller
114+
end
115+
116+
stime = Time.now.to_i
117+
118+
while (stime + ctimeout > Time.now.to_i)
119+
begin
120+
client = Rex::Socket::Udp.create(
121+
'PeerHost' => rhost,
122+
'PeerPort' => lport.to_i,
123+
'Proxies' => datastore['Proxies'],
124+
'Context' =>
125+
{
126+
'Msf' => framework,
127+
'MsfPayload' => self,
128+
'MsfExploit' => assoc_exploit
129+
})
130+
rescue Rex::ConnectionRefused
131+
# Connection refused is a-okay
132+
rescue ::Exception
133+
wlog("Exception caught in bind handler: #{$!.class} #{$!}")
134+
end
135+
136+
client.extend(Rex::IO::Stream)
137+
begin
138+
# If a connection was acknowledged, request a basic response before promoting as a session
139+
if client
140+
message = 'syn'
141+
client.write("echo #{message}\n")
142+
response = client.get(rtimeout)
143+
break if response && response.include?(message)
144+
client.close()
145+
client = nil
146+
end
147+
rescue Errno::ECONNREFUSED
148+
client.close()
149+
client = nil
150+
wlog("Connection failed in udp bind handler continuing attempts: #{$!.class} #{$!}")
151+
end
152+
153+
# Wait a second before trying again
154+
Rex::ThreadSafe.sleep(0.5)
155+
end
156+
157+
# Valid client connection?
158+
if (client)
159+
# Increment the has connection counter
160+
self.pending_connections += 1
161+
162+
# Timeout and datastore options need to be passed through to the client
163+
opts = {
164+
:datastore => datastore,
165+
:expiration => datastore['SessionExpirationTimeout'].to_i,
166+
:comm_timeout => datastore['SessionCommunicationTimeout'].to_i,
167+
:retry_total => datastore['SessionRetryTotal'].to_i,
168+
:retry_wait => datastore['SessionRetryWait'].to_i,
169+
:udp_session => true
170+
}
171+
172+
# Start a new thread and pass the client connection
173+
# as the input and output pipe. Client's are expected
174+
# to implement the Stream interface.
175+
conn_threads << framework.threads.spawn("BindUdpHandlerSession", false, client) { |client_copy|
176+
begin
177+
handle_connection(client_copy, opts)
178+
rescue
179+
elog("Exception raised from BindUdp.handle_connection: #{$!}")
180+
end
181+
}
182+
else
183+
wlog("No connection received before the handler completed")
184+
end
185+
}
186+
end
187+
188+
#
189+
# Nothing to speak of.
190+
#
191+
def stop_handler
192+
# Stop the listener threads
193+
self.listener_threads.each do |t|
194+
t.kill
195+
end
196+
self.listener_threads = []
197+
self.listener_pairs = {}
198+
end
199+
200+
protected
201+
202+
attr_accessor :conn_threads # :nodoc:
203+
attr_accessor :listener_threads # :nodoc:
204+
attr_accessor :listener_pairs # :nodoc:
205+
end
206+
207+
end
208+
end

0 commit comments

Comments
 (0)