Skip to content

Commit d8b1401

Browse files
committed
Test fix for rapid7#4306
1 parent 8f2e444 commit d8b1401

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

lib/msf/core/exploit/capture.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ def initialize(info = {})
3939
[
4040
OptInt.new('UDP_SECRET', [true, 'The 32-bit cookie for UDP probe requests.', 1297303091]),
4141
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]),
4342
], Msf::Exploit::Capture
4443
)
4544

@@ -402,9 +401,11 @@ def check_pcaprub_loaded
402401
def lookupnet
403402
check_pcaprub_loaded
404403
dev = datastore['INTERFACE'] || ::Pcap.lookupdev
405-
mask = datastore['NETMASK'] || 24
406404
begin
407-
my_net = IPAddr.new("#{Pcap.lookupnet(dev).first}/#{mask}")
405+
my_ip, my_mask = Pcap.lookupnet(dev)
406+
# convert the netmask obtained from the relevant interface to CIDR
407+
cidr_mask = my_mask.to_s(2).count('1')
408+
my_net = IPAddr.new("#{my_ip}/#{cidr_mask}")
408409
rescue RuntimeError => e
409410
@pcaprub_error = e
410411
print_status("Cannot stat device: #{@pcaprub_error}")
@@ -414,10 +415,7 @@ def lookupnet
414415
end
415416

416417
def should_arp?(ip)
417-
@mydev ||= datastore['INTERFACE'] || ::Pcap.lookupdev
418-
@mymask ||= datastore['NETMASK'] || 24
419-
@mynet ||= lookupnet
420-
@mynet.include?(IPAddr.new(ip))
418+
lookupnet.include?(IPAddr.new(ip))
421419
end
422420

423421
attr_accessor :capture, :arp_cache, :arp_capture, :dst_cache

0 commit comments

Comments
 (0)