[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

HOW to use ssh_channel_open_reverse_forward function to implement a reverse tunnel?


Hi,
I'm trying to implement a simple ssh reverse tunnel with libssh. The condition is I have a home computer(local), and a development server(server), the server is behind a firewall(NAT) and I want program with libssh to do intranet penetration.



I run a client on server, connect to sshd on local, then ssh_channel_listen_forward && ssh_channel_accept_forward as tutorial said.
But accept function always failed with error ''waiting for incoming connection: No channel request of this type from server''.


So turn to the local sshd side, I have registered global_request function(Here I also have a question: what's the difference between message callback and global_request callback? I thought I can handle this kind global_request in message callback, so if I both have message callback and global_request callback, does the global_request come through message callback and global_request callback both?)In it I have handled reply_success, open socket on local, listen to it, allocate a new channel, and call ssh_channel_open_reverse_forward.


I guessed I need another sshd on server, to communicate with this channel. But now I don't have code it because I'm not sure whether ssh_channel_accept_forward can handle this situation? Please clarify the architecture here, Thanks!


I also stuck at ssh_channel_open_reverse_forward function, it never return. I believe the problem is parameter, remotehost/remoteport/sourcehost/sourceport. I have read the comment, see if I want the local sshd listen at 2222, should I set remotehost as "localhost", remoeport as "2222"? Then what is the sourcehost/souceport represent? the server client connected to my local sshd? Since the server here is in NAT, how could I get it's IP?


Please kindly give me some hint on here, especially how the local sshd reverse connect to the server sshd. I tried use openssh -R, I saw without a server side sshd, the tunnel can't be established. So I thought there must be some mechanism, which I need to use ssh_channel_open_reverse_forward && ssh_channel_accept_forward && some magic function :-). Show me the mystery here, THANK U!


Appreciate your patient,
HAVE A NICE DAY!
Yuanzhe

Archive administrator: postmaster@lists.cynapses.org