Files
metasploit-gs/modules/post/multi/gather/ping_sweep.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

90 lines
2.3 KiB
Ruby
Raw Normal View History

##
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
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
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(
[
OptAddressRange.new('RHOSTS', [true, 'IP Range to perform ping sweep against.']),
2023-02-08 13:47: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
break
end
2023-02-08 13:47:34 +00:00
iplst << ipa
end
2011-10-19 22:08:56 +00: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'
else
2023-02-08 13:47:34 +00:00
count = ' -n -c 1 -W 2 '
cmd = 'ping'
end
2011-11-20 12:53:25 +11:00
ip_found = []
2023-02-08 13:47:34 +00:00
while (!iplst.nil? && !iplst.empty?)
a = []
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
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
if r =~ /(TTL|Alive)/i
2017-07-19 11:46:39 +01:00
print_good "\t#{ip_add} host found"
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)
end
rescue Rex::TimeoutError, Rex::Post::Meterpreter::RequestError
rescue ::Exception => e
print_status("The following Error was encountered: #{e.class} #{e}")
end
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
end
2011-11-20 12:53:25 +11:00
end