3

I'm working on a program that creates a reverse SSH tunnel to a middleman server so that computers in a local network, to which a direct connection is not possible, can still be accessed from outside that local network. I have chosen for the libssh library for this and I'm having problems opening a channel to localhost to forward the incoming data to the local application. Opening the SSH session and requesting the forwarding of data to the local computer seems to work fine. However I can't open a channel to the localhost to read and write data from/to the local application. The way I'm currently trying to open a connection to localhost:

ssh_channel localhost_channel = ssh_channel_new(my_ssh_session);
rc = ssh_channel_open_forward(localhost_channel, "127.0.0.1", 5900, 
        "localhost", 5555);
if (rc != SSH_OK) {
    myLog << "Could not open channel to localhost";
    exit(-1);
}

My program does not exit, so SSH_OK is set. The logs however say that the connection was refused. And there is a working VNC server running on port 5900. I can see the connection request coming in. So I'm pretty sure the problem comes from the connection with localhost. I would really appreciate any advice/tips.

I'm using libssh 0.7.2 on Windows 10 and compiling with msvc.

Cœur
  • 37,241
  • 25
  • 195
  • 267
larzz11
  • 1,022
  • 2
  • 11
  • 24

1 Answers1

0

For reverse port forwarding, use ssh_channel_listen_forward and ssh_channel_accept_forward.

The ssh_channel_open_forward is for direct port forwarding.

See Doing reverse port forwarding with libssh.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992