Exemple #1
0
        public void Should_Successfully_To_And_Login_With_New_Password()
        {
            Assert.Inconclusive("SshClient cannot be used from assemblies with strong names.");

#if false
            bool sucess = false;
            for (int i = 0; i < 10; i++)
            {
                using (var client = new Renci.SshNet.SshClient(_testServer.AccessIPv4, "root", NewPassword))
                {
                    client.Connect();

                    sucess = client.IsConnected;

                    if (sucess)
                    {
                        break;
                    }
                }
                Thread.Sleep(1000);
            }

            Assert.IsTrue(sucess);
#endif
        }
Exemple #2
0
        public CcmBridge(string name, string ipPrefix, bool instantiateSshClient = false)
        {
            Name     = name;
            IpPrefix = ipPrefix;
            CcmDir   = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
            if (instantiateSshClient)
            {
                string sshHost     = "TBD";
                int    sshPort     = -1;
                string sshUser     = "******";
                string sshPassword = "******";
                _sshClient = new Renci.SshNet.SshClient(sshHost, sshPort, sshUser, sshPassword);
                _sshClient.Connect();

                _sshShellStream = _sshClient.CreateShellStream("CCM", 80, 60, 100, 100, 1000);
                var outp = new StringBuilder();
                while (true)
                {
                    outp.Append(_sshShellStream.Read());
                    if (outp.ToString().Trim().EndsWith("$"))
                    {
                        break;
                    }
                }
            }
        }
        public ISshSession Create(RouterCredentials credentials)
        {
            var sshClient = new Renci.SshNet.SshClient(credentials.Host, credentials.User, credentials.Password);

            sshClient.Connect();
            return(new SshSession(sshClient, credentials.User));
        }
        private void RestartController(object mSender, EventArgs e)
        {
            Task.Run(() =>
            {
                string IP       = "";
                string Building = "";
                string Room     = "";
                string Tag      = "";
                Task.Run(() =>
                {
                    Button sender = (Button)mSender;
                    IP            = RoomIPs[sender.Id];
                    Building      = ((MainPage)Application.Current.MainPage)._Controllers.FindByIP(IP).Building;
                    Room          = ((MainPage)Application.Current.MainPage)._Controllers.FindByIP(IP).Room;
                    Tag           = ((MainPage)Application.Current.MainPage)._Controllers.FindByIP(IP).Tag;
                });
                using (Renci.SshNet.SshClient sshClient = new Renci.SshNet.SshClient(IP, "Username", "Password"))
                {
                    sshClient.HostKeyReceived += (_sender, _e) => {
                        _e.CanTrust = true;
                    };
                    sshClient.ConnectionInfo.Timeout = TimeSpan.FromSeconds(30);
                    try
                    {
                        sshClient.Connect();
                    }
                    catch
                    {
                        return;
                    }

                    var amxStream = sshClient.CreateShellStream("amxStream", 0, 0, 0, 0, 256);

                    bool streamLockToken = true;
                    var streamTTL        = DateTime.Now.Add(TimeSpan.FromSeconds(30));
                    while (streamLockToken)
                    {
                        if (amxStream.DataAvailable)
                        {
                            streamLockToken = false;
                        }
                        else if (DateTime.Now >= streamTTL)
                        {
                            sshClient.Disconnect();
                            return;
                        }
                        else
                        {
                            System.Threading.Thread.Sleep(0);
                        }
                    }

                    amxStream.WriteLine("reboot");

                    sshClient.Disconnect();
                }
            });
        }
        public void Should_Successfully_To_And_Login_With_Old_Password()
        {
            using (var client = new Renci.SshNet.SshClient(_testServer.AccessIPv4, "root", _newTestServer.AdminPassword))
            {
                client.Connect();

                Assert.IsTrue(client.IsConnected);
            }
        }
Exemple #6
0
 private Renci.SshNet.SshClient GetSshClient()
 {
     if (ssh == null)
     {
         ssh = new Renci.SshNet.SshClient(host, user, GetKeyFiles());
     }
     if (!ssh.IsConnected)
     {
         ssh.Connect();
     }
     return(ssh);
 }
Exemple #7
0
        public void Should_Successfully_To_And_Login_With_Old_Password()
        {
            Assert.Inconclusive("SshClient cannot be used from assemblies with strong names.");

#if false
            using (var client = new Renci.SshNet.SshClient(_testServer.AccessIPv4, "root", _newTestServer.AdminPassword))
            {
                client.Connect();

                Assert.IsTrue(client.IsConnected);
            }
#endif
        }
        // runs multiple commands on the server
        public bool runCommands(string[] commands)
        {
            Renci.SshNet.SshCommand sshCommand;
            Renci.SshNet.SshClient  sshClient = new Renci.SshNet.SshClient(this.ipAddress, 8888, this.username, this.password);
            sshClient.Connect();

            foreach (string s in commands)
            {
                sshCommand = sshClient.RunCommand(s);
                Thread.Sleep(100);
            }
            sshClient.Disconnect();
            return(true);
        }
        private CCMBridge()
        {
            _ccmDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
            _ssh_client = new Renci.SshNet.SshClient(_ssh_host, _ssh_port, _ssh_username, _ssh_password);
            _ssh_client.Connect();

            _ssh_shellStream = _ssh_client.CreateShellStream("CCM", 80, 60, 100, 100, 1000);
            var outp = new StringBuilder();
            while (true)
            {
                outp.Append(_ssh_shellStream.Read());
                if (outp.ToString().Trim().EndsWith("$"))
                    break;
            }
        }
Exemple #10
0
        private CCMBridge()
        {
            _ccmDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
            _ssh_client = new Renci.SshNet.SshClient(Options.Default.SSH_HOST, Options.Default.SSH_PORT, Options.Default.SSH_USERNAME, Options.Default.SSH_PASSWORD);
            _ssh_client.Connect();

            _ssh_shellStream = _ssh_client.CreateShellStream("CCM", 80, 60, 100, 100, 1000);
            var outp = new StringBuilder();
            while (true)
            {
                outp.Append(_ssh_shellStream.Read());
                if (outp.ToString().Trim().EndsWith("$"))
                    break;
            }
        }
Exemple #11
0
        private string OpenAndRunCommand()
        {
            Renci.SshNet.SshClient ssh = new Renci.SshNet.SshClient("119.23.71.29", "root", "Zyp885299");
            ssh.Connect();

            var resultStr = string.Empty;

            resultStr = $"{resultStr}\r\n{RunCommand(ssh, "whoami")}";
            resultStr = $"{resultStr}\r\n{RunCommand(ssh, "ls")}";
            resultStr = $"{resultStr}\r\n{RunCommand(ssh, "ps")}";
            resultStr = $"{resultStr}\r\n{RunCommand(ssh, "top")}";
            resultStr = $"{resultStr}\r\n{RunCommand(ssh, "pwd")}";
            resultStr = $"{resultStr}\r\n{RunCommand(ssh, "exit")}";
            // ssh.Disconnect();
            return(resultStr);
        }
Exemple #12
0
        // Brute SSH
        public static void SSH(string host, string username, string password)
        {
            var SSH = new Renci.SshNet.SshClient(host, username, password);

            try
            {
                SSH.Connect();
                SSH.Disconnect();
                core.Exit("[SSH] Logged in", output);
            }
            catch
            {
                output.error = true;
                core.Exit("[SSH] Failed to login", output);
            }
            finally { SSH.Dispose(); }
        }
        private CCMBridge()
        {
            _ccmDir     = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
            _ssh_client = new Renci.SshNet.SshClient(_ssh_host, _ssh_port, _ssh_username, _ssh_password);
            _ssh_client.Connect();

            _ssh_shellStream = _ssh_client.CreateShellStream("CCM", 80, 60, 100, 100, 1000);
            var outp = new StringBuilder();

            while (true)
            {
                outp.Append(_ssh_shellStream.Read());
                if (outp.ToString().Trim().EndsWith("$"))
                {
                    break;
                }
            }
        }
Exemple #14
0
 public static void AdoptDevice(string IP, string ControllerURL = "http://unifi.scharsich.dev:8080/inform")
 {
     using (var client = new Renci.SshNet.SshClient(IP, "ubnt", "ubnt"))
     {
         client.Connect();
         var cmd = client.CreateCommand("mca-cli-op set-inform " + ControllerURL);
         cmd.Execute();
         if (cmd.ExitStatus != 0)
         {
             MessageBox.Show(cmd.Error);
         }
         else
         {
             MessageBox.Show("Device " + IP + " adopted.");
         }
         client.Disconnect();
     }
 }
Exemple #15
0
 bool IProfileItem.Stop()
 {
     using (Renci.SshNet.SshClient client = new Renci.SshNet.SshClient(Value, Username, AES.DecryptString(Password)))
     {
         try
         {
             client.Connect();
             var cmd = client.RunCommand(string.Format("{0}stop.sh", Path));
             OnLog(new LogEventArgs(string.Format("Attempting to stop all serivices on {0}", Name)));
             client.Disconnect();
         }
         catch (SocketException)
         {
             OnLog(new LogEventArgs(string.Format("Unable to connect to server {0}", Value)));
         }
     }
     return(true);
 }
Exemple #16
0
        private CCMBridge()
        {
            _ccmDir     = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
            _ssh_client = new Renci.SshNet.SshClient(Options.Default.SSH_HOST, Options.Default.SSH_PORT, Options.Default.SSH_USERNAME, Options.Default.SSH_PASSWORD);
            _ssh_client.Connect();

            _ssh_shellStream = _ssh_client.CreateShellStream("CCM", 80, 60, 100, 100, 1000);
            var outp = new StringBuilder();

            while (true)
            {
                outp.Append(_ssh_shellStream.Read());
                if (outp.ToString().Trim().EndsWith("$"))
                {
                    break;
                }
            }
        }
Exemple #17
0
        public ListResult GetListResult()
        {
            var host = Host;
            var username = Username;
            var password = Password;
            using (var sshClient = new Renci.SshNet.SshClient(host, username, password))
            {
                sshClient.Connect();
                var cmd = sshClient.CreateCommand("tdtool --list", Encoding.UTF8);
                var commandResult = cmd.Execute();

                var listDeserializer = new ListDeserializer(new SensorListDeserializer());

                var result = listDeserializer.Deserialize(commandResult);

                return result;
            }
        }
Exemple #18
0
        public void Login(string host)
        {
            if (isLoggedIn)
            {
                return;
            }

            client = new Renci.SshNet.SshClient(host, port, username, password);
            client.Connect();

            stream = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024);

            reader           = new StreamReader(stream);
            writer           = new StreamWriter(stream);
            writer.AutoFlush = true;

            isLoggedIn = true;
        }
 public Task StartAsync(CancellationToken cancellationToken)
 {
     new Thread(() =>
     {
         if (_options.SSHSettings != null)
         {
             Logs.Configuration.LogInformation($"SSH settings detected, testing connection to {_options.SSHSettings.Username}@{_options.SSHSettings.Server} on port {_options.SSHSettings.Port} ...");
             var connection              = new Renci.SshNet.SshClient(_options.SSHSettings.CreateConnectionInfo());
             connection.HostKeyReceived += (object sender, Renci.SshNet.Common.HostKeyEventArgs e) =>
             {
                 e.CanTrust = true;
                 if (!_options.IsTrustedFingerprint(e.FingerPrint, e.HostKey))
                 {
                     Logs.Configuration.LogWarning($"SSH host fingerprint for {e.HostKeyName} is untrusted, start BTCPay with -sshtrustedfingerprints \"{Encoders.Hex.EncodeData(e.FingerPrint)}\"");
                 }
             };
             try
             {
                 connection.Connect();
                 connection.Disconnect();
                 Logs.Configuration.LogInformation($"SSH connection succeeded");
             }
             catch (Renci.SshNet.Common.SshAuthenticationException)
             {
                 Logs.Configuration.LogWarning($"SSH invalid credentials");
             }
             catch (Exception ex)
             {
                 var message = ex.Message;
                 if (ex is AggregateException aggrEx && aggrEx.InnerException?.Message != null)
                 {
                     message = aggrEx.InnerException.Message;
                 }
                 Logs.Configuration.LogWarning($"SSH connection issue: {message}");
             }
             finally
             {
                 connection.Dispose();
             }
         }
     })
     {
         IsBackground = true
     }.Start();
Exemple #20
0
        public Renci.SshNet.SshClient GetConnection()
        {
            try
            {
                if (!Persistent || currentConnection == null)
                {
                    currentConnection = SshClientTools.GetSSHConnection(this);
                }
                else if (!currentConnection.IsConnected)
                {
                    currentConnection.Connect();
                }
            }
            catch
            {
                currentConnection = SshClientTools.GetSSHConnection(this);
            }

            return(currentConnection);
        }
        public void Should_Successfully_To_And_Login_With_New_Password()
        {
            bool sucess = false;

            for (int i = 0; i < 10; i++)
            {
                using (var client = new Renci.SshNet.SshClient(_testServer.AccessIPv4, "root", NewPassword))
                {
                    client.Connect();

                    sucess = client.IsConnected;

                    if (sucess)
                    {
                        break;
                    }
                }
                Thread.Sleep(1000);
            }

            Assert.IsTrue(sucess);
        }
Exemple #22
0
        public CcmBridge(string name, string ipPrefix, bool instantiateSshClient = false)
        {
            Name = name;
            IpPrefix = ipPrefix;
            CcmDir = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()));
            if (instantiateSshClient)
            {
                string sshHost = "TBD";
                int sshPort = -1;
                string sshUser  = "******";
                string sshPassword = "******";
                _sshClient = new Renci.SshNet.SshClient(sshHost, sshPort, sshUser, sshPassword);
                _sshClient.Connect();

                _sshShellStream = _sshClient.CreateShellStream("CCM", 80, 60, 100, 100, 1000);
                var outp = new StringBuilder();
                while (true)
                {
                    outp.Append(_sshShellStream.Read());
                    if (outp.ToString().Trim().EndsWith("$"))
                        break;
                }
            }
        }
        private void RestartController(object mSender, RoutedEventArgs mE)
        {
            Task.Run(() =>
            {
                string IP       = "";
                string Building = "";
                string Room     = "";
                string Tag      = "";
                (mSender as Button).Dispatcher.Invoke(() =>
                {
                    IP       = (mSender as Button).Tag.ToString();
                    Building = ((MainWindow)Application.Current.MainWindow)._1337.FindByIP(IP).Building;
                    Room     = ((MainWindow)Application.Current.MainWindow)._1337.FindByIP(IP).Room;
                    Tag      = ((MainWindow)Application.Current.MainWindow)._1337.FindByIP(IP).Tag;
                });
                using (Renci.SshNet.SshClient sshClient = new Renci.SshNet.SshClient(IP, "username", "password"))
                {
                    sshClient.HostKeyReceived += (_sender, _e) => {
                        _e.CanTrust = true;
                    };
                    Log("Attempting to connect to " + Building + " " + Room + " " + Tag + " controller");
                    sshClient.ConnectionInfo.Timeout = TimeSpan.FromSeconds(30);
                    try
                    {
                        sshClient.Connect();
                    }
                    catch
                    {
                        Log("Controller " + Building + " " + Room + " " + Tag + " connection timed out");
                        return;
                    }
                    Log("Connected to " + Building + " " + Room + " " + Tag + " controller");
                    Log("Attempting to reboot " + Building + " " + Room + " " + Tag + " controller");

                    var amxStream = sshClient.CreateShellStream("amxStream", 0, 0, 0, 0, 256);

                    bool streamLockToken = true;
                    var streamTTL        = DateTime.Now.Add(TimeSpan.FromSeconds(30));
                    while (streamLockToken)
                    {
                        if (amxStream.DataAvailable)
                        {
                            streamLockToken = false;
                        }
                        else if (DateTime.Now >= streamTTL)
                        {
                            Log("Controller " + Building + " " + Room + " " + Tag + " connection nonresponsive");
                            sshClient.Disconnect();
                            return;
                        }
                        else
                        {
                            System.Threading.Thread.Sleep(0);
                        }
                    }

                    amxStream.WriteLine("reboot");

                    Log("Reboot " + Building + " " + Room + " " + Tag + " command sent");

                    sshClient.Disconnect();
                }
            });
        }
        public void Should_Successfully_To_And_Login_With_New_Password()
        {
            bool sucess = false;
            for (int i = 0; i < 10; i++)
            {
                using (var client = new Renci.SshNet.SshClient(_testServer.AccessIPv4, "root", NewPassword))
                {
                    client.Connect();

                    sucess = client.IsConnected;

                    if (sucess)
                        break;
                }
                Thread.Sleep(1000);
            }

            Assert.IsTrue(sucess);
        }
        public void Should_Successfully_To_And_Login_With_Old_Password()
        {
            using (var client = new Renci.SshNet.SshClient(_testServer.AccessIPv4, "root", _newTestServer.AdminPassword))
            {
                client.Connect();

                Assert.IsTrue(client.IsConnected);
            }
        }
Exemple #26
0
        public void Test025_Should_Successfully_To_And_Login_With_New_Password()
        {
            var provider = new net.openstack.Providers.Rackspace.ComputeProvider();
            var serverDetails = provider.GetDetails(_testIdentity, _testServer.Id);
            using(var client = new Renci.SshNet.SshClient(serverDetails.AccessIPv4, "root", NewPassword))
            {
                client.Connect();

                Assert.IsTrue(client.IsConnected);
            }
        }
        public void Should_Successfully_To_And_Login_With_Old_Password()
        {
            var provider = new CloudServersProvider(_testIdentity);
            var serverDetails = provider.GetDetails(_testServer.Id);
            using (var client = new Renci.SshNet.SshClient(serverDetails.AccessIPv4, "root", _testServer.AdminPassword))
            {
                client.Connect();

                Assert.IsTrue(client.IsConnected);
            }
        }
        public void Should_Successfully_To_And_Login_With_New_Password()
        {
            var provider = new CloudServersProvider(_testIdentity);
            var serverDetails = provider.GetDetails(_testServer.Id);
            bool sucess = false;
            for (int i = 0; i < 10; i++)
            {
                using (var client = new Renci.SshNet.SshClient(serverDetails.AccessIPv4, "root", NewPassword))
                {
                    client.Connect();

                    sucess = client.IsConnected;

                    if (sucess)
                        break;
                }
                Thread.Sleep(1000);
            }

            Assert.IsTrue(sucess);
        }
        public void Should_Successfully_To_And_Login_With_Old_Password()
        {
            Assert.Inconclusive("SshClient cannot be used from assemblies with strong names.");

#if false
            using (var client = new Renci.SshNet.SshClient(_testServer.AccessIPv4, "root", _newTestServer.AdminPassword))
            {
                client.Connect();

                Assert.IsTrue(client.IsConnected);
            }
#endif
        }
        public void Should_Successfully_To_And_Login_With_New_Password()
        {
            Assert.Inconclusive("SshClient cannot be used from assemblies with strong names.");

#if false
            bool sucess = false;
            for (int i = 0; i < 10; i++)
            {
                using (var client = new Renci.SshNet.SshClient(_testServer.AccessIPv4, "root", NewPassword))
                {
                    client.Connect();

                    sucess = client.IsConnected;

                    if (sucess)
                        break;
                }
                Thread.Sleep(1000);
            }

            Assert.IsTrue(sucess);
#endif
        }