2007-02-15 21:14:36 +00:00
|
|
|
module Msf
|
|
|
|
|
|
|
|
###
|
|
|
|
#
|
2010-02-20 18:31:46 +00:00
|
|
|
# This module provides methods for sending and receiving
|
2010-01-26 06:38:41 +00:00
|
|
|
# raw packets. It should be preferred over the soon-to-be
|
2010-02-20 18:31:46 +00:00
|
|
|
# deprecated Rex::Socket::Ip and Msf::Exploite::Remote::Ip
|
2010-01-27 19:37:22 +00:00
|
|
|
# mixins.
|
2010-01-26 06:38:41 +00:00
|
|
|
#
|
2010-01-27 19:37:22 +00:00
|
|
|
# Please see the pcaprub documentation for more information
|
|
|
|
# on how to use capture objects.
|
2007-02-15 21:14:36 +00:00
|
|
|
#
|
|
|
|
###
|
|
|
|
|
|
|
|
module Exploit::Capture
|
|
|
|
|
|
|
|
#
|
|
|
|
# Initializes an instance of an exploit module that captures traffic
|
|
|
|
#
|
2009-11-02 14:36:53 +00:00
|
|
|
|
2007-02-15 21:14:36 +00:00
|
|
|
def initialize(info = {})
|
|
|
|
super
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
2009-07-16 22:08:31 +00:00
|
|
|
OptPath.new('PCAPFILE', [false, 'The name of the PCAP capture file to process']),
|
2007-02-15 21:14:36 +00:00
|
|
|
OptString.new('INTERFACE', [false, 'The name of the interface']),
|
|
|
|
OptString.new('FILTER', [false, 'The filter string for capturing traffic']),
|
2008-01-07 07:00:42 +00:00
|
|
|
OptInt.new('SNAPLEN', [true, 'The number of bytes to capture', 65535]),
|
2010-01-26 21:37:40 +00:00
|
|
|
OptInt.new('TIMEOUT', [true, 'The number of seconds to wait for new data', 500]),
|
2010-01-27 19:37:22 +00:00
|
|
|
Opt::RHOST
|
2007-02-15 21:14:36 +00:00
|
|
|
|
|
|
|
], Msf::Exploit::Capture
|
|
|
|
)
|
2009-11-02 14:36:53 +00:00
|
|
|
|
2010-01-27 17:51:16 +00:00
|
|
|
register_advanced_options(
|
|
|
|
[
|
2010-03-16 16:04:02 +00:00
|
|
|
OptInt.new('UDP_SECRET', [true, 'The 32-bit cookie for UDP probe requests.', 1297303091]),
|
2010-01-27 21:19:23 +00:00
|
|
|
OptAddress.new('GATEWAY', [false, 'The gateway IP address. This will be used rather than a random remote address for the UDP probe, if set.']),
|
|
|
|
OptInt.new('NETMASK', [false, 'The local network mask. This is used to decide if an address is in the local network.', 24]),
|
2010-01-27 17:51:16 +00:00
|
|
|
], Msf::Exploit::Capture
|
|
|
|
)
|
|
|
|
|
2009-07-17 20:36:40 +00:00
|
|
|
require 'racket'
|
2009-11-02 14:36:53 +00:00
|
|
|
|
2007-02-15 21:14:36 +00:00
|
|
|
begin
|
2008-01-25 05:59:06 +00:00
|
|
|
require 'pcaprub'
|
2008-01-07 07:00:42 +00:00
|
|
|
@pcaprub_loaded = true
|
2007-02-15 21:14:36 +00:00
|
|
|
rescue ::Exception => e
|
2008-01-07 07:00:42 +00:00
|
|
|
@pcaprub_loaded = false
|
|
|
|
@pcaprub_error = e
|
2007-02-15 21:14:36 +00:00
|
|
|
end
|
2009-11-02 14:36:53 +00:00
|
|
|
|
2007-02-15 21:14:36 +00:00
|
|
|
end
|
|
|
|
|
2010-01-27 17:51:16 +00:00
|
|
|
def stats_recv(pcap=self.capture)
|
|
|
|
return(0) if not pcap
|
|
|
|
pcap.stats['recv']
|
2007-02-15 21:14:36 +00:00
|
|
|
end
|
|
|
|
|
2010-01-27 17:51:16 +00:00
|
|
|
def stats_drop(pcap=self.capture)
|
|
|
|
return(0) if not pcap
|
|
|
|
pcap.stats['drop']
|
2007-02-15 21:14:36 +00:00
|
|
|
end
|
|
|
|
|
2010-01-27 17:51:16 +00:00
|
|
|
def stats_ifdrop(pcap=self.capture)
|
|
|
|
return(0) if not pcap
|
|
|
|
pcap.stats['ifdrop']
|
2008-01-07 07:00:42 +00:00
|
|
|
end
|
2009-11-02 14:36:53 +00:00
|
|
|
|
2007-02-15 21:14:36 +00:00
|
|
|
#
|
|
|
|
# Opens a handle to the specified device
|
|
|
|
#
|
2009-07-21 17:48:10 +00:00
|
|
|
def open_pcap(opts={})
|
2010-02-01 15:11:35 +00:00
|
|
|
check_pcaprub_loaded
|
2009-11-02 14:36:53 +00:00
|
|
|
|
2007-02-15 21:14:36 +00:00
|
|
|
# Capture device
|
2010-07-14 20:38:19 +00:00
|
|
|
dev = opts['INTERFACE'] || datastore['INTERFACE'] || nil
|
2009-07-21 17:48:10 +00:00
|
|
|
len = (opts['SNAPLEN'] || datastore['SNAPLEN'] || 65535).to_i
|
|
|
|
tim = (opts['TIMEOUT'] || datastore['TIMEOUT'] || 0).to_i
|
|
|
|
fil = opts['FILTER'] || datastore['FILTER']
|
2010-01-27 17:51:16 +00:00
|
|
|
arp = opts['ARPCAP'] || true
|
2009-11-02 14:36:53 +00:00
|
|
|
|
2009-07-16 22:08:31 +00:00
|
|
|
# Look for a PCAP file
|
|
|
|
cap = datastore['PCAPFILE'] || ''
|
2009-11-02 14:36:53 +00:00
|
|
|
|
2009-07-16 22:08:31 +00:00
|
|
|
if(not cap.empty?)
|
|
|
|
if(not File.exists?(cap))
|
|
|
|
raise RuntimeError, "The PCAP file #{cap} could not be found"
|
|
|
|
end
|
|
|
|
self.capture = ::Pcap.open_offline(cap)
|
|
|
|
else
|
2010-07-14 20:38:19 +00:00
|
|
|
dev ||= ::Pcap.lookupdev
|
2009-07-16 22:08:31 +00:00
|
|
|
system("ifconfig", dev, "up")
|
|
|
|
self.capture = ::Pcap.open_live(dev, len, true, tim)
|
2010-01-27 17:51:16 +00:00
|
|
|
if arp
|
|
|
|
self.arp_capture = ::Pcap.open_live(dev, 512, true, tim)
|
2010-03-16 16:04:02 +00:00
|
|
|
preamble = datastore['UDP_SECRET'].to_i
|
|
|
|
arp_filter = "arp[6:2] = 2 or (udp[8:4] = #{preamble})"
|
2010-02-20 18:31:46 +00:00
|
|
|
self.arp_capture.setfilter(arp_filter)
|
2010-01-27 17:51:16 +00:00
|
|
|
end
|
2009-07-16 22:08:31 +00:00
|
|
|
end
|
2007-02-15 21:14:36 +00:00
|
|
|
|
|
|
|
if (not self.capture)
|
2009-07-16 22:08:31 +00:00
|
|
|
raise RuntimeError, "Could not start the capture process"
|
2010-02-20 18:31:46 +00:00
|
|
|
elsif (arp and !self.arp_capture)
|
2010-01-27 15:11:18 +00:00
|
|
|
raise RuntimeError, "Could not start the ARP capture process"
|
2007-02-15 21:14:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
self.capture.setfilter(fil) if fil
|
|
|
|
end
|
|
|
|
|
2009-11-02 14:36:53 +00:00
|
|
|
def close_pcap
|
2007-02-15 21:14:36 +00:00
|
|
|
return if not self.capture
|
|
|
|
self.capture = nil
|
2010-01-27 15:11:18 +00:00
|
|
|
self.arp_capture = nil
|
2009-07-21 19:36:37 +00:00
|
|
|
GC.start()
|
2007-02-15 21:14:36 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def capture_extract_ies(raw)
|
|
|
|
set = {}
|
|
|
|
ret = 0
|
|
|
|
idx = 0
|
|
|
|
len = 0
|
|
|
|
|
|
|
|
while (idx < raw.length)
|
|
|
|
len = raw[idx+1]
|
|
|
|
return set if not len
|
|
|
|
set[ raw[idx] ] ||= []
|
|
|
|
set[ raw[idx] ].push(raw[idx + 2, len])
|
|
|
|
idx += len + 2
|
|
|
|
end
|
|
|
|
|
|
|
|
return set
|
|
|
|
end
|
2009-11-02 14:36:53 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# This monstrosity works around a series of bugs in the interrupt
|
|
|
|
# signal handling of Ruby 1.9
|
|
|
|
#
|
2008-01-07 07:00:42 +00:00
|
|
|
def each_packet
|
2009-11-02 14:36:53 +00:00
|
|
|
return if not capture
|
|
|
|
begin
|
|
|
|
@capture_count = 0
|
2010-11-12 06:19:49 +00:00
|
|
|
reader = framework.threads.spawn("PcapReceiver", false) do
|
2009-11-02 14:36:53 +00:00
|
|
|
capture.each do |pkt|
|
|
|
|
yield(pkt)
|
|
|
|
@capture_count += 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
reader.join
|
|
|
|
rescue ::Exception
|
|
|
|
raise $!
|
|
|
|
ensure
|
|
|
|
reader.kill if reader.alive?
|
2008-01-25 05:59:06 +00:00
|
|
|
end
|
2009-11-02 14:36:53 +00:00
|
|
|
|
|
|
|
@capture_count
|
2008-01-07 07:00:42 +00:00
|
|
|
end
|
2007-02-15 21:14:36 +00:00
|
|
|
|
2010-01-26 16:00:16 +00:00
|
|
|
# Injects a packet on the wire. For all injection-related functions, it's
|
|
|
|
# on the module to open up a capture device first (this way, we don't
|
|
|
|
# needlessly spawn new capture devices).
|
2010-01-27 17:51:16 +00:00
|
|
|
def inject(pkt="",pcap=self.capture)
|
2010-02-01 15:11:35 +00:00
|
|
|
check_pcaprub_loaded
|
2010-01-27 17:51:16 +00:00
|
|
|
if not pcap
|
2010-01-26 06:38:41 +00:00
|
|
|
raise RuntimeError, "Could not access the capture process (remember to open_pcap first!)"
|
|
|
|
else
|
2010-01-27 17:51:16 +00:00
|
|
|
pcap.inject(pkt)
|
2010-01-26 06:38:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-01-26 16:00:16 +00:00
|
|
|
# Injects an Ethernet packet with an optional payload.
|
2010-01-26 06:38:41 +00:00
|
|
|
def inject_eth(args={})
|
|
|
|
eth_daddr = args[:eth_daddr] || "ff:ff:ff:ff:ff:ff"
|
|
|
|
eth_saddr = args[:eth_saddr] || "00:00:00:00:00:00"
|
2010-01-26 16:00:16 +00:00
|
|
|
eth_type = args[:eth_type] || 0x0800 # IP default
|
2010-01-26 06:38:41 +00:00
|
|
|
payload = args[:payload]
|
2010-01-27 17:51:16 +00:00
|
|
|
pcap = args[:pcap] || self.capture
|
2010-01-26 06:38:41 +00:00
|
|
|
n = Racket::Racket.new
|
|
|
|
n.l2 = Racket::L2::Ethernet.new
|
|
|
|
n.l2.dst_mac = eth_daddr
|
|
|
|
n.l2.src_mac = eth_saddr
|
2010-01-26 16:00:16 +00:00
|
|
|
n.l2.ethertype = eth_type
|
2010-01-26 06:38:41 +00:00
|
|
|
pkt = n.pack
|
|
|
|
pkt += payload if payload
|
2010-01-27 17:51:16 +00:00
|
|
|
inject pkt,pcap
|
2010-01-26 06:38:41 +00:00
|
|
|
end
|
|
|
|
|
2011-04-22 18:25:19 +00:00
|
|
|
def inject_pcap(pcap_file, filter=nil, delay = 0, pcap=self.capture)
|
|
|
|
check_pcaprub_loaded
|
|
|
|
if not pcap
|
|
|
|
raise RuntimeError, "Could not access the capture process (remember to open_pcap first!)"
|
|
|
|
end
|
|
|
|
|
|
|
|
if(not File.exists?(pcap_file))
|
|
|
|
raise RuntimeError, "The PCAP file #{pcap_file} could not be found"
|
|
|
|
end
|
|
|
|
|
|
|
|
if(pcap_file.empty?)
|
|
|
|
raise RuntimeError, "The PCAP file #{pcap_file} is empty"
|
|
|
|
end
|
|
|
|
|
|
|
|
capture_file = ::Pcap.open_offline(pcap_file)
|
|
|
|
capture_file.setfilter(filter) if filter
|
|
|
|
while (pkt = capture_file.next) do
|
|
|
|
pcap.inject(pkt)
|
2011-05-12 20:08:33 +00:00
|
|
|
Kernel.select(nil, nil, nil, (delay * 1.0)/1000)
|
2011-04-22 18:25:19 +00:00
|
|
|
end
|
|
|
|
GC.start
|
|
|
|
end
|
|
|
|
|
2010-01-27 18:21:33 +00:00
|
|
|
# Capture_sendto is intended to replace the old Rex::Socket::Ip.sendto method. It requires
|
2010-01-27 17:51:16 +00:00
|
|
|
# a payload and a destination address. To send to the broadcast address, set bcast
|
|
|
|
# to true (this will guarantee that packets will be sent even if ARP doesn't work
|
|
|
|
# out).
|
2010-01-27 18:21:33 +00:00
|
|
|
def capture_sendto(payload="", dhost=nil, bcast=false)
|
2010-01-27 17:51:16 +00:00
|
|
|
raise RuntimeError, "Could not access the capture process (remember to open_pcap first!)" unless self.capture
|
|
|
|
raise RuntimeError, "Must specify a host to sendto" unless dhost
|
2010-01-27 15:11:18 +00:00
|
|
|
dst_mac,src_mac = lookup_eth(dhost)
|
2010-01-27 22:46:41 +00:00
|
|
|
if dst_mac == nil and not bcast
|
2010-01-27 15:11:18 +00:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
inject_eth(:payload => payload, :eth_daddr => dst_mac, :eth_saddr => src_mac)
|
|
|
|
end
|
|
|
|
|
2010-01-26 16:00:16 +00:00
|
|
|
# Depending on what kind of packet you get, the resultant hash returned will
|
|
|
|
# contain one or several Racket objects.
|
2010-01-27 17:51:16 +00:00
|
|
|
def inject_reply(proto=:udp,pcap=self.capture)
|
2010-01-26 06:38:41 +00:00
|
|
|
reply = nil
|
|
|
|
to = (datastore['TIMEOUT'] || 500).to_f / 1000.0
|
2010-01-27 17:51:16 +00:00
|
|
|
if not pcap
|
2010-01-26 06:38:41 +00:00
|
|
|
raise RuntimeError, "Could not access the capture process (remember to open_pcap first!)"
|
|
|
|
else
|
|
|
|
begin
|
2010-02-20 18:31:46 +00:00
|
|
|
::Timeout.timeout(to) do
|
2010-01-27 17:51:16 +00:00
|
|
|
pcap.each do |r|
|
2010-01-26 06:38:41 +00:00
|
|
|
eth = Racket::L2::Ethernet.new(r)
|
|
|
|
case proto
|
2010-01-26 16:00:16 +00:00
|
|
|
when :arp
|
|
|
|
next if not eth.ethertype == 0x0806
|
|
|
|
arp = Racket::L3::ARP.new(eth.payload)
|
|
|
|
reply = {:raw => r, :eth => eth, :arp => arp}
|
|
|
|
break
|
|
|
|
when :ip
|
|
|
|
next if not eth.ethertype == 0x0800
|
|
|
|
ip = Racket::L3::IPv4.new(eth.payload)
|
|
|
|
reply = {:raw => r, :eth => eth, :ip => ip}
|
|
|
|
break
|
2010-01-26 06:38:41 +00:00
|
|
|
when :udp
|
2010-01-26 16:00:16 +00:00
|
|
|
ip = Racket::L3::IPv4.new(eth.payload)
|
2010-01-26 06:38:41 +00:00
|
|
|
next if not ip.protocol == 17
|
|
|
|
udp = Racket::L4::UDP.new(ip.payload)
|
|
|
|
reply = {:raw => r, :eth => eth, :ip => ip, :udp => udp, :payload => udp.payload}
|
|
|
|
break
|
|
|
|
when :tcp
|
2010-01-26 16:00:16 +00:00
|
|
|
ip = Racket::L3::IPv4.new(eth.payload)
|
2010-01-26 06:38:41 +00:00
|
|
|
next if not ip.protocol == 6
|
|
|
|
tcp = Racket::L4::TCP.new(ip.payload)
|
|
|
|
reply = {:raw => r, :eth => eth, :ip => ip, :tcp => tcp, :payload => tcp.payload}
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-02-20 18:31:46 +00:00
|
|
|
rescue ::Timeout::Error
|
2010-01-26 06:38:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return reply
|
|
|
|
end
|
|
|
|
|
2010-02-20 18:31:46 +00:00
|
|
|
# This ascertains the correct Ethernet addresses one should use to
|
2010-01-27 17:51:16 +00:00
|
|
|
# ensure injected IP packets actually get where they are going, and
|
|
|
|
# manages the self.arp_cache hash. It always uses self.arp_capture
|
2010-01-27 22:46:41 +00:00
|
|
|
# do inject and capture packets, and will always first fire off a
|
|
|
|
# UDP packet using the regular socket to learn the source host's
|
|
|
|
# and gateway's mac addresses.
|
2010-01-27 15:11:18 +00:00
|
|
|
def lookup_eth(addr=nil,iface=nil)
|
2010-01-27 17:51:16 +00:00
|
|
|
raise RuntimeError, "Could not access the capture process." if not self.arp_capture
|
2010-02-20 18:31:46 +00:00
|
|
|
|
|
|
|
self.arp_cache ||= {}
|
|
|
|
self.dst_cache ||= {}
|
|
|
|
|
|
|
|
return self.dst_cache[addr] if self.dst_cache[addr]
|
|
|
|
|
|
|
|
if ! self.arp_cache[Rex::Socket.source_address(addr)]
|
2010-01-27 22:46:41 +00:00
|
|
|
probe_gateway(addr)
|
2010-02-20 18:31:46 +00:00
|
|
|
end
|
|
|
|
|
2010-01-27 22:46:41 +00:00
|
|
|
src_mac = self.arp_cache[Rex::Socket.source_address(addr)]
|
|
|
|
unless should_arp?(addr)
|
|
|
|
dst_mac = self.arp_cache[:gateway]
|
|
|
|
else
|
|
|
|
dst_mac = self.arp_cache[addr] || arp(addr)
|
|
|
|
end
|
2010-02-20 18:31:46 +00:00
|
|
|
|
|
|
|
self.dst_cache[addr] = [dst_mac,src_mac]
|
2010-01-27 22:46:41 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def probe_gateway(addr)
|
|
|
|
dst_host = (datastore['GATEWAY'] || IPAddr.new((rand(16777216) + 2969567232), Socket::AF_INET).to_s)
|
|
|
|
dst_port = rand(30000)+1024
|
2010-03-16 16:04:02 +00:00
|
|
|
preamble = [datastore['UDP_SECRET']].pack("N")
|
2010-01-27 22:46:41 +00:00
|
|
|
secret = "#{preamble}#{Rex::Text.rand_text(rand(0xff)+1)}"
|
|
|
|
UDPSocket.open.send(secret,0,dst_host,dst_port)
|
|
|
|
begin
|
|
|
|
to = (datastore['TIMEOUT'] || 1500).to_f / 1000.0
|
2010-02-20 18:31:46 +00:00
|
|
|
::Timeout.timeout(to) do
|
2010-01-27 22:46:41 +00:00
|
|
|
while(my_packet = inject_reply(:udp,self.arp_capture))
|
2010-03-16 16:04:02 +00:00
|
|
|
if my_packet[:payload] == secret
|
2010-01-27 22:46:41 +00:00
|
|
|
dst_mac = self.arp_cache[:gateway] = my_packet[:eth].dst_mac
|
|
|
|
src_mac = self.arp_cache[Rex::Socket.source_address(addr)] = my_packet[:eth].src_mac
|
|
|
|
return [dst_mac,src_mac]
|
|
|
|
else
|
|
|
|
next
|
2010-01-26 06:38:41 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-02-20 18:31:46 +00:00
|
|
|
rescue ::Timeout::Error
|
2010-02-02 22:05:24 +00:00
|
|
|
# Well, that didn't work (this common on networks where there's no gatway, like
|
|
|
|
# VMWare network interfaces. We'll need to use a fake source hardware address.
|
|
|
|
self.arp_cache[Rex::Socket.source_address(addr)] = "00:00:00:00:00:00"
|
2010-01-26 06:38:41 +00:00
|
|
|
end
|
|
|
|
end
|
2010-01-26 16:00:16 +00:00
|
|
|
|
2010-01-27 22:46:41 +00:00
|
|
|
# A pure-Ruby ARP exchange. It uses self.arp_capture to send and recv
|
|
|
|
# packets, rather than self.capture.
|
2010-01-26 16:00:16 +00:00
|
|
|
def arp(target_ip=nil)
|
2010-01-27 02:57:20 +00:00
|
|
|
return self.arp_cache[target_ip] if self.arp_cache[target_ip]
|
2010-01-27 21:19:23 +00:00
|
|
|
return self.arp_cache[:gateway] unless should_arp? target_ip
|
2010-03-16 16:04:02 +00:00
|
|
|
source_ip = Rex::Socket.source_address(target_ip)
|
2010-01-27 17:51:16 +00:00
|
|
|
raise RuntimeError, "Could not access the capture process." if not self.arp_capture
|
2010-03-16 16:04:02 +00:00
|
|
|
n = arp_packet(target_ip,source_ip)
|
2010-01-26 16:00:16 +00:00
|
|
|
inject_eth(:eth_type => 0x0806,
|
2010-01-27 22:46:41 +00:00
|
|
|
:payload => n.pack,
|
|
|
|
:pcap => self.arp_capture,
|
|
|
|
:eth_saddr => self.arp_cache[Rex::Socket.source_address(target_ip)]
|
|
|
|
)
|
2010-01-26 16:00:16 +00:00
|
|
|
begin
|
2010-01-27 22:46:41 +00:00
|
|
|
to = (datastore['TIMEOUT'] || 500).to_f / 1000.0
|
2010-02-20 18:31:46 +00:00
|
|
|
::Timeout.timeout(to) do
|
2010-01-27 17:51:16 +00:00
|
|
|
while (my_packet = inject_reply(:arp,self.arp_capture))
|
2010-01-26 16:00:16 +00:00
|
|
|
if my_packet[:arp].spa == target_ip
|
2010-01-27 02:57:20 +00:00
|
|
|
self.arp_cache[target_ip] = my_packet[:arp].sha
|
2010-02-20 18:31:46 +00:00
|
|
|
return self.arp_cache[target_ip]
|
2010-01-26 16:00:16 +00:00
|
|
|
else
|
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2010-02-20 18:31:46 +00:00
|
|
|
rescue ::Timeout::Error
|
2010-01-26 16:00:16 +00:00
|
|
|
end
|
|
|
|
end
|
2010-01-26 21:37:40 +00:00
|
|
|
|
2010-03-16 16:04:02 +00:00
|
|
|
def arp_packet(target_ip,source_ip)
|
2010-01-27 22:46:41 +00:00
|
|
|
n = Racket::Racket.new
|
|
|
|
n.l3 = Racket::L3::ARP.new
|
|
|
|
n.l3.opcode = 1
|
|
|
|
n.l3.tpa = target_ip || datastore['RHOST']
|
2010-03-16 16:04:02 +00:00
|
|
|
n.l3.spa = datastore['LHOST'] || source_ip
|
2010-02-02 22:05:24 +00:00
|
|
|
my_eth = self.arp_cache[Rex::Socket.source_address(target_ip)]
|
|
|
|
n.l3.sha = my_eth || "00:00:00:00:00:00"
|
2010-01-27 22:46:41 +00:00
|
|
|
return n
|
|
|
|
end
|
|
|
|
|
2010-01-26 21:37:40 +00:00
|
|
|
# Allow modules to reset their arp caches arbitrarily.
|
|
|
|
def expire_arpcache
|
2010-01-27 02:57:20 +00:00
|
|
|
self.arp_cache = {}
|
2010-01-26 21:37:40 +00:00
|
|
|
end
|
2010-01-27 19:37:22 +00:00
|
|
|
|
|
|
|
# For compatabilty with Msf::Exploit::Remote::Ip
|
|
|
|
def rhost
|
|
|
|
datastore['RHOST']
|
|
|
|
end
|
2010-01-27 21:19:23 +00:00
|
|
|
|
2010-02-01 15:11:35 +00:00
|
|
|
def check_pcaprub_loaded
|
2011-05-12 20:08:33 +00:00
|
|
|
if not @pcaprub_loaded
|
2010-02-01 15:11:35 +00:00
|
|
|
print_status("The Pcaprub module is not available: #{@pcaprub_error}")
|
|
|
|
raise RuntimeError, "Pcaprub not available"
|
2011-05-12 20:08:33 +00:00
|
|
|
#Those methods have been added later
|
|
|
|
elsif (not Pcap.respond_to? "lookupaddrs")
|
|
|
|
print_status("The Pcaprub module is not up-to-date")
|
|
|
|
raise RuntimeError, "The Pcaprub module is missing some functions"
|
2010-02-01 15:11:35 +00:00
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def lookupnet
|
|
|
|
check_pcaprub_loaded
|
|
|
|
dev = datastore['INTERFACE'] || ::Pcap.lookupdev
|
|
|
|
mask = datastore['NETMASK'] || 24
|
|
|
|
begin
|
|
|
|
my_net = IPAddr.new("#{Pcap.lookupnet(dev).first}/#{mask}")
|
|
|
|
rescue RuntimeError => e
|
|
|
|
@pcaprub_error = e
|
|
|
|
print_status("Cannot stat device: #{@pcaprub_error}")
|
2010-02-01 16:48:04 +00:00
|
|
|
raise RuntimeError, "Pcaprub error: #{@pcaprub_error}"
|
2010-02-01 15:11:35 +00:00
|
|
|
end
|
|
|
|
return my_net
|
|
|
|
end
|
|
|
|
|
2010-01-27 21:19:23 +00:00
|
|
|
def should_arp?(ip)
|
2010-02-20 18:52:13 +00:00
|
|
|
@mydev ||= datastore['INTERFACE'] || ::Pcap.lookupdev
|
|
|
|
@mymask ||= datastore['NETMASK'] || 24
|
|
|
|
@mynet ||= lookupnet
|
|
|
|
@mynet.include?(IPAddr.new(ip))
|
2010-01-27 21:19:23 +00:00
|
|
|
end
|
2010-02-20 18:31:46 +00:00
|
|
|
|
|
|
|
attr_accessor :capture, :arp_cache, :arp_capture, :dst_cache
|
2007-02-15 21:14:36 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
|
2009-07-16 22:08:31 +00:00
|
|
|
end
|
2009-11-02 14:36:53 +00:00
|
|
|
|