Using proxy

Jan 15, 2013 at 8:29 PM

Hi,

 

first of all thank you very much for this great project. I tested the dynamic port forwarding feature and almost everything works great.

Tunneling through a proxy however causes some problems on my side. For this purpose I use Fiddler 2 which I set up to run on my localhost on port 9999. When I try to connect to my SSH server through the proxy I see request in Fiddler when I call sshclient.Connect() but I don't get any answer and my call times out.

 

Have you used Fiddler before with your lib? As I see the first request there I don't know if the problem is in Fiddler itself or in my or your code.

 

Best regards,

Sebastian

Coordinator
Jan 17, 2013 at 1:38 AM

Hi Sebastian,

 

I dont think I used Fiddlet before but I just checked in some code changes where I made some port forwarding improvments.

 

Can you try to checkout the latest version and see if it works for you?

 

Just as an example, I used following code to stress test my local portforwarding in case you want to recreate it for dynamic port forwarding:

            using (var ssh = new SshClient(connectionInfo))
            {
                ssh.Connect();

                //var port1 = ssh.AddForwardedPort<ForwardedPortLocal>("localhost", 8084, "www.renci.org", 80);
                var port1 = new ForwardedPortLocal("localhost", 8084, "www.renci.org", 80);
                ssh.AddForwardedPort(port1);
                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();

                var globalCounter = 0;

                System.Threading.Tasks.Parallel.For(0, 10000,
                    new ParallelOptions
                    {
                        MaxDegreeOfParallelism = 40,
                    },
                    (counter) =>
                    {
                        Interlocked.Increment(ref globalCounter);
                        var req = HttpWebRequest.Create("http://localhost:8084");
                        using (var response = req.GetResponse())
                        {
                            var r = new StreamReader(response.GetResponseStream());
                            var output = r.ReadToEnd();
                            Console.WriteLine(string.Format("{3}\tRequest: {0}\tTime: {1}\tLength: {2}", counter, DateTime.Now, output.Length, globalCounter));
                        }
                    }
                );


                Thread.Sleep(1000 * 60 * 10);

                port1.Stop();

                ssh.Disconnect();
            }

 

Thanks,

Oleg

Jan 17, 2013 at 6:23 PM
Thank you, I will try it the next days (currently ill) and give you feedback.
Best regards,
Sebastian



olegkap <notifications@codeplex.com> schrieb:

From: olegkap

Hi Sebastian,

I dont think I used Fiddlet before but I just checked in some code changes where I made some port forwarding improvments.

Can you try to checkout the latest version and see if it works for you?

Just as an example, I used following code to stress test my local portforwarding in case you want to recreate it for dynamic port forwarding:

            using (var ssh = new SshClient(connectionInfo))
            {
                ssh.Connect();

                //var port1 = ssh.AddForwardedPort<ForwardedPortLocal>("localhost", 8084, "www.renci.org", 80);
                var port1 = new ForwardedPortLocal("localhost", 8084, "www.renci.org", 80);
                ssh.AddForwardedPort(port1);
                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();

                var globalCounter = 0;

                System.Threading.Tasks.Parallel.For(0, 10000,
                    new ParallelOptions
                    {
                        MaxDegreeOfParallelism = 40,
                    },
                    (counter) =>
                    {
                        Interlocked.Increment(ref globalCounter);
                        var req = HttpWebRequest.Create("http://localhost:8084");
                        using (var response = req.GetResponse())
                        {
                            var r = new StreamReader(response.GetResponseStream());
                            var output = r.ReadToEnd();
                            Console.WriteLine(string.Format("{3}\tRequest: {0}\tTime: {1}\tLength: {2}", counter, DateTime.Now, output.Length, globalCounter));
                        }
                    }
                );


                Thread.Sleep(1000 * 60 * 10);

                port1.Stop();

                ssh.Disconnect();
            }

Thanks,

Oleg

Apr 30, 2013 at 3:27 PM
Hi Sebastian, Oleg,
I see that you say that you had success with dynamic ports and I wondered if you could provide some more details as I am struggling with this.

I have set up an SSH client with dynamic port forwarding on 1080 (see simple code example at the end).

The client connection and port forwarding is successful (port and client IsConnected both true).

Also the sshd server auth.log (Debian Linux) shows that the session was opened OK as follows:
Apr 30 15:09:33 myserver sshd[3297]: Accepted publickey for pi from 83.99.144.145 port 51313 ssh2
Apr 30 15:09:33 myserver sshd[3297]: pam_unix(sshd:session): session opened for user pi by (uid=0)
So far so good. However when I try to use the forwarded port as a SOCKS5 proxy from Firefox the request times out. I have tried the same SSH setup with PuTTY and this works fine.

Any help really appreciated - hopefully it's something simple I'm doing wrong!! Thanks.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Renci.SshNet;

namespace SSHTest
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Console.WriteLine("SSH Test");
            string keyfile = "C:\\PI_01_sshnet.ppk";
            string host = "81.82.183.175";
            string username = "test";
            int port = 22;

            string pword = "";
            System.Console.WriteLine("Enter key file pass code:");
            ConsoleColor oldFore = Console.ForegroundColor;
            Console.ForegroundColor = Console.BackgroundColor;
            pword = System.Console.ReadLine();
            Console.ForegroundColor = oldFore;
            
            var connectionInfo = new PrivateKeyConnectionInfo(host, port, username, new PrivateKeyFile(keyfile, pword));
            
            using (var myclient = new SshClient(connectionInfo))
            {
                myclient.Connect();

                if (myclient.IsConnected)
                    System.Console.WriteLine("Client connected");
                else
                    System.Console.WriteLine("Connection error");

                var dynamicPort = new ForwardedPortDynamic(1080);
                myclient.AddForwardedPort(dynamicPort);
                dynamicPort.Start();

                if (dynamicPort.IsStarted)
                {
                    System.Console.WriteLine("Port forwarding started OK");
                }
                else
                {
                    System.Console.WriteLine("Port forwarding not started");
                }
                System.Console.WriteLine("Press enter to exit");

                System.Console.ReadLine();                

                myclient.Disconnect();
            }
        }
    }
May 3, 2013 at 1:40 AM
I have been having the same problem after I updated to the latest build, last build I was using that worked was from late last year.
May 3, 2013 at 6:55 AM
Edited May 3, 2013 at 1:56 PM
I have tried older builds. With 2013.1.8 and earlier I get a different error in Firefox "The connection was reset" which looks like a different error???