2011-10-12 23:20:34 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# ## This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2011-10-12 23:20:34 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
require 'msf/core/post/common'
|
|
|
|
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
|
|
|
include Msf::Post::Common
|
|
|
|
|
|
|
|
|
|
|
|
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>'],
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Platform' => [ 'windows','linux', 'osx', 'bsd', 'solaris' ],
|
|
|
|
'SessionTypes' => [ 'meterpreter','shell' ]
|
|
|
|
))
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
|
|
|
|
OptAddressRange.new('RHOSTS', [true, 'IP Range to perform ping sweep against.']),
|
|
|
|
|
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
|
|
|
# Run Method for when run command is issued
|
|
|
|
def run
|
|
|
|
iprange = datastore['RHOSTS']
|
|
|
|
found_hosts = []
|
|
|
|
print_status("Performing ping sweep for IP range #{iprange}")
|
|
|
|
iplst = []
|
|
|
|
begin
|
|
|
|
i, a = 0, []
|
|
|
|
ipadd = Rex::Socket::RangeWalker.new(iprange)
|
|
|
|
numip = ipadd.num_ips
|
|
|
|
while (iplst.length < numip)
|
|
|
|
ipa = ipadd.next_ip
|
2011-10-23 11:56:13 +00:00
|
|
|
if (not ipa)
|
|
|
|
break
|
|
|
|
end
|
2011-10-12 23:20:34 +00:00
|
|
|
iplst << ipa
|
|
|
|
end
|
|
|
|
if session.type =~ /shell/
|
|
|
|
# Only one thread possible when shell
|
|
|
|
thread_num = 1
|
|
|
|
else
|
|
|
|
# When in Meterpreter the safest thread number is 10
|
|
|
|
thread_num = 10
|
|
|
|
end
|
|
|
|
|
2011-10-19 22:08:56 +00:00
|
|
|
ip_found = []
|
2011-11-20 01:53:25 +00:00
|
|
|
|
2011-10-12 23:20:34 +00:00
|
|
|
iplst.each do |ip|
|
|
|
|
# Set count option for ping command
|
|
|
|
case session.platform
|
|
|
|
when /win/i
|
|
|
|
count = " -n 1 " + ip
|
|
|
|
cmd = "ping"
|
|
|
|
when /solaris/i
|
|
|
|
count = " #{ip} 1"
|
|
|
|
cmd = "/bin/ping"
|
|
|
|
else
|
|
|
|
count = " -c 1 #{ip}"
|
|
|
|
cmd = "/bin/ping"
|
|
|
|
end
|
2011-10-19 22:08:56 +00:00
|
|
|
|
2011-10-15 01:37:50 +00:00
|
|
|
if i <= thread_num
|
2011-10-12 23:20:34 +00:00
|
|
|
a.push(::Thread.new {
|
|
|
|
r = cmd_exec(cmd, count)
|
|
|
|
if r =~ /(TTL|Alive)/i
|
2011-10-19 22:08:56 +00:00
|
|
|
print_status "\t#{ip.inspect} host found"
|
|
|
|
ip_found << ip
|
2011-10-12 23:20:34 +00:00
|
|
|
else
|
|
|
|
vprint_status("\t#{ip} host not found")
|
|
|
|
end
|
|
|
|
|
|
|
|
})
|
|
|
|
i += 1
|
|
|
|
else
|
2011-10-15 01:37:50 +00:00
|
|
|
sleep(0.5) and a.delete_if {|x| not x.alive?} while not a.empty?
|
2011-10-12 23:20:34 +00:00
|
|
|
i = 0
|
|
|
|
end
|
|
|
|
end
|
|
|
|
a.delete_if {|x| not x.alive?} while not a.empty?
|
2011-11-20 01:53:25 +00:00
|
|
|
|
2011-10-12 23:20:34 +00:00
|
|
|
rescue ::Exception => e
|
|
|
|
print_status("The following Error was encountered: #{e.class} #{e}")
|
2011-11-20 01:53:25 +00:00
|
|
|
|
2011-10-12 23:20:34 +00:00
|
|
|
end
|
2011-10-19 22:08:56 +00:00
|
|
|
ip_found.each do |i|
|
|
|
|
report_host(:host => i)
|
|
|
|
end
|
2011-10-12 23:20:34 +00:00
|
|
|
end
|
2011-11-20 01:53:25 +00:00
|
|
|
end
|