Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/scanner/discovery/arp_sweep.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::Capture7include Msf::Auxiliary::Report8include Msf::Auxiliary::Scanner910OUI_LIST = Rex::Oui1112def initialize13super(14'Name' => 'ARP Sweep Local Network Discovery',15'Description' => %q{16Enumerate alive Hosts in local network using ARP requests.17},18'Author' => 'belch',19'License' => MSF_LICENSE20)2122register_options([23OptString.new('SHOST', [false, "Source IP Address"]),24OptString.new('SMAC', [false, "Source MAC Address"]),25# one re-register TIMEOUT here with a lower value, cause 5 seconds will be enough in most of the case26OptInt.new('TIMEOUT', [true, 'The number of seconds to wait for new data', 5]),27])2829deregister_options('SNAPLEN', 'FILTER', 'PCAPFILE', 'SECRET', 'GATEWAY_PROBE_HOST', 'GATEWAY_PROBE_PORT')30end3132def run_batch_size33datastore['BATCHSIZE'] || 25634end3536def run_batch(hosts)37open_pcap({'SNAPLEN' => 68, 'FILTER' => "arp[6:2] == 0x0002"})3839@netifaces = true40if not netifaces_implemented?41print_error("WARNING : NetworkInterface is not up-to-date, some functionality will not be available")42@netifaces = false43end4445@interface = datastore['INTERFACE'] || Pcap.lookupdev46shost = datastore['SHOST']47shost ||= get_ipv4_addr(@interface) if @netifaces48raise 'SHOST should be defined' unless shost4950smac = datastore['SMAC']51smac ||= get_mac(@interface) if @netifaces52raise 'SMAC should be defined' unless smac5354begin5556hosts.each do |dhost|57if dhost != shost58probe = buildprobe(shost, smac, dhost)59inject(probe)6061while(reply = getreply())62next unless reply.is_arp?63company = OUI_LIST::lookup_oui_company_name(reply.arp_saddr_mac)64print_good("#{reply.arp_saddr_ip} appears to be up (#{company}).")65report_host(:host => reply.arp_saddr_ip, :mac=>reply.arp_saddr_mac)66report_note(:host => reply.arp_saddr_ip, :type => "mac_oui", :data => company)67end6869end70end7172etime = Time.now.to_f + datastore['TIMEOUT']73while (Time.now.to_f < etime)74while(reply = getreply())75next unless reply.is_arp?76company = OUI_LIST::lookup_oui_company_name(reply.arp_saddr_mac)77print_good("#{reply.arp_saddr_ip} appears to be up (#{company}).")78report_host(:host => reply.arp_saddr_ip, :mac=>reply.arp_saddr_mac)79report_note(:host => reply.arp_saddr_ip, :type => "mac_oui", :data => company)80end81Kernel.select(nil, nil, nil, 0.50)82end8384ensure85close_pcap()86end87end8889def buildprobe(shost, smac, dhost)90p = PacketFu::ARPPacket.new91p.eth_saddr = smac92p.eth_daddr = "ff:ff:ff:ff:ff:ff"93p.arp_opcode = 194p.arp_saddr_mac = p.eth_saddr95p.arp_daddr_mac = p.eth_daddr96p.arp_saddr_ip = shost97p.arp_daddr_ip = dhost98p.recalc99p100end101102def getreply103pkt_bytes = capture.next104Kernel.select(nil,nil,nil,0.1)105return unless pkt_bytes106pkt = PacketFu::Packet.parse(pkt_bytes)107return unless pkt.is_arp?108return unless pkt.arp_opcode == 2109pkt110end111end112113114