2010-04-30 08:40:19 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/projects/Framework/
|
|
|
|
##
|
2009-07-22 02:48:00 +00:00
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
require 'msf/core'
|
2009-07-22 02:48:00 +00:00
|
|
|
|
|
|
|
class Metasploit3 < Msf::Auxiliary
|
|
|
|
|
|
|
|
include Msf::Exploit::Remote::Capture
|
|
|
|
include Msf::Auxiliary::Report
|
|
|
|
include Msf::Auxiliary::Scanner
|
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-07-22 02:48:00 +00:00
|
|
|
def initialize
|
|
|
|
super(
|
|
|
|
'Name' => 'ARP Sweep Local Network Discovery',
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Description' => %q{
|
|
|
|
Enumerate alive Hosts in local network using ARP requests.
|
|
|
|
},
|
|
|
|
'Author' => 'belch',
|
|
|
|
'License' => MSF_LICENSE
|
|
|
|
)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-07-22 02:48:00 +00:00
|
|
|
register_options([
|
|
|
|
OptString.new('SHOST', [true, "Source IP Address"]),
|
|
|
|
OptString.new('SMAC', [true, "Source MAC Address"]),
|
|
|
|
], self.class)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-10-06 05:37:36 +00:00
|
|
|
deregister_options('SNAPLEN', 'FILTER')
|
2009-07-22 02:48:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run_batch_size
|
|
|
|
datastore['BATCHSIZE'] || 256
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_batch(hosts)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
|
|
|
shost = datastore['SHOST']
|
2009-07-22 02:48:00 +00:00
|
|
|
smac = datastore['SMAC']
|
2010-04-30 08:40:19 +00:00
|
|
|
|
|
|
|
open_pcap({'SNAPLEN' => 68, 'FILTER' => "arp[6:2] == 0x0002"})
|
2009-07-22 02:48:00 +00:00
|
|
|
|
|
|
|
begin
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-07-22 02:48:00 +00:00
|
|
|
hosts.each do |dhost|
|
|
|
|
probe = buildprobe(datastore['SHOST'], datastore['SMAC'], dhost)
|
|
|
|
capture.inject(probe)
|
|
|
|
|
|
|
|
while(reply = getreply())
|
|
|
|
next if not reply[:arp]
|
2009-07-23 11:47:10 +00:00
|
|
|
print_status("#{reply[:arp].spa} appears to be up.")
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-07-23 11:47:10 +00:00
|
|
|
report_host(:host => reply[:arp].spa, :mac=>reply[:arp].sha)
|
2009-07-22 02:48:00 +00:00
|
|
|
end
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-07-22 02:48:00 +00:00
|
|
|
etime = Time.now.to_f + (hosts.length * 0.05)
|
|
|
|
while (Time.now.to_f < etime)
|
|
|
|
while(reply = getreply())
|
|
|
|
next if not reply[:arp]
|
2009-07-23 11:47:10 +00:00
|
|
|
print_status("#{reply[:arp].spa} appears to be up.")
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-07-23 11:47:10 +00:00
|
|
|
report_host(:host => reply[:arp].spa, :mac=>reply[:arp].sha)
|
2009-07-22 02:48:00 +00:00
|
|
|
end
|
|
|
|
Kernel.select(nil, nil, nil, 0.50)
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-07-22 02:48:00 +00:00
|
|
|
ensure
|
|
|
|
close_pcap()
|
|
|
|
end
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-07-22 02:48:00 +00:00
|
|
|
def buildprobe(shost, smac, dhost)
|
|
|
|
n = Racket::Racket.new
|
2009-12-29 23:32:50 +00:00
|
|
|
n.l2 = Racket::L2::Ethernet.new(Racket::Misc.randstring(14))
|
2009-07-22 02:48:00 +00:00
|
|
|
n.l2.src_mac = smac
|
|
|
|
n.l2.dst_mac = 'ff:ff:ff:ff:ff:ff'
|
|
|
|
n.l2.ethertype = 0x0806
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-29 23:32:50 +00:00
|
|
|
n.l3 = Racket::L3::ARP.new
|
|
|
|
n.l3.opcode = Racket::L3::ARP::ARPOP_REQUEST
|
2009-07-22 02:48:00 +00:00
|
|
|
n.l3.sha = n.l2.src_mac
|
|
|
|
n.l3.tha = n.l2.dst_mac
|
|
|
|
n.l3.spa = shost
|
|
|
|
n.l3.tpa = dhost
|
|
|
|
n.pack
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-07-22 02:48:00 +00:00
|
|
|
def getreply
|
|
|
|
pkt = capture.next
|
|
|
|
return if not pkt
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-12-29 23:32:50 +00:00
|
|
|
eth = Racket::L2::Ethernet.new(pkt)
|
2009-07-22 02:48:00 +00:00
|
|
|
return if not eth.ethertype == 0x0806
|
|
|
|
|
2009-12-29 23:32:50 +00:00
|
|
|
arp = Racket::L3::ARP.new(eth.payload)
|
|
|
|
return if not arp.opcode == Racket::L3::ARP::ARPOP_REPLY
|
2009-07-22 02:48:00 +00:00
|
|
|
|
|
|
|
{:raw => pkt, :eth => eth, :arp => arp}
|
|
|
|
end
|
|
|
|
end
|