2011-10-12 23:20:34 +00:00
|
|
|
##
|
2017-07-24 06:26:21 -07:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-15 13:50:46 -05:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2011-10-12 23:20:34 +00:00
|
|
|
##
|
|
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
class MetasploitModule < Msf::Post
|
2011-10-12 23:20:34 +00:00
|
|
|
|
2023-02-08 13:47:34 +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>'],
|
|
|
|
|
'Platform' => %w[bsd linux osx solaris win],
|
|
|
|
|
'SessionTypes' => [ 'meterpreter', 'shell' ]
|
|
|
|
|
)
|
|
|
|
|
)
|
2013-09-05 13:41:25 -05:00
|
|
|
register_options(
|
|
|
|
|
[
|
2011-10-12 23:20:34 +00:00
|
|
|
|
|
|
|
|
OptAddressRange.new('RHOSTS', [true, 'IP Range to perform ping sweep against.']),
|
|
|
|
|
|
2023-02-08 13:47:34 +00:00
|
|
|
]
|
|
|
|
|
)
|
2011-10-12 23:20:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 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
|
2023-02-08 13:47:34 +00:00
|
|
|
if !ipa
|
2011-10-23 11:56:13 +00:00
|
|
|
break
|
|
|
|
|
end
|
2023-02-08 13:47:34 +00:00
|
|
|
|
2011-10-12 23:20:34 +00:00
|
|
|
iplst << ipa
|
|
|
|
|
end
|
2011-10-19 22:08:56 +00:00
|
|
|
|
2016-03-17 23:26:12 -05:00
|
|
|
case session.platform
|
2016-10-29 14:59:05 +10:00
|
|
|
when 'windows'
|
2023-02-08 13:47:34 +00:00
|
|
|
count = ' -n 1 '
|
|
|
|
|
cmd = 'ping'
|
2016-10-29 14:59:05 +10:00
|
|
|
when 'solaris'
|
2023-02-08 13:47:34 +00:00
|
|
|
cmd = '/usr/sbin/ping'
|
2012-07-23 18:34:05 -04:00
|
|
|
else
|
2023-02-08 13:47:34 +00:00
|
|
|
count = ' -n -c 1 -W 2 '
|
|
|
|
|
cmd = 'ping'
|
2011-10-12 23:20:34 +00:00
|
|
|
end
|
2011-11-20 12:53:25 +11:00
|
|
|
|
2012-07-23 18:34:05 -04:00
|
|
|
ip_found = []
|
|
|
|
|
|
2023-02-08 13:47:34 +00:00
|
|
|
while (!iplst.nil? && !iplst.empty?)
|
2012-10-12 17:12:42 -04:00
|
|
|
a = []
|
2016-03-17 23:26:12 -05:00
|
|
|
1.upto session.max_threads do
|
2023-02-08 13:47:34 +00:00
|
|
|
a << framework.threads.spawn("Module(#{refname})", false, iplst.shift) do |ip_add|
|
2012-08-07 15:59:01 -05:00
|
|
|
next if ip_add.nil?
|
2023-02-08 13:47:34 +00:00
|
|
|
|
2016-03-17 23:26:12 -05:00
|
|
|
if session.platform =~ /solaris/i
|
2012-10-12 18:35:05 -05:00
|
|
|
r = cmd_exec(cmd, "-n #{ip_add} 1")
|
2012-08-07 15:59:01 -05:00
|
|
|
else
|
2012-10-12 18:35:05 -05:00
|
|
|
r = cmd_exec(cmd, count + ip_add)
|
2012-08-07 15:59:01 -05:00
|
|
|
end
|
2012-07-23 18:34:05 -04:00
|
|
|
if r =~ /(TTL|Alive)/i
|
2017-07-19 11:46:39 +01:00
|
|
|
print_good "\t#{ip_add} host found"
|
2012-07-23 18:34:05 -04:00
|
|
|
ip_found << ip_add
|
|
|
|
|
else
|
|
|
|
|
vprint_status("\t#{ip_add} host not found")
|
|
|
|
|
end
|
2012-08-07 15:59:01 -05:00
|
|
|
end
|
|
|
|
|
end
|
2023-02-08 13:47:34 +00:00
|
|
|
a.map(&:join)
|
2012-07-23 18:34:05 -04:00
|
|
|
end
|
2012-07-23 18:34:03 -05:00
|
|
|
rescue Rex::TimeoutError, Rex::Post::Meterpreter::RequestError
|
2011-10-12 23:20:34 +00:00
|
|
|
rescue ::Exception => e
|
|
|
|
|
print_status("The following Error was encountered: #{e.class} #{e}")
|
|
|
|
|
end
|
2012-07-23 18:34:05 -04:00
|
|
|
|
|
|
|
|
ip_found.each do |ip|
|
2023-02-08 13:47:34 +00:00
|
|
|
report_host(host: ip)
|
2011-10-19 22:08:56 +00:00
|
|
|
end
|
2011-10-12 23:20:34 +00:00
|
|
|
end
|
2011-11-20 12:53:25 +11:00
|
|
|
end
|