-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNoxiousClient.js
54 lines (50 loc) · 1.34 KB
/
NoxiousClient.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
"use strict";
var
socks = require('socksv5'),
http = require('http');
class NoxiousClient {
constructor() {
this.socksConfig = {
proxyHost: '127.0.0.1',
proxyPort: 9999,
localDNS: false,
auths: [
socks.auth.None()
]
};
}
transmitObject(destAddress, msg, cb) {
let postData = JSON.stringify(msg);
// localDNS: false is a critical parameter here, this allows lookup of
// hidden (*.onion) addresses. proxy here refers to the tor instance
let postOptions = {
host: destAddress,
port: 1111,
path: '/',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(postData)
},
agent: new socks.HttpAgent(this.socksConfig)
};
let postReq = http.request(postOptions, function(res) {
res.setEncoding('utf8');
let body = '';
res.on('data', function(d) {
body += d;
});
res.on('end', function() {
console.log('[noxclient transmitObject] HTTP Status: ', res.statusCode);
if(cb && typeof(cb) == 'function') {
let response = {};
response.status = res.statusCode;
response.body = JSON.parse(body);
cb(response);
}
});
});
postReq.end(postData,'utf8');
}
}
module.exports = NoxiousClient;