Skip to content

Commit 7f425fc

Browse files
committed
Configurable fix for rapid7#4305
Rename UDP_SECRET to just SECRET, as it is used for more than just UDP Rename and properly document GATEWAY option Introduce an option to configure what UDP port will be probed
1 parent f22d719 commit 7f425fc

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lib/msf/core/exploit/capture.rb

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,16 @@ def initialize(info = {})
3737

3838
register_advanced_options(
3939
[
40-
OptInt.new('UDP_SECRET', [true, 'The 32-bit cookie for UDP probe requests.', 1297303091]),
41-
OptAddress.new('GATEWAY', [false, 'The gateway IP address. This will be used rather than a random remote address for the UDP probe, if set.']),
40+
OptInt.new('SECRET', [true, 'A 32-bit cookie for probe requests.', 'MSF!'.unpack('N')]),
41+
OptAddress.new('GATEWAY_PROBE_HOST',
42+
[
43+
true,
44+
'Send a TTL=1 random UDP datagram to this host to discover the default gateway\'s MAC',
45+
'www.metasploit.com'])
46+
OptPort.new('GATEWAY_PROBE_PORT',
47+
[
48+
false,
49+
'The port on GATEWAY_PROBE_HOST to send a random UDP probe to (random if 0 or unset)'])
4250
], Msf::Exploit::Capture
4351
)
4452

@@ -116,7 +124,7 @@ def open_pcap(opts={})
116124
self.capture = ::Pcap.open_live(dev, len, true, tim)
117125
if do_arp
118126
self.arp_capture = ::Pcap.open_live(dev, 512, true, tim)
119-
preamble = datastore['UDP_SECRET'].to_i
127+
preamble = datastore['SECRET'].to_i
120128
arp_filter = "arp[6:2] = 2 or (udp[8:4] = #{preamble})"
121129
self.arp_capture.setfilter(arp_filter)
122130
end
@@ -303,19 +311,18 @@ def lookup_eth(addr=nil, iface=nil)
303311
end
304312

305313
def probe_gateway(addr)
306-
dst_host = (datastore['GATEWAY'] || IPAddr.new((rand(16777216) + 2969567232), Socket::AF_INET).to_s)
307-
dst_port = rand(30000)+1024
308-
preamble = [datastore['UDP_SECRET']].pack("N")
314+
dst_host = datastore['GATEWAY_PROBE_HOST']
315+
dst_port = datastore['GATEWAY_PROBE_PORT'] == 0 ? rand(30000) + 1024 : datastore['GATEWAY_PROBE_PORT']
316+
preamble = [datastore['SECRET']].pack("N")
309317
secret = "#{preamble}#{Rex::Text.rand_text(rand(0xff)+1)}"
310318

311319
begin
312320
UDPSocket.open do |sock|
313321
sock.setsockopt(::Socket::IPPROTO_IP, ::Socket::IP_TTL, 1)
314322
sock.send(secret, 0, dst_host, dst_port)
315323
end
316-
#UDPSocket.open.send(secret, 0, dst_host, dst_port)
317324
rescue Errno::ENETUNREACH
318-
# This happens on networks with no gatway. We'll need to use a
325+
# This happens on networks with no gateway. We'll need to use a
319326
# fake source hardware address.
320327
self.arp_cache[Rex::Socket.source_address(addr)] = "00:00:00:00:00:00"
321328
end

0 commit comments

Comments
 (0)