Coder Social home page Coder Social logo

reverse-tunnel-ssh's Introduction

reverse-tunnel-ssh

Easy ssh reverse tunnel

Tunnel-SSH Logo

##How to use

npm i reverse-tunnel-ssh (--save)
// Tunnel your local port 8000 to tunneltest.com:8000

//tunnel is a ssh2 clientConnection object
var tunnel = require('reverse-tunnel-ssh');
tunnel({
  host: 'tunneltest.com',
  username: 'root',
  dstHost: '0.0.0.0', // bind to all IPv4 interfaces
  dstPort: 8000,
  //srcHost: '127.0.0.1', // default
  //srcPort: dstPort // default is the same as dstPort
}, function(error, clientConnection) {
  //
});

// Tunnel your local port 8000 to a free port on tunneltest.com

var conn = tunnel({
  host: 'tunneltest.com',
  username: 'somebody',
  dstHost: '0.0.0.0', // bind to all IPv4 interfaces
  dstPort: 0, // dynamically choose an open port on tunneltest.com
  //srcHost: '127.0.0.1', // default
  srcPort: 8000, // must be specified if dstPort=0
}, function (error, clientConnection) {
  //
});
conn.on('forward-in', function (port) {
  console.log('Forwarding from tunneltest.com:' + port);
});

If you plan to expose a local port on a remote machine (external interface) you need to enable the "GatewayPorts" option in your 'sshd_config'

# What ports, IPs and protocols we listen for
Port 22
GatewayPorts yes

reverse-tunnel-ssh's People

Contributors

agebrock avatar dbushong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

reverse-tunnel-ssh's Issues

Example not working

This the example that I'm running:

var tunnel = require('reverse-tunnel-ssh');
// This is a very handy way to test your next webhook !

// Please set up your /etc/hosts or change the hostname befor
// running the example.

var config = {
  host: '192.168.88.111',
  username: 'root',
  dstHost: '0.0.0.0', // bind to all interfaces (see hint in the readme)
  dstPort: 8818,
  //srcHost: '127.0.0.1', // default
  //srcPort: dstPort // default is the same as dstPort
}
tunnel(config, function(error, clientConnection) {
  if (error) console.log(error);
  console.log(clientConnection._forwarding);
});

require('http').createServer(function(res, res){
  res.end('SSH-TUNNEL: Gate to heaven !');
}).listen(config.dstPort);

console.log('Tunnel created: http://'+config.host+':'+config.dstPort);

This the error:

Error: All configured authentication methods failed
    at tryNextAuth (/home/rocco/Desktop/PROVE/reverse-ssh-tunnel/node_modules/reverse-tunnel-ssh/node_modules/ssh2/lib/client.js:377:17)
    at SSH2Stream.onUSERAUTH_FAILURE (/home/rocco/Desktop/PROVE/reverse-ssh-tunnel/node_modules/reverse-tunnel-ssh/node_modules/ssh2/lib/client.js:575:5)
    at emitTwo (events.js:87:13)
    at SSH2Stream.emit (events.js:172:7)
    at parsePacket (/home/rocco/Desktop/PROVE/reverse-ssh-tunnel/node_modules/reverse-tunnel-ssh/node_modules/ssh2/node_modules/ssh2-streams/lib/ssh.js:3923:10)
    at SSH2Stream._transform (/home/rocco/Desktop/PROVE/reverse-ssh-tunnel/node_modules/reverse-tunnel-ssh/node_modules/ssh2/node_modules/ssh2-streams/lib/ssh.js:667:13)
    at SSH2Stream.Transform._read (_stream_transform.js:167:10)
    at SSH2Stream._read (/home/rocco/Desktop/PROVE/reverse-ssh-tunnel/node_modules/reverse-tunnel-ssh/node_modules/ssh2/node_modules/ssh2-streams/lib/ssh.js:251:15)
    at SSH2Stream.Transform._write (_stream_transform.js:155:12)
    at doWrite (_stream_writable.js:300:12)

What am I doing wrong?

Clarification

You said:

If you plan to expose a local port on a remote machine (external interface) you need to enable the "GatewayPorts" option in your 'sshd_config'

You're talking about sshd_config on the remote machine, not the local one correct?

Keepalive

Keepalive is missing... very important feature

'ready' event is not really ready

Hi,
I found 'ready' event is emit as soon as it connect to reverse server, but forward and something else need to do after that.
So if I connect to this client after it receive 'ready' event too fast, it will receive ECONNREFUSED.
I think maybe you should add a new event or some better way to fix
Thanks a lot!

Empty response

I have a remotehost with GatewayPorts yes configured. I'm able to set up reverse tunneling to http://localhost:8000/ by running ssh remotehost -R 8888:localhost:8000. I'm now looking to reproduce that command in Node without spawning ssh.

With the code below, browsing to http://remotehost:8888/ gives me an empty response.

tunnel({
  host: 'remotehost',
  username: username,
  privateKey: privateKey,
  dstHost: '0.0.0.0',
  dstPort: 8888,
  localPort: 8000
}, function (err, server) {
  if (err) {
    throw err
  }
})

I also tried adding keepAlive: true. It didn't seem to change much.

I also looked at your index.js. I tried setting DEBUG=* but I think you're using the debug module wrong. If I turn it into require('debug')('reverse-tunnel-ssh'), I get some logging: ready happens once as expected and then every connection logs a tcp connection.

Finally, when is my callback supposed to be called? Looking at the code, it waits for the first incoming connection. Instead, I'd like to pass a continuation for when the tunnel has been set up, keep the tunnel open, and continue my script, which doesn't seem to be possible.

Could you perhaps share a typical usage example? Thanks.

Cannot connect

I keep getting "ssh_exchange_identification: Connection closed by remote host" when trying to connect to the device. I get verification the tunnel has been created but I cannot seem to login. Here is the code on the node I want to connect too:

`var tunnel = require('reverse-tunnel-ssh');

// This is a very handy way to test your next webhook !

// Please set up your /etc/hosts or change the hostname befor
// running the example.

var config = {
host: 'xx.xx.xx.x',
username: 'root',
password: 'some_pass',
dstHost: '0.0.0.0', // bind to all interfaces (see hint in the readme)
dstPort: 1987,
//srcHost: '127.0.0.1', // default
//srcPort: dstPort // default is the same as dstPort
}

tunnel(config, function(error, clientConnection) {
console.log(clientConnection._forwarding);
});

require('http').createServer(function(res, res){
res.end('SSH-TUNNEL: Gate to heaven !');
}).listen(config.dstPort);

console.log('Tunnel created: http://'+config.host+':'+config.dstPort);`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.