コード例 #1
0
        public bool CheckConnection()
        {
            Chilkat.Ssh ssh = new Chilkat.Ssh();

            bool success = ssh.Connect(DestinationAdress, Port);

            if (success != true)
            {
                Debug.WriteLine(ssh.LastErrorText);
                return(false);
            }

            // Wait a max of 5 seconds when reading responses..
            ssh.IdleTimeoutMs = 5000;

            // Authenticate using login/password:
            success = ssh.AuthenticatePw(UserName, _password);
            if (success != true)
            {
                Debug.WriteLine(ssh.LastErrorText);
                return(false);
            }

            return(success);
        }
コード例 #2
0
        public bool RunSSHCode(string Code, ref string resultmessage)
        {
            Chilkat.Ssh ssh = new Chilkat.Ssh();

            bool success = ssh.Connect(DestinationAdress, Port);

            if (success != true)
            {
                Debug.WriteLine(ssh.LastErrorText);
                return(false);
            }

            // Wait a max of 5 seconds when reading responses..
            ssh.IdleTimeoutMs = 5000;

            // Authenticate using login/password:
            success = ssh.AuthenticatePw(UserName, _password);
            if (success != true)
            {
                Debug.WriteLine(ssh.LastErrorText);
                return(false);
            }

            //  Send some commands and get the output.
            resultmessage = ssh.QuickCommand(Code, "ansi");
            if (ssh.LastMethodSuccess != true)
            {
                Debug.WriteLine(ssh.LastErrorText);
                return(false);
            }
            Debug.WriteLine(resultmessage);


            return(true);
        }
コード例 #3
0
        public bool UploadStringWithSCP(string content, string destFileName)
        {
            Chilkat.Ssh ssh     = new Chilkat.Ssh();
            bool        success = ssh.Connect(DestinationAdress, Port);

            if (success != true)
            {
                Debug.WriteLine(ssh.LastErrorText);
                return(false);
            }

            // Wait a max of 5 seconds when reading responses..
            ssh.IdleTimeoutMs = 5000;

            // Authenticate using login/password:
            success = ssh.AuthenticatePw(UserName, _password);
            if (success != true)
            {
                Debug.WriteLine(ssh.LastErrorText);
                return(false);
            }

            // Once the SSH object is connected and authenticated, we use it
            // as the underlying transport in our SCP object.
            Chilkat.Scp scp = new Chilkat.Scp();

            success = scp.UseSsh(ssh);
            if (success != true)
            {
                Debug.WriteLine(scp.LastErrorText);
                return(false);
            }

            // The utf-8 byte representation of the string will be uploaded.
            // See https://www.chilkatsoft.com/p/p_463.asp for a list of valid charsets.
            string charset = "utf-8";

            // This uploads to the "uploads/text" directory relative to the HOME
            // directory of the SSH user account.
            // Note: The remote target directory must already exist on the SSH server.
            success = scp.UploadString(destFileName, content, charset);
            if (success != true)
            {
                Debug.WriteLine(scp.LastErrorText);
                return(false);
            }

            Debug.WriteLine("SCP upload string success.");

            // Disconnect
            ssh.Disconnect();

            return(true);
        }
コード例 #4
0
ファイル: SshBot.cs プロジェクト: dusty3ntity/certpot
        public void AuthenticateWithPassword(string username, string password)
        {
            if (!_client.IsConnected)
            {
                throw new Exception("Client is not connected");
            }

            if (!_client.AuthenticatePw(username, password))
            {
                throw new SshException(ErrorType.SshAuthenticationError, _client.LastErrorText);
            }

            IsAuthenticated = true;
        }
コード例 #5
0
        public bool UploadWithScp(string sourceFileName, string destFileName)
        {
            Chilkat.Ssh ssh = new Chilkat.Ssh();

            bool success = ssh.Connect(DestinationAdress, Port);

            if (success != true)
            {
                Debug.WriteLine(ssh.LastErrorText);
                return(false);
            }

            // Wait a max of 5 seconds when reading responses..
            ssh.IdleTimeoutMs = 5000;

            // Authenticate using login/password:
            success = ssh.AuthenticatePw(UserName, _password);
            if (success != true)
            {
                Debug.WriteLine(ssh.LastErrorText);
                return(false);
            }

            // Once the SSH object is connected and authenticated, we use it
            // as the underlying transport in our SCP object.
            Chilkat.Scp scp = new Chilkat.Scp();

            success = scp.UseSsh(ssh);
            if (success != true)
            {
                Debug.WriteLine(scp.LastErrorText);
                return(false);
            }

            success = scp.UploadFile(sourceFileName, destFileName);
            if (success != true)
            {
                Debug.WriteLine(scp.LastErrorText);
                return(false);
            }

            Debug.WriteLine("SCP upload file success.");

            // Disconnect
            ssh.Disconnect();

            return(true);
        }
コード例 #6
0
        public static void newMethod()
        {
            //  This example assumes Chilkat SSH/SFTP to have been previously unlocked.
            //  See Unlock SSH for sample code.

            Chilkat.Ssh ssh = new Chilkat.Ssh();

            //  Any string automatically begins a fully-functional 30-day trial.
            bool suc = ssh.UnlockComponent("Anything for 30-day trial");

            if (suc != true)
            {
                Console.WriteLine(ssh.LastErrorText);
                return;
            }
            int  port    = 22;
            bool success = ssh.Connect("172.24.16.155", port);

            if (success != true)
            {
                Console.WriteLine(ssh.LastErrorText);
                return;
            }

            //  Authenticate using login/password:
            success = ssh.AuthenticatePw("harinath", "1234");
            if (success != true)
            {
                Console.WriteLine(ssh.LastErrorText);
                return;
            }

            //  Send some commands and get the output.
            string strOutput = ssh.QuickCommand("df", "ansi");

            if (ssh.LastMethodSuccess != true)
            {
                Console.WriteLine(ssh.LastErrorText);
                return;
            }

            Console.WriteLine("---- df ----");
            Console.WriteLine(strOutput);

            strOutput = ssh.QuickCommand("echo hello world", "ansi");
            if (ssh.LastMethodSuccess != true)
            {
                Console.WriteLine(ssh.LastErrorText);
                return;
            }

            Console.WriteLine("---- echo hello world ----");
            Console.WriteLine(strOutput);

            strOutput = ssh.QuickCommand("date", "ansi");
            if (ssh.LastMethodSuccess != true)
            {
                Console.WriteLine(ssh.LastErrorText);
                return;
            }

            Console.WriteLine("---- date ----");
            Console.WriteLine(strOutput);
        }
        private void bgWorker_req_maker_DoWork(object sender, DoWorkEventArgs e)
        {
            Chilkat.Ssh ssh     = new Chilkat.Ssh();
            bool        success = false;
            // Connect to an SSH server:
            string ssh_hostname = "";
            int    ssh_port     = 22;
            string ssh_username = "";
            string ssh_password = "";

            if (sshServerTextBox.Text == "")
            {
                MessageBox.Show("SSH Target Is Not valid !");
            }
            else if (AbdalControler.unauthorized_process == true)
            {
                MessageBox.Show("This domain is unauthorized !");
                Application.Exit();
            }
            else
            {
                try
                {
                    int success_password_counter = 0;



                    radRadialGauge.RangeEnd = this.password_file_line.Length;
                    for (int counter = 0; counter <= this.password_file_line.Length; counter++)
                    {
                        if (AbdalControler.stop_force_process == true)
                        {
                            break;
                        }

                        if (FastTrafficGenToggleSwitch.Value == false)
                        {
                            System.Threading.Thread.Sleep(500);
                        }



                        if (this.password_file_line[counter] != "")
                        {
                            radRadialGauge.Value = counter;
                            ssh_hostname         = sshServerTextBox.Text;
                            ssh_username         = sshUserNameTextBox.Text;
                            ssh_password         = this.password_file_line[counter];
                            ssh_port             = Convert.ToInt32(sshPortTextBox.Text);



                            if (proxy_ToggleSwitch.Value == true)
                            {
                                ssh.HttpProxyHostname = proxyServerTextBox.Text;
                                ssh.HttpProxyPort     = Convert.ToInt32(proxyPortTextBox.Text);

                                ssh.HttpProxyUsername = proxyUserNameTextBox.Text;
                                ssh.HttpProxyPassword = proxyPasswordTextBox.Text;

                                if (proxyVersionDropDownList.Text == "Basic")
                                {
                                    ssh.HttpProxyAuthMethod = "Basic";
                                }
                                else if (proxyVersionDropDownList.Text == "NTLM")
                                {
                                    ssh.HttpProxyAuthMethod = "NTLM";
                                }
                                else
                                {
                                    ////
                                }
                            }


                            success = ssh.Connect(ssh_hostname, ssh_port);
                            if (success == true)
                            {
                                ssh.IdleTimeoutMs = 5000;
                                success           = ssh.AuthenticatePw(ssh_username, ssh_password);
                                //Found Password
                                if (success == true)
                                {
                                    success_password_counter++;
                                    success_passwordRichTextBox.Items.Add("[+] " + sshUserNameTextBox.Text + " >>" + " " + this.password_file_line[counter]);
                                    success_password_links_text.Text = success_password_counter.ToString();
                                    using (var soundPlayer = new SoundPlayer(@"pass-foun.wav"))
                                    {
                                        soundPlayer.PlaySync(); // can also use soundPlayer.Play()
                                    }
                                    ssh.Disconnect();
                                }
                                else
                                {
                                    LogAttackTextEditor.AppendText("[-] " + sshUserNameTextBox.Text + " >>" + " " + this.password_file_line[counter] + Environment.NewLine);
                                    LogAttackTextEditor.SelectionStart = LogAttackTextEditor.Text.Length;
                                    LogAttackTextEditor.ScrollToCaret();

                                    ssh.Disconnect();
                                }
                            }
                            else
                            {
                                //  watch -n 1 "cat /var/log/auth.log | grep 'Failed password'"


                                LogAttackTextEditor.AppendText("Cannot connect to ssh server" + Environment.NewLine);
                                LogAttackTextEditor.SelectionStart = LogAttackTextEditor.Text.Length;
                                LogAttackTextEditor.ScrollToCaret();

                                ssh.Disconnect();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            } // End else
        }