SSH.NET icon indicating copy to clipboard operation
SSH.NET copied to clipboard

Can't use as socks tunnel on MAUI application (.net 8)

Open Flyguy opened this issue 9 months ago • 5 comments

When I trying to use var _port= new ForwardedPortDynamic("127.0.0.1", 5000), On that's code:

_client = new SshClient(s);
_client.HostKeyReceived += (sender, e) =>
{
    e.CanTrust = true;
};
_client.Connect();
_client.AddForwardedPort(_port);
_client.ErrorOccurred += _client_ErrorOccurred;
_port.Start();

I have received exception like "Session operation has timed out". But when I have used _client.createCommand it's works fine and returns good output. What's i doing wrong ?

Flyguy avatar Feb 12 '25 21:02 Flyguy

That looks about right to me. There are a couple of examples in the tests:

https://github.com/sshnet/SSH.NET/blob/16d84d0395a277a89a7487ff1b731d016d430dc2/test/Renci.SshNet.IntegrationTests/SshTests.cs#L472

What is the stack trace of the exception?

Rob-Hague avatar Feb 14 '25 07:02 Rob-Hague

That looks about right to me. There are a couple of examples in the tests:

SSH.NET/test/Renci.SshNet.IntegrationTests/SshTests.cs

Line 472 in 16d84d0 public void Ssh_DynamicPortForwarding_IPv4()

What is the stack trace of the exception?

Renci.SshNet.Session.WaitOnHandle(WaitHandle waitHandle, TimeSpan timeout) Renci.SshNet.Session.Renci.SshNet.ISession.WaitOnHandle(WaitHandle waitHandle) Renci.SshNet.Channels.Channel.WaitOnHandle(WaitHandle waitHandle) Renci.SshNet.Channels.ChannelDirectTcpip.Open(String remoteHost, UInt32 port, IForwardedPort forwardedPort, Socket socket) Renci.SshNet.ForwardedPortDynamic.HandleSocks4(Socket socket, IChannelDirectTcpip channel, TimeSpan timeout) Renci.SshNet.ForwardedPortDynamic.HandleSocks(IChannelDirectTcpip channel, Socket clientSocket, TimeSpan timeout) Renci.SshNet.ForwardedPortDynamic.ProcessAccept(Socket clientSocket)

Flyguy avatar Feb 14 '25 11:02 Flyguy

I have tried to use putty with dynamicport setting for that connection. All works fine. Any ideas ? :(

Flyguy avatar Feb 18 '25 19:02 Flyguy

No bright ideas, sorry. It looks like it negotiates the socks request but it is timing out waiting for a response from the server after requesting the port forwarding.

There are a few events on the port class that you could subscribe to and check: _port.RequestReceived, _port.Exception, _port.Closing

Depending on how much control you have over the client and server, you could try socks5 with the client, or see if the server logs have anything useful

Rob-Hague avatar Feb 18 '25 21:02 Rob-Hague

You could also try a pre-release package which has some logging. See https://github.com/sshnet/SSH.NET#using-pre-release-nuget-package and https://github.com/sshnet/SSH.NET/blob/develop/docfx/logging.md

At the Trace level it will be quite verbose but will show all the SSH packets being sent/received

Rob-Hague avatar Feb 19 '25 07:02 Rob-Hague