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/post/windows/gather/arp_scanner.rb
Views: 11655
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Auxiliary::Report78OUI_LIST = Rex::Oui910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Windows Gather ARP Scanner',15'Description' => %q{16This Module will perform an ARP scan for a given IP range through a17Meterpreter Session.18},19'License' => MSF_LICENSE,20'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],21'Platform' => [ 'win' ],22'SessionTypes' => [ 'meterpreter'],23'Compat' => {24'Meterpreter' => {25'Commands' => %w[26stdapi_railgun_api27]28}29}30)31)32register_options(33[34OptString.new('RHOSTS', [true, 'The target address range or CIDR identifier', nil]),35OptInt.new('THREADS', [false, 'The number of concurrent threads', 10])3637]38)39end4041# Run Method for when run command is issued42def run43print_status("Running module against #{sysinfo['Computer']}")44arp_scan(datastore['RHOSTS'], datastore['THREADS'])45end4647def arp_scan(cidr, threads)48print_status("ARP Scanning #{cidr}")49ws = client.railgun.ws2_3250iphlp = client.railgun.iphlpapi51a = []52iplst = []53found = ''54ipadd = Rex::Socket::RangeWalker.new(cidr)55numip = ipadd.num_ips56while (iplst.length < numip)57ipa = ipadd.next_ip58if !ipa59break60end6162iplst << ipa63end6465while (!iplst.nil? && !iplst.empty?)66a = []671.upto(threads) do68a << framework.threads.spawn("Module(#{refname})", false, iplst.shift) do |ip_text|69next if ip_text.nil?7071h = ws.inet_addr(ip_text)72ip = h['return']73h = iphlp.SendARP(ip, 0, 6, 6)74if h['return'] == client.railgun.const('NO_ERROR')75mac_text = h['pMacAddr'].unpack('C*').map { |e| '%02x' % e }.join(':')76company = OUI_LIST.lookup_oui_company_name(mac_text)77print_good("\tIP: #{ip_text} MAC #{mac_text} (#{company})")78report_host(host: ip_text, mac: mac_text)79next if company.nil?8081report_note(host: ip_text, type: 'mac_oui', data: company)82end83end84end85a.map(&:join)86end87return found88end89end909192