Header Ads Widget

Ticker

6/recent/ticker-posts

Fragmento de NodeJS: crea socks5 con ssh

Fragmento de NodeJS: crea socks5 con ssh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
dieciséis
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var socks = require('socksv5');
var Client = require('ssh2').Client;
 
var ssh_config = {
  host: '103.92.11.200',
  port: 22,
  username: 'root',
  password: 'xxxxxx'
};
 
socks.createServer(function(info, accept, deny) {
 
  var conn = new Client();
  conn.on('ready', function() {
    conn.forwardOut(info.srcAddr,
      info.srcPort,
      info.dstAddr,
      info.dstPort,
      function(err, stream) {
        if (err) {
          conn.end();
          return deny();
        }
 
        var clientSocket;
        if (clientSocket = accept(true)) {
          stream.pipe(clientSocket).pipe(stream).on('close', function() {
            conn.end();
          });
        } else
          conn.end();
      });
  }).on('error', function(err) {
    deny();
  }).connect(ssh_config);
}).listen(1080, '0.0.0.0', function() {
  console.log('SOCKSv5 proxy server started on port 1080');
}).useAuth(socks.auth.UserPassword(function(user, password, cb) {
  cb(user === 'user' && password === 'pass');
}));

Ejemplo de prueba:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
dieciséis
17
18
19
D:\cygwin64\bin>curl -i --socks5 127.0.0.1:1080 --proxy-user user:pass google.co
m --socks5-hostname localhost
HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=UTF-8
Date: Thu, 30 Jul 2020 16:51:21 GMT
Expires: Sat, 29 Aug 2020 16:51:21 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 0
X-Frame-Options: SAMEORIGIN
 
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

Publicar un comentario

0 Comentarios