@@ -37,9 +37,16 @@ def initialize(info = {})
37
37
38
38
register_advanced_options (
39
39
[
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.' ] ) ,
42
- OptInt . new ( 'NETMASK' , [ false , 'The local network mask. This is used to decide if an address is in the local network.' , 24 ] ) ,
40
+ OptInt . new ( 'SECRET' , [ true , 'A 32-bit cookie for probe requests.' , 'MSF!' . unpack ( 'N' ) . first ] ) ,
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)' ] )
43
50
] , Msf ::Exploit ::Capture
44
51
)
45
52
@@ -117,7 +124,7 @@ def open_pcap(opts={})
117
124
self . capture = ::Pcap . open_live ( dev , len , true , tim )
118
125
if do_arp
119
126
self . arp_capture = ::Pcap . open_live ( dev , 512 , true , tim )
120
- preamble = datastore [ 'UDP_SECRET ' ] . to_i
127
+ preamble = datastore [ 'SECRET ' ] . to_i
121
128
arp_filter = "arp[6:2] = 2 or (udp[8:4] = #{ preamble } )"
122
129
self . arp_capture . setfilter ( arp_filter )
123
130
end
@@ -304,15 +311,18 @@ def lookup_eth(addr=nil, iface=nil)
304
311
end
305
312
306
313
def probe_gateway ( addr )
307
- dst_host = ( datastore [ 'GATEWAY' ] || IPAddr . new ( ( rand ( 16777216 ) + 2969567232 ) , Socket :: AF_INET ) . to_s )
308
- dst_port = rand ( 30000 ) + 1024
309
- 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" )
310
317
secret = "#{ preamble } #{ Rex ::Text . rand_text ( rand ( 0xff ) +1 ) } "
311
318
312
319
begin
313
- UDPSocket . open . send ( secret , 0 , dst_host , dst_port )
320
+ UDPSocket . open do |sock |
321
+ sock . setsockopt ( ::Socket ::IPPROTO_IP , ::Socket ::IP_TTL , 1 )
322
+ sock . send ( secret , 0 , dst_host , dst_port )
323
+ end
314
324
rescue Errno ::ENETUNREACH
315
- # 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
316
326
# fake source hardware address.
317
327
self . arp_cache [ Rex ::Socket . source_address ( addr ) ] = "00:00:00:00:00:00"
318
328
end
@@ -402,9 +412,11 @@ def check_pcaprub_loaded
402
412
def lookupnet
403
413
check_pcaprub_loaded
404
414
dev = datastore [ 'INTERFACE' ] || ::Pcap . lookupdev
405
- mask = datastore [ 'NETMASK' ] || 24
406
415
begin
407
- my_net = IPAddr . new ( "#{ Pcap . lookupnet ( dev ) . first } /#{ mask } " )
416
+ my_ip , my_mask = Pcap . lookupnet ( dev )
417
+ # convert the netmask obtained from the relevant interface to CIDR
418
+ cidr_mask = my_mask . to_s ( 2 ) . count ( '1' )
419
+ my_net = IPAddr . new ( "#{ my_ip } /#{ cidr_mask } " )
408
420
rescue RuntimeError => e
409
421
@pcaprub_error = e
410
422
print_status ( "Cannot stat device: #{ @pcaprub_error } " )
@@ -414,10 +426,7 @@ def lookupnet
414
426
end
415
427
416
428
def should_arp? ( ip )
417
- @mydev ||= datastore [ 'INTERFACE' ] || ::Pcap . lookupdev
418
- @mymask ||= datastore [ 'NETMASK' ] || 24
419
- @mynet ||= lookupnet
420
- @mynet . include? ( IPAddr . new ( ip ) )
429
+ lookupnet . include? ( IPAddr . new ( ip ) )
421
430
end
422
431
423
432
attr_accessor :capture , :arp_cache , :arp_capture , :dst_cache
0 commit comments