Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/multi/gather/ping_sweep.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post67def initialize(info = {})8super(9update_info(10info,11'Name' => 'Multi Gather Ping Sweep',12'Description' => %q{ Performs IPv4 ping sweep using the OS included ping command.},13'License' => MSF_LICENSE,14'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],15'Platform' => %w[bsd linux osx solaris win],16'SessionTypes' => [ 'meterpreter', 'shell' ]17)18)19register_options(20[2122OptAddressRange.new('RHOSTS', [true, 'IP Range to perform ping sweep against.']),2324]25)26end2728# Run Method for when run command is issued29def run30iprange = datastore['RHOSTS']31print_status("Performing ping sweep for IP range #{iprange}")32iplst = []33begin34ipadd = Rex::Socket::RangeWalker.new(iprange)35numip = ipadd.num_ips36while (iplst.length < numip)37ipa = ipadd.next_ip38if !ipa39break40end4142iplst << ipa43end4445case session.platform46when 'windows'47count = ' -n 1 '48cmd = 'ping'49when 'solaris'50cmd = '/usr/sbin/ping'51else52count = ' -n -c 1 -W 2 '53cmd = 'ping'54end5556ip_found = []5758while (!iplst.nil? && !iplst.empty?)59a = []601.upto session.max_threads do61a << framework.threads.spawn("Module(#{refname})", false, iplst.shift) do |ip_add|62next if ip_add.nil?6364if session.platform =~ /solaris/i65r = cmd_exec(cmd, "-n #{ip_add} 1")66else67r = cmd_exec(cmd, count + ip_add)68end69if r =~ /(TTL|Alive)/i70print_good "\t#{ip_add} host found"71ip_found << ip_add72else73vprint_status("\t#{ip_add} host not found")74end75end76end77a.map(&:join)78end79rescue Rex::TimeoutError, Rex::Post::Meterpreter::RequestError80rescue ::Exception => e81print_status("The following Error was encountered: #{e.class} #{e}")82end8384ip_found.each do |ip|85report_host(host: ip)86end87end88end899091