Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #3
0
        protected override bool StopJob(Job operation)
        {
            if (!_jobPids.ContainsKey(operation.Guid))
            {
                return(false);
            }

            var ssh = new Chilkat.Ssh();

            if (!ssh.Connect(_domainName, _port))
            {
                return(false);
            }

            if (!ssh.AuthenticatePk(_username, _privateKey))
            {
                return(false);
            }

            var result = ssh.ChannelSendClose(_jobPids[operation.Guid]);

            _jobPids.Remove(operation.Guid);

            return(result);
        }
Beispiel #4
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);
        }
Beispiel #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);
        }
Beispiel #6
0
        protected override bool StartJob(Job operation)
        {
            var ssh = new Chilkat.Ssh();

            if (!ssh.Connect(_domainName, _port))
            {
                return(false);
            }

            if (!ssh.AuthenticatePk(_username, _privateKey))
            {
                return(false);
            }

            var execPath = $"{_rootPath}/{operation.Method.Name}";
            var args     = new StringBuilder($"{_rootPath}/data");

            foreach (var input in operation.Input)
            {
                args.Append($" {input.Id}");
            }

            var command = $"./{execPath} {args}";
            var pid     = ssh.QuickCmdSend(command);

            if (pid < 0)
            {
                return(false);
            }
            else
            {
                _jobPids.Add(operation.Guid, pid);
            }

            return(true);
        }
Beispiel #7
0
        public static void publickeyAuth()
        {
            Chilkat.Ssh ssh = new Chilkat.Ssh();

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

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

            //  Set some timeouts, in milliseconds:
            ssh.ConnectTimeoutMs = 5000;
            ssh.IdleTimeoutMs    = 15000;

            //  Connect to the SSH server.
            //  The standard SSH port = 22
            //  The hostname may be a hostname or IP address.
            int    port;
            string hostname;

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

            Chilkat.SshKey key = new Chilkat.SshKey();

            //  Read the PEM file into a string variable:
            //  (This does not load the PEM file into the key.  The LoadText
            //  method is a convenience method for loading the full contents of ANY text
            //  file into a string variable.)
            string privKey = key.LoadText("private.ppk");

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

            //  Load a private key from a PEM string:
            //  (Private keys may be loaded from OpenSSH and Putty formats.
            //  Both encrypted and unencrypted private key file formats
            //  are supported.  This example loads an unencrypted private
            //  key in OpenSSH format.  PuTTY keys typically use the .ppk
            //  file extension, while OpenSSH keys use the PEM format.
            //  (For PuTTY keys, call FromPuttyPrivateKey instead.)
            success = key.FromOpenSshPrivateKey(privKey);
            if (success != true)
            {
                Console.WriteLine(key.LastErrorText);
                return;
            }

            //  Authenticate with the SSH server using the login and
            //  private key.  (The corresponding public key should've
            //  been installed on the SSH server beforehand.)
            success = ssh.AuthenticatePk("myLogin", key);
            if (success != true)
            {
                Console.WriteLine(ssh.LastErrorText);
                return;
            }

            Console.WriteLine(ssh.LastErrorText);
            Console.WriteLine("Public-Key Authentication Successful!");
        }
Beispiel #8
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);
        }
Beispiel #9
0
        public static void puttykeyAuth(int serverPort)
        {
            Chilkat.Ssh ssh = new Chilkat.Ssh();

            bool success = ssh.UnlockComponent("Anything for 30-day trial.");

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

            //  Load a .ppk PuTTY private key.
            Chilkat.SshKey puttyKey = new Chilkat.SshKey();
            string         ppkText  = puttyKey.LoadText("private_key.ppk");

            //  The ppkText contains this content:

            //      PuTTY-User-Key-File-2: ssh-rsa
            //      Encryption: aes256-cbc
            //      Comment: rsa-key-20170126
            //      Public-Lines: 6
            //      AAAAB3NzaC1yc2EAAAABJQAAAQEAx+52s7vvaZ8rT2UdFZWlSUVDHDQ+5ZRFvgRW
            //      6nm2sO1c9WqNg7u2PQL4jeKSDX2XWcMnpleALz2x8Rr4rMy5E1iZzvWov8VtFd8l
            //      fa9HOkgEeJB3VFuYR3NlnD3eyCoYJYPVpHJHrIeui2WZs5vQ76HDe+th8+z5Ald4
            //      zPw3p2c6ZJpBrkSBM67hWokoBDi23c7NhszDHhJBrv+B98cQxnagI1PUKqN7E8Vg
            //      bNtBI8beIMHyI69up9G1AXSEi0cGIjYNx9RNUPau1mRk/SvfqxgWkAjM005lj7hc
            //      bOsjbdKK3T2NtrKTaYjEiXlEXcj1iGuApsD/m73pYaEJB3Nd7w==
            //      Private-Lines: 14
            //      MoaDbq0owouN/7Z9Pga0favDhM2bSEgMErJBxdDmNUXIVVcUoLiD/Ps1RA+BeBBX
            //      wxqKUt9PqLy/pnafPR/i2xjJiQtQ0CWkPxND16Gi1dqLzmbQYYl1ev4+LzuG0zNX
            //      HDGMvRiwagY7mY+F1tUjBYfOL6z8XHw4m40YcY1QorOO+0MMzAVT5Hkg8YyXW209
            //      B/V/LRADFMVA2BlL39y11cb5ZpFStPH/waYUMY+2w1ZmJZ7dcRoMjuKmY+YE/tUx
            //      n9X3P0qTNSbw6e6sMG3Dhr1vfoJUQWApUliD6GpUiCeIvXBcVqG8Vsfq9XADsPl0
            //      +nFAwjSZflywcB7/FwhGb7q5UmcJK06SzoMl7Og5e3g7NCs3yNNQIv+qCpDjhxrA
            //      hpT03mbipu7OXCZDeUwUhMGJAmYHE5iqm1rPCsSVbaMgpxhCWf01Cx4gLx3aMvn4
            //      MdylA31GuL3wSxcWTslrOI8+449lZN/qZEnGEZkYTrnlu123jTqsAWMMtuHSz2Ig
            //      6GA89oTdlppkNflhNH3OJ85kMUrc3p/ZBMdndz8jTDTljmJjHR5oNMoShFof115A
            //      nWjUHqBwCgcubLYyH3afDvBTOhtl0tJ9Oby0wJlOAGnCXiPSDbF/y7J7xml/PS9t
            //      XlSVNxtAY15NDO6Fp96sBVfKuJsfJ90PzdBom4ikIuf7sMwtElrHHLuYfcXJQYLp
            //      G5jBmqDgnirosVPEBIxlxFzz/HCRmdU+tsYg46gqI4R5UpKUe8WSaJoZkDGsrqhm
            //      e+1SJaBuafR4v2bx/bV414Hg7LGQosK2S3crxH4UgZl+g02vWznZfBH+9CmHvKDR
            //      AxfcKOTzsaILKJtQPV81lmJ45sARYMcB5jMiE4kBg56hiXouChsvKkm55WVcW1E+
            //      Private-MAC: 17512c9f7582c1d9c3ae2b01b4d67a6b1dbd1d0e

            //  "secret" is the actual password for the above PPK.

            puttyKey.Password = "******";
            success           = puttyKey.FromPuttyPrivateKey(ppkText);
            if (success != true)
            {
                Console.WriteLine(puttyKey.LastErrorText);
                return;
            }

            string sshHostname = "172.24.16.155";
            //string sshHostname = "172.24.19.59";
            int sshPort = 22;

            //  Connect to an SSH server
            success = ssh.Connect(sshHostname, sshPort);
            if (success != true)
            {
                Console.WriteLine(ssh.LastErrorText);
                return;
            }

            //  Authenticate with the SSH server using a username + private key.
            //  (The private key serves as the password.  The username identifies
            //  the SSH user account on the server.)
            success = ssh.AuthenticatePk("harinath", puttyKey);
            if (success != true)
            {
                Console.WriteLine(ssh.LastErrorText);
                return;
            }

            Console.WriteLine("OK, the connection and authentication with the SSH server is completed.");
        }
        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
        }
Beispiel #11
0
 public SshBot()
 {
     _client = new Chilkat.Ssh();
     _client.IdleTimeoutMs = IdleTimeoutMs;
     _client.ReadTimeoutMs = ReadTimeoutMs;
 }