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
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2010-04-30 08:40:19 +00:00
|
|
|
##
|
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
|
|
|
|
|
2012-07-09 22:39:26 +00:00
|
|
|
OUI_LIST = Rex::Oui
|
|
|
|
|
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([
|
2011-06-02 21:31:36 +00:00
|
|
|
OptString.new('SHOST', [false, "Source IP Address"]),
|
|
|
|
OptString.new('SMAC', [false, "Source MAC Address"]),
|
2011-04-14 16:29:56 +00:00
|
|
|
# one re-register TIMEOUT here with a lower value, cause 5 seconds will be enough in most of the case
|
|
|
|
OptInt.new('TIMEOUT', [true, 'The number of seconds to wait for new data', 5]),
|
2009-07-22 02:48:00 +00:00
|
|
|
], self.class)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2011-06-02 21:31:36 +00:00
|
|
|
deregister_options('SNAPLEN', 'FILTER', 'PCAPFILE', 'UDP_SECRET', 'GATEWAY', 'NETMASK')
|
2009-07-22 02:48:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run_batch_size
|
|
|
|
datastore['BATCHSIZE'] || 256
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_batch(hosts)
|
2011-07-27 20:21:47 +00:00
|
|
|
open_pcap({'SNAPLEN' => 68, 'FILTER' => "arp[6:2] == 0x0002"})
|
2011-07-27 18:53:59 +00:00
|
|
|
|
2011-06-02 21:31:36 +00:00
|
|
|
@netifaces = true
|
2011-10-17 02:42:01 +00:00
|
|
|
if not netifaces_implemented?
|
2011-06-02 21:31:36 +00:00
|
|
|
print_error("WARNING : Pcaprub is not uptodate, some functionality will not be available")
|
|
|
|
@netifaces = false
|
|
|
|
end
|
|
|
|
|
2011-08-25 00:11:20 +00:00
|
|
|
@interface = datastore['INTERFACE'] || Pcap.lookupdev
|
2010-04-30 08:40:19 +00:00
|
|
|
shost = datastore['SHOST']
|
2011-08-25 00:11:20 +00:00
|
|
|
shost ||= get_ipv4_addr(@interface) if @netifaces
|
2011-06-02 21:31:36 +00:00
|
|
|
raise RuntimeError ,'SHOST should be defined' unless shost
|
2011-11-20 02:12:07 +00:00
|
|
|
|
2009-07-22 02:48:00 +00:00
|
|
|
smac = datastore['SMAC']
|
2011-08-25 00:11:20 +00:00
|
|
|
smac ||= get_mac(@interface) if @netifaces
|
2011-06-02 21:31:36 +00:00
|
|
|
raise RuntimeError ,'SMAC should be defined' unless smac
|
2010-04-30 08:40:19 +00:00
|
|
|
|
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|
|
2011-06-02 21:31:36 +00:00
|
|
|
if dhost != shost
|
|
|
|
probe = buildprobe(shost, smac, dhost)
|
2011-07-27 17:44:36 +00:00
|
|
|
inject(probe)
|
2009-07-22 02:48:00 +00:00
|
|
|
|
2011-06-02 21:31:36 +00:00
|
|
|
while(reply = getreply())
|
2011-07-27 17:44:36 +00:00
|
|
|
next unless reply.is_arp?
|
2012-07-09 23:24:30 +00:00
|
|
|
company = OUI_LIST::lookup_oui_company_name(reply.arp_saddr_mac)
|
2012-07-09 22:39:26 +00:00
|
|
|
print_status("#{reply.arp_saddr_ip} appears to be up (#{company}).")
|
2011-07-27 17:44:36 +00:00
|
|
|
report_host(:host => reply.arp_saddr_ip, :mac=>reply.arp_saddr_mac)
|
2012-07-09 22:39:26 +00:00
|
|
|
report_note(:host => reply.arp_saddr_ip, :type => "mac_oui", :data => company)
|
2011-06-02 21:31:36 +00:00
|
|
|
end
|
2011-07-27 17:44:36 +00:00
|
|
|
|
2009-07-22 02:48:00 +00:00
|
|
|
end
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2011-04-14 16:29:56 +00:00
|
|
|
etime = Time.now.to_f + datastore['TIMEOUT']
|
2009-07-22 02:48:00 +00:00
|
|
|
while (Time.now.to_f < etime)
|
|
|
|
while(reply = getreply())
|
2011-07-27 17:44:36 +00:00
|
|
|
next unless reply.is_arp?
|
2012-07-09 23:24:30 +00:00
|
|
|
company = OUI_LIST::lookup_oui_company_name(reply.arp_saddr_mac)
|
2012-07-09 22:39:26 +00:00
|
|
|
print_status("#{reply.arp_saddr_ip} appears to be up (#{company}).")
|
2011-07-27 17:44:36 +00:00
|
|
|
report_host(:host => reply.arp_saddr_ip, :mac=>reply.arp_saddr_mac)
|
2012-07-09 22:39:26 +00:00
|
|
|
report_note(:host => reply.arp_saddr_ip, :type => "mac_oui", :data => company)
|
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)
|
2011-07-27 17:44:36 +00:00
|
|
|
p = PacketFu::ARPPacket.new
|
|
|
|
p.eth_saddr = smac
|
|
|
|
p.eth_daddr = "ff:ff:ff:ff:ff:ff"
|
|
|
|
p.arp_opcode = 1
|
|
|
|
p.arp_saddr_mac = p.eth_saddr
|
|
|
|
p.arp_daddr_mac = p.eth_daddr
|
|
|
|
p.arp_saddr_ip = shost
|
|
|
|
p.arp_daddr_ip = dhost
|
|
|
|
p.recalc
|
|
|
|
p
|
2009-07-22 02:48:00 +00:00
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2009-07-22 02:48:00 +00:00
|
|
|
def getreply
|
2011-07-27 17:44:36 +00:00
|
|
|
pkt_bytes = capture.next
|
|
|
|
Kernel.select(nil,nil,nil,0.1)
|
|
|
|
return unless pkt_bytes
|
|
|
|
pkt = PacketFu::Packet.parse(pkt_bytes)
|
|
|
|
return unless pkt.is_arp?
|
|
|
|
return unless pkt.arp_opcode == 2
|
|
|
|
pkt
|
2009-07-22 02:48:00 +00:00
|
|
|
end
|
2011-07-27 17:44:36 +00:00
|
|
|
|
2009-07-22 02:48:00 +00:00
|
|
|
end
|