-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwakeupsoc.js
89 lines (73 loc) · 2.27 KB
/
wakeupsoc.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
const request = require('request');
const tr = require('tor-request');
const URI = require('urijs');
const urls = require('./urls');
const rules = require('./rules');
const params = require('./params');
const CONFIG_TOR = true;
const NB_REQUEST = 80000;
const REFRESH_IP = 100;
const TIMEOUT = 2000;
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
function buildMaliciousURI(url) {
const options = {};
const rule = rules[getRandomInt(0, rules.length)];
const param = params[getRandomInt(0, params.length)];
if (rule.http_uri) {
url.addQuery(param, rule.contents[getRandomInt(0, rule.contents.length)]);
}
options.timeout = TIMEOUT;
options.maxRedirects = 1;
options.followRedirect = false;
options.followAllRedirects = false;
options.strictSSL = false;
options.headers = {'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.27 Safari/525.13'};
if (rule.http_header) {
const header = rule.contents[getRandomInt(0, rule.contents.length)];
options.headers = {[header.name]: header.value};
}
options.url = url.normalizeQuery().toString();
return options;
}
function doRequest(options) {
return new Promise(function(resolve, reject) {
tr.request(options, function(error, res, body) {
if (!error && res.statusCode == 200) {
resolve(body);
} else {
reject(error);
}
});
});
}
if (CONFIG_TOR) {
tr.setTorAddress('localhost', 9150);
tr.TorControlPort.port = 9051;
// tor --hash-password TODO | more
tr.TorControlPort.password = 'TODO';
}
async function main() {
for (let j = 0; j < NB_REQUEST; j++) {
const url = new URI(urls[getRandomInt(0, urls.length)]);
const options = buildMaliciousURI(url);
console.log('[' + j + '] request url:', options.url);
if (CONFIG_TOR) {
if ((j % REFRESH_IP) == 0) {
console.log('newTorSession');
tr.newTorSession(function(err) {
if (err) {
console.log('err = ' + err);
}
});
}
const res = await doRequest(options).catch((err) => console.log(err)); ;
} else {
request(options, function(error, response, body) {});
}
}
}
main();