2011-10-12 23:20:34 +00:00
|
|
|
##
|
2014-10-17 16:47:33 +00:00
|
|
|
# This module requires Metasploit: http://metasploit.com/download
|
2013-10-15 18:50:46 +00:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2011-10-12 23:20:34 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
|
2016-03-08 13:02:44 +00:00
|
|
|
class MetasploitModule < Msf::Post
|
2011-10-12 23:20:34 +00:00
|
|
|
|
2013-09-05 18:41:25 +00:00
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
|
|
|
'Name' => 'Multi Gather Ping Sweep',
|
|
|
|
'Description' => %q{ Performs IPv4 ping sweep using the OS included ping command.},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
|
2013-09-24 17:33:31 +00:00
|
|
|
'Platform' => %w{ bsd linux osx solaris win },
|
2013-09-05 18:41:25 +00:00
|
|
|
'SessionTypes' => [ 'meterpreter', 'shell' ]
|
|
|
|
))
|
|
|
|
register_options(
|
|
|
|
[
|
2011-10-12 23:20:34 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
OptAddressRange.new('RHOSTS', [true, 'IP Range to perform ping sweep against.']),
|
2011-10-12 23:20:34 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
], self.class)
|
|
|
|
end
|
2011-10-12 23:20:34 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
# Run Method for when run command is issued
|
|
|
|
def run
|
|
|
|
iprange = datastore['RHOSTS']
|
|
|
|
print_status("Performing ping sweep for IP range #{iprange}")
|
|
|
|
iplst = []
|
|
|
|
begin
|
|
|
|
ipadd = Rex::Socket::RangeWalker.new(iprange)
|
|
|
|
numip = ipadd.num_ips
|
|
|
|
while (iplst.length < numip)
|
|
|
|
ipa = ipadd.next_ip
|
|
|
|
if (not ipa)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
iplst << ipa
|
|
|
|
end
|
2011-10-19 22:08:56 +00:00
|
|
|
|
2016-03-18 04:26:12 +00:00
|
|
|
case session.platform
|
2013-08-30 21:28:54 +00:00
|
|
|
when /win/i
|
|
|
|
count = " -n 1 "
|
|
|
|
cmd = "ping"
|
|
|
|
when /solaris/i
|
|
|
|
cmd = "/usr/sbin/ping"
|
|
|
|
else
|
|
|
|
count = " -n -c 1 -W 2 "
|
|
|
|
cmd = "ping"
|
|
|
|
end
|
2011-11-20 01:53:25 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
ip_found = []
|
2012-07-23 22:34:05 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
while(not iplst.nil? and not iplst.empty?)
|
|
|
|
a = []
|
2016-03-18 04:26:12 +00:00
|
|
|
1.upto session.max_threads do
|
2013-08-30 21:28:54 +00:00
|
|
|
a << framework.threads.spawn("Module(#{self.refname})", false, iplst.shift) do |ip_add|
|
|
|
|
next if ip_add.nil?
|
2016-03-18 04:26:12 +00:00
|
|
|
if session.platform =~ /solaris/i
|
2013-08-30 21:28:54 +00:00
|
|
|
r = cmd_exec(cmd, "-n #{ip_add} 1")
|
|
|
|
else
|
|
|
|
r = cmd_exec(cmd, count + ip_add)
|
|
|
|
end
|
|
|
|
if r =~ /(TTL|Alive)/i
|
|
|
|
print_status "\t#{ip_add} host found"
|
|
|
|
ip_found << ip_add
|
|
|
|
else
|
|
|
|
vprint_status("\t#{ip_add} host not found")
|
|
|
|
end
|
2012-07-23 22:34:05 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
a.map {|x| x.join }
|
|
|
|
end
|
|
|
|
rescue Rex::TimeoutError, Rex::Post::Meterpreter::RequestError
|
|
|
|
rescue ::Exception => e
|
|
|
|
print_status("The following Error was encountered: #{e.class} #{e}")
|
|
|
|
end
|
2012-07-23 22:34:05 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
ip_found.each do |ip|
|
|
|
|
report_host(:host => ip)
|
|
|
|
end
|
|
|
|
end
|
2011-11-20 01:53:25 +00:00
|
|
|
end
|