Skip to content

Commit 56ffa4a

Browse files
author
Tod Beardsley
committed
Fixes for network_interface PR rapid7#2085
Implementing the suggestions from @limhoff-r7. See rapid7#2085 FixRM rapid7#8023 FixRM rapid7#7943
1 parent 8ade335 commit 56ffa4a

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ group :db do
2323
end
2424

2525
group :pcap do
26-
gem 'network_interface'
26+
gem 'network_interface', '~> 0.0.1'
2727
# For sniffer and raw socket modules
2828
gem 'pcaprub'
2929
end

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ DEPENDENCIES
6969
json
7070
metasploit_data_models (~> 0.16.1)
7171
msgpack
72-
network_interface
72+
network_interface (~> 0.0.1)
7373
nokogiri
7474
packetfu (= 1.1.8)
7575
pcaprub

lib/msf/core/exploit/capture.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ def initialize(info = {})
6464
end
6565

6666
def stats_recv(pcap=self.capture)
67-
return(0) if not pcap
67+
return(0) unless pcap
6868
pcap.stats['recv']
6969
end
7070

7171
def stats_drop(pcap=self.capture)
72-
return(0) if not pcap
72+
return(0) unless pcap
7373
pcap.stats['drop']
7474
end
7575

7676
def stats_ifdrop(pcap=self.capture)
77-
return(0) if not pcap
77+
return(0) unless pcap
7878
pcap.stats['ifdrop']
7979
end
8080

@@ -133,7 +133,7 @@ def open_pcap(opts={})
133133
end
134134

135135
def close_pcap
136-
return if not self.capture
136+
return unless self.capture
137137
self.capture = nil
138138
self.arp_capture = nil
139139
GC.start()
@@ -147,7 +147,7 @@ def capture_extract_ies(raw)
147147

148148
while (idx < raw.length)
149149
len = raw[idx+1]
150-
return set if not len
150+
return set unless len
151151
set[raw[idx]] ||= []
152152
set[raw[idx]].push(raw[idx + 2, len])
153153
idx += len + 2
@@ -161,7 +161,7 @@ def capture_extract_ies(raw)
161161
# signal handling of Ruby 1.9
162162
#
163163
def each_packet
164-
return if not capture
164+
return unless capture
165165
begin
166166
@capture_count = 0
167167
reader = framework.threads.spawn("PcapReceiver", false) do
@@ -218,7 +218,7 @@ def inject_eth(args={})
218218

219219
def inject_pcap(pcap_file, filter=nil, delay = 0, pcap=self.capture)
220220
check_pcaprub_loaded
221-
if not pcap
221+
unless pcap
222222
raise RuntimeError, "Could not access the capture process (remember to open_pcap first!)"
223223
end
224224

@@ -234,7 +234,7 @@ def inject_pcap(pcap_file, filter=nil, delay = 0, pcap=self.capture)
234234
capture_file.setfilter(filter) if filter
235235
while (pkt = capture_file.next) do
236236
pcap.inject(pkt)
237-
Kernel.select(nil, nil, nil, (delay * 1.0)/1000)
237+
Rex.sleep((delay * 1.0)/1000)
238238
end
239239
GC.start
240240
end
@@ -283,7 +283,7 @@ def inject_reply(proto=:udp, pcap=self.capture)
283283
# UDP packet using the regular socket to learn the source host's
284284
# and gateway's mac addresses.
285285
def lookup_eth(addr=nil, iface=nil)
286-
raise RuntimeError, "Could not access the capture process." if not self.arp_capture
286+
raise RuntimeError, "Could not access the capture process." unless self.arp_capture
287287

288288
self.arp_cache ||= {}
289289
self.dst_cache ||= {}
@@ -336,7 +336,7 @@ def arp(target_ip=nil)
336336
return self.arp_cache[target_ip] if self.arp_cache[target_ip]
337337
return self.arp_cache[:gateway] unless should_arp? target_ip
338338
source_ip = Rex::Socket.source_address(target_ip)
339-
raise RuntimeError, "Could not access the capture process." if not self.arp_capture
339+
raise RuntimeError, "Could not access the capture process." unless self.arp_capture
340340
p = arp_packet(target_ip, source_ip)
341341
inject_eth(:eth_type => 0x0806,
342342
:payload => p,
@@ -515,7 +515,7 @@ def get_ipv4_broadcast(dev, num=0)
515515
def get_ipv6_addr_count(dev)
516516
check_pcaprub_loaded
517517
dev = get_interface_guid(dev)
518-
raise RuntimeError, "IPv6 information is not available on this platform" if not ::NetworkInterface.const_defined?(:AF_INET6)
518+
raise RuntimeError, "IPv6 information is not available on this platform" unless ::NetworkInterface.const_defined?(:AF_INET6)
519519
addrs = NetworkInterface.addresses(dev)
520520
raise RuntimeError, "Interface #{dev} do not exists" if !addrs
521521
addrs[NetworkInterface::AF_INET6].length
@@ -525,7 +525,7 @@ def get_ipv6_addr_count(dev)
525525
def get_ipv6_addr(dev, num=0)
526526
check_pcaprub_loaded
527527
dev = get_interface_guid(dev)
528-
raise RuntimeError, "IPv6 information is not available on this platform" if not ::NetworkInterface.const_defined?(:AF_INET6)
528+
raise RuntimeError, "IPv6 information is not available on this platform" unless ::NetworkInterface.const_defined?(:AF_INET6)
529529
addrs = NetworkInterface.addresses(dev)
530530
raise RuntimeError, "Interface #{dev} do not exists" if !addrs
531531
raise RuntimeError, "Interface #{dev} do not have an ipv6 address at position #{num}" if addrs[NetworkInterface::AF_INET6].length < num + 1
@@ -536,7 +536,7 @@ def get_ipv6_addr(dev, num=0)
536536
def get_ipv6_netmask(dev, num=0)
537537
check_pcaprub_loaded
538538
dev = get_interface_guid(dev)
539-
raise RuntimeError, "IPv6 information is not available on this platform" if not ::NetworkInterface.const_defined?(:AF_INET6)
539+
raise RuntimeError, "IPv6 information is not available on this platform" unless ::NetworkInterface.const_defined?(:AF_INET6)
540540
addrs = NetworkInterface.addresses(dev)
541541
raise RuntimeError, "Interface #{dev} do not exists" if !addrs
542542
raise RuntimeError, "Interface #{dev} do not have an ipv6 address at position #{num}" if addrs[NetworkInterface::AF_INET6].length < num + 1

0 commit comments

Comments
 (0)