2014-09-16 21:41:14 +00:00
|
|
|
##
|
|
|
|
# WARNING: Metasploit no longer maintains or accepts meterpreter scripts.
|
|
|
|
# If you'd like to imporve this script, please try to port it as a post
|
|
|
|
# module instead. Thank you.
|
|
|
|
##
|
|
|
|
|
|
|
|
|
2010-07-08 14:24:24 +00:00
|
|
|
# Author: Carlos Perez at carlos_perez[at]darkoperator.com
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
################## Variable Declarations ##################
|
|
|
|
@client = client
|
|
|
|
@@exec_opts = Rex::Parser::Arguments.new(
|
2013-09-30 18:47:53 +00:00
|
|
|
"-h" => [ false, "Help menu." ],
|
|
|
|
"-i" => [ false, "Enumerate Local Interfaces"],
|
|
|
|
"-r" => [ true, "The target address range or CIDR identifier"],
|
|
|
|
"-s" => [ false, "Save found IP Addresses to logs."]
|
2010-07-08 14:24:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def enum_int
|
2013-09-30 18:47:53 +00:00
|
|
|
print_status("Enumerating Interfaces")
|
|
|
|
client.net.config.interfaces.each do |i|
|
|
|
|
if not i.mac_name =~ /Loopback/
|
|
|
|
print_status("\t#{i.mac_name}")
|
|
|
|
print_status("\t#{i.ip}")
|
|
|
|
print_status("\t#{i.netmask}")
|
|
|
|
print_status()
|
|
|
|
end
|
2013-09-17 15:42:58 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
end
|
2010-07-08 14:24:24 +00:00
|
|
|
end
|
2011-10-23 11:56:13 +00:00
|
|
|
|
2010-07-08 14:24:24 +00:00
|
|
|
def arp_scan(cidr)
|
2013-09-30 18:47:53 +00:00
|
|
|
print_status("ARP Scanning #{cidr}")
|
|
|
|
ws = client.railgun.ws2_32
|
|
|
|
iphlp = client.railgun.iphlpapi
|
|
|
|
i, a = 0, []
|
|
|
|
iplst,found = [],""
|
|
|
|
ipadd = Rex::Socket::RangeWalker.new(cidr)
|
|
|
|
numip = ipadd.num_ips
|
|
|
|
while (iplst.length < numip)
|
|
|
|
ipa = ipadd.next_ip
|
|
|
|
if (not ipa)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
iplst << ipa
|
|
|
|
end
|
|
|
|
iplst.each do |ip_text|
|
|
|
|
if i < 10
|
|
|
|
a.push(::Thread.new {
|
|
|
|
h = ws.inet_addr(ip_text)
|
|
|
|
ip = h["return"]
|
|
|
|
h = iphlp.SendARP(ip,0,6,6)
|
|
|
|
if h["return"] == client.railgun.const("NO_ERROR")
|
|
|
|
mac_text = h["pMacAddr"].unpack('C*').map { |e| "%02x" % e }.join(':')
|
|
|
|
print_status("IP: #{ip_text} MAC #{mac_text}")
|
|
|
|
found << "#{ip_text}\n"
|
|
|
|
end
|
|
|
|
})
|
|
|
|
i += 1
|
|
|
|
else
|
|
|
|
sleep(0.05) and a.delete_if {|x| not x.alive?} while not a.empty?
|
|
|
|
i = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
a.delete_if {|x| not x.alive?} while not a.empty?
|
|
|
|
return found
|
2010-07-08 14:24:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def save_found(found_ip)
|
2013-09-30 18:47:53 +00:00
|
|
|
info = @client.sys.config.sysinfo
|
|
|
|
# Create Filename info to be appended to downloaded files
|
|
|
|
filenameinfo = "_" + ::Time.now.strftime("%Y%m%d.%M%S")
|
2010-07-08 14:24:24 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
# Create a directory for the logs
|
|
|
|
logs = ::File.join(Msf::Config.log_directory,'scripts', 'arp_scanner',Rex::FileUtils.clean_path(info['Computer'] + filenameinfo))
|
|
|
|
# Create the log directory
|
|
|
|
::FileUtils.mkdir_p(logs)
|
2010-07-08 14:24:24 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
#log file name
|
|
|
|
dest = Rex::FileUtils.clean_path(logs + "/" + info['Computer'] + filenameinfo + ".txt")
|
2010-07-08 14:24:24 +00:00
|
|
|
|
2013-09-30 18:47:53 +00:00
|
|
|
print_status("Saving found IP's to #{dest}")
|
|
|
|
file_local_write(dest,found_ip)
|
2010-07-08 14:24:24 +00:00
|
|
|
|
|
|
|
end
|
|
|
|
save2log = false
|
|
|
|
cidr2scan = ""
|
|
|
|
@@exec_opts.parse(args) { |opt, idx, val|
|
2013-09-30 18:47:53 +00:00
|
|
|
case opt
|
|
|
|
when "-h"
|
|
|
|
print_line "Meterpreter Script for performing an ARPS Scan Discovery."
|
|
|
|
print_line(@@exec_opts.usage)
|
|
|
|
raise Rex::Script::Completed
|
|
|
|
when "-i"
|
|
|
|
enum_int
|
|
|
|
raise Rex::Script::Completed
|
|
|
|
when "-r"
|
|
|
|
cidr2scan = val
|
|
|
|
when "-s"
|
|
|
|
save2log = true
|
|
|
|
end
|
2010-07-08 14:24:24 +00:00
|
|
|
}
|
2017-04-26 04:31:39 +00:00
|
|
|
if client.platform == 'windows'
|
2013-09-30 18:47:53 +00:00
|
|
|
if args.length > 0
|
|
|
|
if save2log
|
|
|
|
save_found(arp_scan(cidr2scan))
|
|
|
|
else
|
|
|
|
arp_scan(cidr2scan)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
print_line "Meterpreter Script for performing an ARPS Scan Discovery."
|
|
|
|
print_line(@@exec_opts.usage)
|
|
|
|
raise Rex::Script::Completed
|
|
|
|
end
|
2010-07-08 14:24:24 +00:00
|
|
|
else
|
2013-09-30 18:47:53 +00:00
|
|
|
print_error("This version of Meterpreter is not supported with this Script!")
|
|
|
|
raise Rex::Script::Completed
|
2011-10-23 11:56:13 +00:00
|
|
|
end
|