This project is read-only.

Reverse SSH Tunnel

Jun 10, 2011 at 4:27 PM

Can SSH.NET be used to set up a 'Reverse SSH Tunnel'? 

Jun 10, 2011 at 4:36 PM

What do you mean by reverse tunnel?

How would you execute similar command in unix?

 

At the moment it supports local and remote port forwarding, is this what you mean?

 

Thanks,

Oleg

Jun 10, 2011 at 5:09 PM

We're using this command to establish a "reverse tunnel" using putty.

putty -R 5900:localhost:5900 [servername]

I believe the remote port forwarding will do the trick but I haven't got it working yet.

Jun 10, 2011 at 5:30 PM

Yes,

 

You talking about remote port forwarding feature.

 

Yes, it supportetd but might be still buggy so any feedback is welcome.

Here some example how you would use this feature:

            using (var client = new SshClient(connectionInfo))
            {
                client.Connect();
                var port1 = client.AddForwardedPort<ForwardedPortRemote>(8081, "www.renci.org", 80);
                
                port1.Exception += delegate(object sender, ExceptionEventArgs e)
                {
                    Console.WriteLine(e.Exception.ToString());
                };
                
                port1.RequestReceived += delegate(object sender, PortForwardEventArgs e)
                {
                    Console.WriteLine(e.OriginatorHost + ":" + e.OriginatorPort);
                };
                
                port1.Start();


                Thread.Sleep(1000 * 60 * 10);
            }

Let me know if you have any questions or problems,

Thanks,

Oleg

Jun 11, 2011 at 2:24 AM
Edited Jun 11, 2011 at 3:18 AM

 

Thanks for your help. Unfortunately I haven't been successful with the remote port forwarding.  Here's my code, it's in VB but should work the same as your example.

-----------------------------------

        Using client = New SshClient("ssh.myserver.com", "login", "pwd")
            client.Connect()

            Dim port As New Renci.SshNet.ForwardedPortRemote
            port = client.AddForwardedPort(Of ForwardedPortRemote)(5900, "ssh.myserver.com", 5900)
            port.Start()

            System.Threading.Thread.Sleep(1000 * 60 * 10)

        End Using

-----------------------------------

The initial connection is working (we can see it in the ssh server console) but I don't think the port forwarding is working.

What we're really trying to do is use TightVNC server to establish remote control of client computers.  We're currently using PuTTY to create a "Reverse SSH Tunnel" (aka remote port forwarding) on the client pc.  This works but we can't integrate PuTTY into our code.  If you're familiar with PuTTY, you can see the port forwarding settings that work.

( I couldn't embed the screenshot of the PuTTY configuration screen so I copied all the settings below.)  Maybe something in these settings will make more sense to you than they do to me :)

PuTTY Configuration
Category: Connection > SSH > Tunnels

Options controlling SSH port forwarding
[X] Local ports accept connections from other hosts
[X] Remort ports do the same (SSH-2 only)

Forwarded Ports:
Source port: 5900
Destination: localhost:5900
( )Local (o)Remote ( )Dynamic
(o)Auto  ( )IPv4   ( )IPv6

Thanks,

Dave

Jun 13, 2011 at 2:48 PM


Hi,

 

I tested that feature here and found one problem that I fixed so I hope it should resolve your issue.

I introduced a bug, which was validating only IPv4 addresses but not IPv6 so I think that might be a problem in your case.

Please download latest code and see if it works for you.

 

Thanks,

Oleg

Jun 13, 2011 at 5:27 PM

I currently don't have a copy of Visual Studio 2010 so I can't build the dll.  I tried with the Express version but it won't let me build a dll.

Could you possibly build it?

Thanks,

Dave

Jun 13, 2011 at 5:46 PM

Yea,

no problem.

Use this link : http://download.codeplex.com/Project/Download/FileDownload.aspx?ProjectName=sshnet&DownloadId=249529

 

Thanks,

Oleg

Jun 14, 2011 at 4:51 PM

It's still not working in our scenario.  I'm getting this exception on port.Start()

System.Net.Sockets.SocketException (0x80004005): An established connection was aborted by the software in your host machine

This looks like the host is the problem (we're running WinSSH) but it does work using PuTTY.  Any ideas?

Jun 16, 2011 at 3:53 PM

Dave,

 

Sorry for delay in response,

I  just busy with other project that I am trying to wrap it up and then will look into this issue.

One thing to check is can you use the library to connect to the server and lets say execute any command?

The reason I ask that that in the past there were a problems with connecting to specific servers and it was due to the fact that server sent or handled SSH messages a little bit different then other.

So one thing you could see if you can capture the log information using putty, since it works, and send it to me. What I would be interesting to look at is what message requests and replies are sent by the putty.

 

Thanks,

Oleg

Jun 16, 2011 at 4:03 PM

Will do, thanks.