Land #2085, use the new network_interface gem.
commit
8ade33552c
1
Gemfile
1
Gemfile
|
@ -23,6 +23,7 @@ group :db do
|
||||||
end
|
end
|
||||||
|
|
||||||
group :pcap do
|
group :pcap do
|
||||||
|
gem 'network_interface'
|
||||||
# For sniffer and raw socket modules
|
# For sniffer and raw socket modules
|
||||||
gem 'pcaprub'
|
gem 'pcaprub'
|
||||||
end
|
end
|
||||||
|
|
|
@ -31,6 +31,7 @@ GEM
|
||||||
metaclass (~> 0.0.1)
|
metaclass (~> 0.0.1)
|
||||||
msgpack (0.5.4)
|
msgpack (0.5.4)
|
||||||
multi_json (1.0.4)
|
multi_json (1.0.4)
|
||||||
|
network_interface (0.0.1)
|
||||||
nokogiri (1.5.9)
|
nokogiri (1.5.9)
|
||||||
packetfu (1.1.8)
|
packetfu (1.1.8)
|
||||||
pcaprub (0.11.3)
|
pcaprub (0.11.3)
|
||||||
|
@ -68,6 +69,7 @@ DEPENDENCIES
|
||||||
json
|
json
|
||||||
metasploit_data_models (~> 0.16.1)
|
metasploit_data_models (~> 0.16.1)
|
||||||
msgpack
|
msgpack
|
||||||
|
network_interface
|
||||||
nokogiri
|
nokogiri
|
||||||
packetfu (= 1.1.8)
|
packetfu (= 1.1.8)
|
||||||
pcaprub
|
pcaprub
|
||||||
|
|
|
@ -53,6 +53,14 @@ module Capture
|
||||||
@pcaprub_error = e
|
@pcaprub_error = e
|
||||||
end
|
end
|
||||||
|
|
||||||
|
begin
|
||||||
|
require 'network_interface'
|
||||||
|
@network_interface_loaded = true
|
||||||
|
rescue ::Exception => e
|
||||||
|
@network_interface_loaded = false
|
||||||
|
@network_interface_error = e
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def stats_recv(pcap=self.capture)
|
def stats_recv(pcap=self.capture)
|
||||||
|
@ -376,6 +384,9 @@ module Capture
|
||||||
if not @pcaprub_loaded
|
if not @pcaprub_loaded
|
||||||
print_status("The Pcaprub module is not available: #{@pcaprub_error}")
|
print_status("The Pcaprub module is not available: #{@pcaprub_error}")
|
||||||
raise RuntimeError, "Pcaprub not available"
|
raise RuntimeError, "Pcaprub not available"
|
||||||
|
elsif not @network_interface_loaded
|
||||||
|
print_status("The NetworkInterface module is not available: #{@network_interface_error}")
|
||||||
|
raise RuntimeError, "NetworkInterface not available"
|
||||||
else
|
else
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
@ -406,29 +417,24 @@ module Capture
|
||||||
|
|
||||||
#Netifaces code
|
#Netifaces code
|
||||||
|
|
||||||
# netifaces code is not available in pcaprub 0.9.2 and prior,
|
|
||||||
# which is going to be installed in a lot of places. Modules
|
|
||||||
# which want it should check explicitly for it. TODO: Bug upstream
|
|
||||||
# to release it for real in 0.9.3
|
|
||||||
def netifaces_implemented?
|
def netifaces_implemented?
|
||||||
@pcaprub_loaded and
|
@network_interface_loaded and
|
||||||
Pcap.respond_to?(:lookupaddrs) and
|
NetworkInterface.respond_to?(:interfaces) and
|
||||||
Pcap.respond_to?(:interfaces) and
|
NetworkInterface.respond_to?(:addresses)
|
||||||
Pcap.respond_to?(:addresses)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def list_interfaces
|
def list_interfaces
|
||||||
check_pcaprub_loaded
|
check_pcaprub_loaded
|
||||||
Pcap.interfaces
|
NetworkInterface.interfaces
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_interface?(dev)
|
def is_interface?(dev)
|
||||||
check_pcaprub_loaded
|
check_pcaprub_loaded
|
||||||
if RUBY_PLATFORM == "i386-mingw32"
|
if RUBY_PLATFORM == "i386-mingw32"
|
||||||
if dev =~ /\\Device\\NPF_\{[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}\}/
|
if dev =~ /\\Device\\NPF_\{[A-F0-9]{8}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{4}-[A-F0-9]{12}\}/
|
||||||
return Pcap.interfaces.include?(dev)
|
return NetworkInterface.interfaces.include?(dev)
|
||||||
elsif dev.to_s =~ /^[0-9]{1,2}$/
|
elsif dev.to_s =~ /^[0-9]{1,2}$/
|
||||||
if (dev.to_i <= Pcap.interfaces.length) and (dev.to_i >= 0)
|
if (dev.to_i <= NetworkInterface.interfaces.length) and (dev.to_i >= 0)
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
|
@ -437,7 +443,7 @@ module Capture
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
return Pcap.interfaces.include?(dev)
|
return NetworkInterface.interfaces.include?(dev)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -447,7 +453,7 @@ module Capture
|
||||||
if RUBY_PLATFORM == "i386-mingw32"
|
if RUBY_PLATFORM == "i386-mingw32"
|
||||||
if dev.to_s =~ /^[0-9]{1,2}$/
|
if dev.to_s =~ /^[0-9]{1,2}$/
|
||||||
if is_interface?(dev)
|
if is_interface?(dev)
|
||||||
Pcap.interfaces[(dev.to_i) - 1]
|
NetworkInterface.interfaces[(dev.to_i) - 1]
|
||||||
else
|
else
|
||||||
return dev
|
return dev
|
||||||
end
|
end
|
||||||
|
@ -462,80 +468,80 @@ module Capture
|
||||||
def get_mac(dev)
|
def get_mac(dev)
|
||||||
check_pcaprub_loaded
|
check_pcaprub_loaded
|
||||||
dev = get_interface_guid(dev)
|
dev = get_interface_guid(dev)
|
||||||
addrs = Pcap.addresses(dev)
|
addrs = NetworkInterface.addresses(dev)
|
||||||
raise RuntimeError, "Interface #{dev} does not exist" if !addrs
|
raise RuntimeError, "Interface #{dev} does not exist" if !addrs
|
||||||
raise RuntimeError, "Can not get mac address for interface #{dev}" if !addrs[Pcap::AF_LINK][0]['addr']
|
raise RuntimeError, "Can not get mac address for interface #{dev}" if !addrs[NetworkInterface::AF_LINK][0]['addr']
|
||||||
addrs[Pcap::AF_LINK][0]['addr']
|
addrs[NetworkInterface::AF_LINK][0]['addr']
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_ipv4_addr_count(dev)
|
def get_ipv4_addr_count(dev)
|
||||||
check_pcaprub_loaded
|
check_pcaprub_loaded
|
||||||
dev = get_interface_guid(dev)
|
dev = get_interface_guid(dev)
|
||||||
addrs = Pcap.addresses(dev)
|
addrs = NetworkInterface.addresses(dev)
|
||||||
raise RuntimeError, "Interface #{dev} does not exist" if !addrs
|
raise RuntimeError, "Interface #{dev} does not exist" if !addrs
|
||||||
addrs[Pcap::AF_INET].length
|
addrs[NetworkInterface::AF_INET].length
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_ipv4_addr(dev, num=0)
|
def get_ipv4_addr(dev, num=0)
|
||||||
check_pcaprub_loaded
|
check_pcaprub_loaded
|
||||||
dev = get_interface_guid(dev)
|
dev = get_interface_guid(dev)
|
||||||
addrs = Pcap.addresses(dev)
|
addrs = NetworkInterface.addresses(dev)
|
||||||
raise RuntimeError, "Interface #{dev} do not exists" if !addrs
|
raise RuntimeError, "Interface #{dev} do not exists" if !addrs
|
||||||
raise RuntimeError, "Interface #{dev} do not have an ipv4 address at position #{num}" if addrs[Pcap::AF_INET].length < num + 1
|
raise RuntimeError, "Interface #{dev} do not have an ipv4 address at position #{num}" if addrs[NetworkInterface::AF_INET].length < num + 1
|
||||||
raise RuntimeError, "Can not get the IPv4 address for interface #{dev}" if !addrs[Pcap::AF_INET][num]['addr']
|
raise RuntimeError, "Can not get the IPv4 address for interface #{dev}" if !addrs[NetworkInterface::AF_INET][num]['addr']
|
||||||
addrs[Pcap::AF_INET][num]['addr']
|
addrs[NetworkInterface::AF_INET][num]['addr']
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_ipv4_netmask(dev, num=0)
|
def get_ipv4_netmask(dev, num=0)
|
||||||
check_pcaprub_loaded
|
check_pcaprub_loaded
|
||||||
dev = get_interface_guid(dev)
|
dev = get_interface_guid(dev)
|
||||||
addrs = Pcap.addresses(dev)
|
addrs = NetworkInterface.addresses(dev)
|
||||||
raise RuntimeError, "Interface #{dev} do not exists" if !addrs
|
raise RuntimeError, "Interface #{dev} do not exists" if !addrs
|
||||||
raise RuntimeError, "Interface #{dev} do not have an ipv4 address at position #{num}" if addrs[Pcap::AF_INET].length < num + 1
|
raise RuntimeError, "Interface #{dev} do not have an ipv4 address at position #{num}" if addrs[NetworkInterface::AF_INET].length < num + 1
|
||||||
raise RuntimeError, "Can not get IPv4 netmask for interface #{dev}" if !addrs[Pcap::AF_INET][num]['netmask']
|
raise RuntimeError, "Can not get IPv4 netmask for interface #{dev}" if !addrs[NetworkInterface::AF_INET][num]['netmask']
|
||||||
addrs[Pcap::AF_INET][num]['netmask']
|
addrs[NetworkInterface::AF_INET][num]['netmask']
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_ipv4_broadcast(dev, num=0)
|
def get_ipv4_broadcast(dev, num=0)
|
||||||
check_pcaprub_loaded
|
check_pcaprub_loaded
|
||||||
dev = get_interface_guid(dev)
|
dev = get_interface_guid(dev)
|
||||||
addrs = Pcap.addresses(dev)
|
addrs = NetworkInterface.addresses(dev)
|
||||||
raise RuntimeError, "Interface #{dev} do not exists" if !addrs
|
raise RuntimeError, "Interface #{dev} do not exists" if !addrs
|
||||||
raise RuntimeError, "Interface #{dev} do not have an ipv4 address at position #{num}" if addrs[Pcap::AF_INET].length < num + 1
|
raise RuntimeError, "Interface #{dev} do not have an ipv4 address at position #{num}" if addrs[NetworkInterface::AF_INET].length < num + 1
|
||||||
raise RuntimeError, "Can not get IPv4 broadcast address for interface #{dev}" if !addrs[Pcap::AF_INET][num]['broadcast']
|
raise RuntimeError, "Can not get IPv4 broadcast address for interface #{dev}" if !addrs[NetworkInterface::AF_INET][num]['broadcast']
|
||||||
addrs[Pcap::AF_INET][num]['broadcast']
|
addrs[NetworkInterface::AF_INET][num]['broadcast']
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_ipv6_addr_count(dev)
|
def get_ipv6_addr_count(dev)
|
||||||
check_pcaprub_loaded
|
check_pcaprub_loaded
|
||||||
dev = get_interface_guid(dev)
|
dev = get_interface_guid(dev)
|
||||||
raise RuntimeError, "IPv6 information is not available on this platform" if not ::Pcap.const_defined?(:AF_INET6)
|
raise RuntimeError, "IPv6 information is not available on this platform" if not ::NetworkInterface.const_defined?(:AF_INET6)
|
||||||
addrs = Pcap.addresses(dev)
|
addrs = NetworkInterface.addresses(dev)
|
||||||
raise RuntimeError, "Interface #{dev} do not exists" if !addrs
|
raise RuntimeError, "Interface #{dev} do not exists" if !addrs
|
||||||
addrs[Pcap::AF_INET6].length
|
addrs[NetworkInterface::AF_INET6].length
|
||||||
end
|
end
|
||||||
|
|
||||||
# NOTE: IPv6 is not implemented on Windows
|
# NOTE: IPv6 is not implemented on Windows
|
||||||
def get_ipv6_addr(dev, num=0)
|
def get_ipv6_addr(dev, num=0)
|
||||||
check_pcaprub_loaded
|
check_pcaprub_loaded
|
||||||
dev = get_interface_guid(dev)
|
dev = get_interface_guid(dev)
|
||||||
raise RuntimeError, "IPv6 information is not available on this platform" if not ::Pcap.const_defined?(:AF_INET6)
|
raise RuntimeError, "IPv6 information is not available on this platform" if not ::NetworkInterface.const_defined?(:AF_INET6)
|
||||||
addrs = Pcap.addresses(dev)
|
addrs = NetworkInterface.addresses(dev)
|
||||||
raise RuntimeError, "Interface #{dev} do not exists" if !addrs
|
raise RuntimeError, "Interface #{dev} do not exists" if !addrs
|
||||||
raise RuntimeError, "Interface #{dev} do not have an ipv6 address at position #{num}" if addrs[Pcap::AF_INET6].length < num + 1
|
raise RuntimeError, "Interface #{dev} do not have an ipv6 address at position #{num}" if addrs[NetworkInterface::AF_INET6].length < num + 1
|
||||||
raise RuntimeError, "Can not get ipv6 address for interface #{dev}" if !addrs[Pcap::AF_INET6][num]['addr']
|
raise RuntimeError, "Can not get ipv6 address for interface #{dev}" if !addrs[NetworkInterface::AF_INET6][num]['addr']
|
||||||
addrs[Pcap::AF_INET6][num]['addr'].gsub(/%(.)*$/,'')
|
addrs[NetworkInterface::AF_INET6][num]['addr'].gsub(/%(.)*$/, '')
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_ipv6_netmask(dev, num=0)
|
def get_ipv6_netmask(dev, num=0)
|
||||||
check_pcaprub_loaded
|
check_pcaprub_loaded
|
||||||
dev = get_interface_guid(dev)
|
dev = get_interface_guid(dev)
|
||||||
raise RuntimeError, "IPv6 information is not available on this platform" if not ::Pcap.const_defined?(:AF_INET6)
|
raise RuntimeError, "IPv6 information is not available on this platform" if not ::NetworkInterface.const_defined?(:AF_INET6)
|
||||||
addrs = Pcap.addresses(dev)
|
addrs = NetworkInterface.addresses(dev)
|
||||||
raise RuntimeError, "Interface #{dev} do not exists" if !addrs
|
raise RuntimeError, "Interface #{dev} do not exists" if !addrs
|
||||||
raise RuntimeError, "Interface #{dev} do not have an ipv6 address at position #{num}" if addrs[Pcap::AF_INET6].length < num + 1
|
raise RuntimeError, "Interface #{dev} do not have an ipv6 address at position #{num}" if addrs[NetworkInterface::AF_INET6].length < num + 1
|
||||||
raise RuntimeError, "Can not get ipv6 netmask address for interface #{dev}" if !addrs[Pcap::AF_INET6][num]['netmask']
|
raise RuntimeError, "Can not get ipv6 netmask address for interface #{dev}" if !addrs[NetworkInterface::AF_INET6][num]['netmask']
|
||||||
addrs[Pcap::AF_INET6][num]['netmask']
|
addrs[NetworkInterface::AF_INET6][num]['netmask']
|
||||||
end
|
end
|
||||||
|
|
||||||
# Protocol-specific encoding/decoding methods until more
|
# Protocol-specific encoding/decoding methods until more
|
||||||
|
|
|
@ -44,7 +44,7 @@ class Metasploit3 < Msf::Auxiliary
|
||||||
|
|
||||||
@netifaces = true
|
@netifaces = true
|
||||||
if not netifaces_implemented?
|
if not netifaces_implemented?
|
||||||
print_error("WARNING : Pcaprub is not uptodate, some functionality will not be available")
|
print_error("WARNING : NetworkInterface is not up-to-date, some functionality will not be available")
|
||||||
@netifaces = false
|
@netifaces = false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -23,37 +23,40 @@ $:.unshift(ENV['MSF_LOCAL_LIB']) if ENV['MSF_LOCAL_LIB']
|
||||||
|
|
||||||
if RUBY_PLATFORM == "i386-mingw32"
|
if RUBY_PLATFORM == "i386-mingw32"
|
||||||
begin
|
begin
|
||||||
require 'pcaprub'
|
require 'network_interface'
|
||||||
rescue ::Exception => e
|
rescue ::Exception => e
|
||||||
$stderr.puts "Error: pcaprub is not installed..."
|
$stderr.puts "Error: NetworkInterface is not installed..."
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
unless (Pcap.respond_to?(:lookupaddrs) and
|
|
||||||
Pcap.respond_to?(:interfaces) and
|
unless (
|
||||||
Pcap.respond_to?(:addresses))
|
NetworkInterface.respond_to?(:interfaces) and
|
||||||
$stderr.puts "Error: Looks like you are not running the latest version of pcaprub"
|
NetworkInterface.respond_to?(:addresses) and
|
||||||
|
NetworkInterface.respond_to?(:interface_info)
|
||||||
|
)
|
||||||
|
$stderr.puts "Error: Looks like you are not running the latest version of NetworkInterface"
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
found = false
|
found = false
|
||||||
Pcap.interfaces.each_with_index do |iface, i|
|
NetworkInterface.interfaces.each_with_index do |iface, i|
|
||||||
found = true
|
found = true
|
||||||
detail = Pcap.interface_info(iface)
|
detail = NetworkInterface.interface_info(iface)
|
||||||
addr = Pcap.addresses(iface)
|
addr = NetworkInterface.addresses(iface)
|
||||||
puts "#" * 70
|
puts "#" * 70
|
||||||
puts ""
|
puts ""
|
||||||
puts "INDEX : " + (i + 1).to_s
|
puts "INDEX : " + (i + 1).to_s
|
||||||
puts "NAME : " + detail["name"]
|
puts "NAME : " + detail["name"]
|
||||||
puts "DESCRIPTION : " + detail["description"]
|
puts "DESCRIPTION : " + detail["description"]
|
||||||
puts "GUID : " + detail["guid"]
|
puts "GUID : " + detail["guid"]
|
||||||
if addr[Pcap::AF_LINK][0]['addr']
|
if addr[NetworkInterface::AF_LINK][0]['addr']
|
||||||
puts "MAC ADDRESSE : #{addr[Pcap::AF_LINK][0]['addr']}"
|
puts "MAC ADDRESS : #{addr[NetworkInterface::AF_LINK][0]['addr']}"
|
||||||
else
|
else
|
||||||
puts "MAC ADDRESSE : NONE"
|
puts "MAC ADDRESS : NONE"
|
||||||
end
|
end
|
||||||
if addr[Pcap::AF_INET][0]['addr'] and addr[Pcap::AF_INET][0]['netmask']
|
if addr[NetworkInterface::AF_INET][0]['addr'] and addr[NetworkInterface::AF_INET][0]['netmask']
|
||||||
puts "IP ADDRESSE : #{addr[Pcap::AF_INET][0]['addr']}/#{addr[Pcap::AF_INET][0]['netmask']}"
|
puts "IP ADDRESS : #{addr[NetworkInterface::AF_INET][0]['addr']}/#{addr[NetworkInterface::AF_INET][0]['netmask']}"
|
||||||
else
|
else
|
||||||
puts "IP ADDRESSE : NONE"
|
puts "IP ADDRESS : NONE"
|
||||||
end
|
end
|
||||||
puts ""
|
puts ""
|
||||||
end
|
end
|
||||||
|
@ -63,8 +66,6 @@ if RUBY_PLATFORM == "i386-mingw32"
|
||||||
$stderr.puts "Error, no network interfaces have been detected"
|
$stderr.puts "Error, no network interfaces have been detected"
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
$stderr.puts "Error: This script is usefull only on Windows, under other OS just use the built-in commands (ifconfig, ip link show, ...)"
|
$stderr.puts "Error: This script is useful only on Windows, under other OS just use the built-in commands (ifconfig, ip link show, ...)"
|
||||||
exit
|
exit
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue