sshnet / SSH.NET

SSH.NET is a Secure Shell (SSH) library for .NET, optimized for parallelism.
http://sshnet.github.io/SSH.NET/
MIT License
3.95k stars 930 forks source link

MS WINDOWS UWP APP | Port forwarding with SSH.NET does not work! #630

Open sm-a opened 4 years ago

sm-a commented 4 years ago

Hello, everybody,

when i try to create a port forwarding with the following code it does not work (no error, nothing). So I would be happy if someone had an idea what goes wrong in my code.

Here now my code:

        using (var client = new SshClient(conInfo))
        {

            client.KeepAliveInterval = new TimeSpan(0, 0, 30);
            client.ConnectionInfo.Timeout = new TimeSpan(0, 0, 20);
            client.Connect();
            ForwardedPortRemote port = new ForwardedPortRemote(8888, "127.0.0.1", 443);
            client.AddForwardedPort(port);

            port.Start();

            var dialog = new MessageDialog("Wenn Sie fertig sind mit der Konfiguration schließen Sie bitte diesen Message Dialog!");
            await dialog.ShowAsync();

            port.Stop();
            client.Disconnect();
        }

I'm glad for any help.

Greetings Sven

SSpormann commented 4 years ago

can you set local loop back at the properties debug?

sm-a commented 4 years ago

@SSpormann thank you for your help. How can I set local loop back?

SSpormann commented 4 years ago

image

sm-a commented 4 years ago

@SSpormann thank you for your help. "Allow local network loopback" is already activated. What can I do to get the App to work?

SSpormann commented 4 years ago

Are you useing the nuget package ? try downloading the newest version from github, that way i managed to get it to work

sm-a commented 4 years ago

@SSpormann Yes I use the nuget package. How can I get the newest version. When I look on github releases (https://github.com/sshnet/SSH.NET/releases/tag/2016.1.0) I found only an old version from 2016. How can I get a newer version or is it the newest?

SSpormann commented 4 years ago

https://github.com/sshnet/SSH.NET

displays last update 4 days ago, but nuget wasn't updated for ages, just import the projects to your foulder,

WindowsDevicePortalWrapper.UniversalWindows

and

WindowsDevicePortalWrapper

sm-a commented 4 years ago

@SSpormann When I download from github as zip I don't find dll or another file that I can use as reference in Visual Studio 2019. What I must do? Sorry for my question. I am new in the Windows Plattform in development. I hope you can me help out.

darkoperator commented 4 years ago

You will have to compile it and use the resulting assembly since it is currently in dev for the next release.

Sent from my iPhone

On Mar 4, 2020, at 10:09 AM, sm-a notifications@github.com wrote:

 @SSpormann When I download from github as zip I don't find dll or another file that I can use as reference in Visual Studio 2019. What I must do? Sorry for my question. I am new in the Windows Plattform in development. I hope you can me help out.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

AraHaan commented 4 years ago

Which brings me to my next question; why does openssh on windows allow sendenv on port forwarding but ssh.net does not? I would also like the exact contents somehow of the result from the server as well for debugging purposes as well. Please help.

darkoperator commented 4 years ago

Because one is a port of OpenSSH and the other is an implementation of the SSH protocol as in RFC 4253

AraHaan commented 4 years ago

Then is there a way to implement my own SendEnv then for the initial port forwarding thing in ssh.net then? I do need it because I do explicitly set the environment variable in my code and I do want it sent for the server to use that variable to construct a fixed port forwarded url (that value woulc be what it is fixed to on the first part of the returned url).

darkoperator commented 4 years ago

No clue there on the how, but in the can yes since both projects are open source, it would be just finding what it sends and implement it in C#. Im just a user like you, have not gone down the protocol path on the changes I have done for my own use

Reply to this email directly, view it on GitHub, or unsubscribe.

sm-a commented 4 years ago

@SSpormann When I load Renci.SshNet.VS2019.sln under the folder "src" and run a clean build and then a rebuild I get the message that the rebuild was not successful (only one is successful). What am I doing wrong?

After the rebuild I get a virus warning from Microsoft Defender. Please check if it contains a virus. See attached Screenshot.

Windows Security 08 03 2020 13_53_36

Thank you for your help.

darkoperator commented 4 years ago

More than likely a False Positive, my guess is that encryption functions used are the same as those used by the ransomeware and it is flagging on those falsely flagging the binary. No clue how to ping MS on this to have them take a look.

darinkes commented 4 years ago

Same here #490 Contacted Microsoft because of this but never got any response :/

sm-a commented 4 years ago

The problem still exists. I have now a .net core WPF app and it is the same failure. If I use the following code and then call the forwarded port 8443 it loads endlessly in the browser and nothing happens.

Has nobody any idea to fix this? I use the following version: 2020.0.0-beta1

Here my actual code:

ConnectionInfo conInfo;
var pk = new PrivateKeyFile(smaRSAKey);
var keyFiles = new[] { pk };

var methods = new List<AuthenticationMethod>();
methods.Add(new PrivateKeyAuthenticationMethod(smaUserName, keyFiles));

conInfo = new ConnectionInfo(smaHost, 22, smaUserName, methods.ToArray());

using (var client = new SshClient(conInfo))
{

    client.KeepAliveInterval = new TimeSpan(0, 0, 30);
    client.ConnectionInfo.Timeout = new TimeSpan(0, 0, 20);
    client.Connect();

    var port = new ForwardedPortLocal("localhost", 8443, smaHost, 443);
    client.AddForwardedPort(port);

    port.Start();

    MessageBox.Show("If finish then click OK!");

    port.Stop();
    client.Disconnect();

}