-
-
Notifications
You must be signed in to change notification settings - Fork 63
Expand file tree
/
Copy pathcreateServerConnectionFilter.js
More file actions
43 lines (35 loc) · 1.27 KB
/
createServerConnectionFilter.js
File metadata and controls
43 lines (35 loc) · 1.27 KB
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
import dns from 'dns';
import socks5 from '../src/socks5.js';
const port = 1080,
server = socks5.createServer({
connectionFilter(destination, origin, callback) {
console.log('Attempting to connect to...');
console.log(destination);
console.log();
console.log('Inbound origin of request is...');
console.log(origin);
return dns.reverse(destination.address, function(err, hostnames) {
if (err) {
console.error('DNS reverse lookup failed for %s', destination.address);
console.error(err);
// if the reverse lookup fails, we just deny the connection
return callback(new Error('connection to destination address is denied (only github is allowed)'));
}
if (!hostnames || !hostnames.length || !/github/.test(hostnames[0])) {
console.log('Not allowing connection to %s:%s', destination.address, destination.port);
return callback(new Error('connection to destination address is denied (only github is allowed)'));
}
return callback();
});
},
});
server.on('connectionFilter', function(destination, origin, err) {
console.log(
'connection to %s:%s has been denied (only requests to github are allowed)',
destination.address,
destination.port,
);
console.error(err);
});
// start listening!
server.listen(port);