Example #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            SSHConnectionParameter f = new SSHConnectionParameter();

            f.UserName = "******";

            f.Password           = "******";
            f.Protocol           = SSHProtocol.SSH2;
            f.AuthenticationType = AuthenticationType.Password;

            Reader reader = new Reader();
            Socket s      = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            s.Connect(new IPEndPoint(IPAddress.Parse("192.168.10.131"), 22));
            _conn        = SSHConnection.Connect(f, reader, s);
            reader._conn = _conn;
            SSHChannel ch = _conn.OpenShell(reader);

            reader._pf = ch;
            SSHConnectionInfo ci = _conn.ConnectionInfo;

            Thread.Sleep(1000);

            byte[] b = new byte[1];

            string cmd = "ls";

            byte[] data = (new UnicodeEncoding()).GetBytes(cmd);
            reader._pf.Transmit(data);


            Thread.Sleep(5000);
            string x = reader.SessionLog;
            //reader.OnData +=
        }
Example #2
0
 public void OpenConnect()
 {
     f.UserName           = username;
     f.Password           = password;
     f.Protocol           = SSHProtocol.SSH2;
     f.AuthenticationType = AuthenticationType.Password;
     f.WindowSize         = 0x1000;
     s.Connect(new IPEndPoint(IPAddress.Parse(host), port));
     _conn    = SSHConnection.Connect(f, this, s);
     this._pf = _conn.OpenShell(this);
     SSHConnectionInfo ci = _conn.ConnectionInfo;
 }
Example #3
0
        private static void AgentForward()
        {
            SSHConnectionParameter f = new SSHConnectionParameter();

            f.EventTracer = new Tracer(); //to receive detailed events, set ISSHEventTracer
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            f.Protocol = SSHProtocol.SSH2;  //this sample works on both SSH1 and SSH2
            string host_ip = "172.22.1.15"; //<--!!! [TO USERS OF Granados]

            f.UserName = "******";            //<--!!! if you try this sample, edit these values for your environment!
            string password = "";

            s.Connect(new IPEndPoint(IPAddress.Parse(host_ip), 22)); //22 is the default SSH port

            //former algorithm is given priority in the algorithm negotiation
            f.PreferableHostKeyAlgorithms = new PublicKeyAlgorithm[] { PublicKeyAlgorithm.RSA, PublicKeyAlgorithm.DSA };
            f.PreferableCipherAlgorithms  = new CipherAlgorithm[] { CipherAlgorithm.Blowfish, CipherAlgorithm.TripleDES };
            f.WindowSize   = 0x1000;      //this option is ignored with SSH1
            f.AgentForward = new AgentForwardClient();
            Reader reader = new Reader(); //simple event receiver

            AuthenticationType at = AuthenticationType.Password;

            f.AuthenticationType = at;
            f.Password           = password;

            //Creating a new SSH connection over the underlying socket
            _conn        = SSHConnection.Connect(f, reader, s);
            reader._conn = _conn;

            //Opening a shell
            SSHChannel ch = _conn.OpenShell(reader);

            reader._pf = ch;

            while (!reader._ready)
            {
                Thread.Sleep(100);
            }

            Thread.Sleep(1000);
            ch.Transmit(Encoding.Default.GetBytes("ssh -A -l okajima localhost\r"));

            //Go to sample shell
            SampleShell(reader);
        }
Example #4
0
        private void OpenShell()
        {
            m_cmdLineAdapter = Dialect.CreateCmdLineAdapter();
            m_stream         = new PipeStream();
            //m_reader = new StreamReader(m_stream);
            SSHConnectionParameter f = new SSHConnectionParameter();

            f.UserName           = Params.SshLogin;
            f.Password           = Params.SshPassword;
            f.Protocol           = SSHProtocol.SSH2;
            f.AuthenticationType = AuthenticationType.Password;
            f.WindowSize         = 0x1000;
            m_treader            = new STunReader(m_stream);
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            s.Connect(Params.SshHost, Params.SshPort);
            m_conn = SSHConnection.Connect(f, m_treader, s);

            m_treader.Channel = m_conn.OpenShell(m_treader);

            //SSHConnectionInfo ci = m__conn.ConnectionInfo;

            //byte[] b = new byte[1];
            //while (true)
            //{
            //    int input = System.Console.Read();

            //    b[0] = (byte)input;
            //    //Debug.WriteLine(input);
            //    reader._pf.Transmit(b);
            //}


            //m_shell = new SshShell(Params.SshHost, Params.SshLogin);
            //if (!String.IsNullOrEmpty(Params.SshPassword)) m_shell.Password = Params.SshPassword;
            //if (!String.IsNullOrEmpty(Params.IdentifyFile)) m_shell.AddIdentityFile(Params.IdentifyFile);
            //m_shell.Connect(Params.SshPort);
            //m_shell.WriteLine("echo AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
            //m_instream = new PipeStream();
            //m_outstream = new PipeStream();
            //m_outstream.BlockLastReadBuffer = false;
            //m_shell.SetStream(m_instream, m_outstream);
            ////m_stream = m_shell.GetStream();
            ////m_shell.m_instream = (PipedInputStream)((CombinedStream)m_stream).InputStream;
            //m_reader = new StreamReader(m_outstream);
            //ConsumeOutput();
        }
Example #5
0
        private void Connect(string hostname, string user, string pass, string private_key_file)
        {
            SSHConnectionParameter f = new SSHConnectionParameter();

            f.UserName = user;
            f.Password = pass;
            f.Protocol = Routrek.SSHC.SSHProtocol.SSH2;

            if (string.IsNullOrWhiteSpace(private_key_file))
            {
                f.AuthenticationType = Routrek.SSHC.AuthenticationType.Password;
            }
            else
            {
                f.AuthenticationType = Routrek.SSHC.AuthenticationType.PublicKey;
                f.IdentityFile       = private_key_file;
            }
            f.WindowSize = 0x1000;
            f.Protocol   = SSHProtocol.SSH2;

            Socket    s  = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            IPAddress ip = Dns.GetHostEntry(hostname).AddressList[0]; // Dns.GetHostByName(hostname).AddressList[0];

            s.Connect(new IPEndPoint(ip, 22));
            _conn = Routrek.SSHC.SSHConnection.Connect(f, reader, s);

            Routrek.SSHC.SSHChannel ch = _conn.OpenShell(reader);
            ch.ResizeTerminal(80, 24, 14, 14);
            reader._pf = ch;
            Routrek.SSHC.SSHConnectionInfo ci = _conn.ConnectionInfo;


            if (!eReadyToRoll.WaitOne(60000))
            {
                //prompt not received
                throw new Exception("Connected to the target OK, but have not received the clear command prompt ($ or #).");
            }

            isOpen = true;
        }
Example #6
0
        /// <summary>
        /// Method to connect to the Wabis machine
        /// </summary>
        /// <returns>true if connected else false</returns>
        public bool Connect()
        {
            connParameter.Protocol           = Routrek.SSHC.SSHProtocol.SSH2;
            connParameter.AuthenticationType = AuthenticationType.Password;
            connParameter.WindowSize         = 0x1000;
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, System.Net.Sockets.ProtocolType.Tcp);

            try
            {
                s.Connect(new IPEndPoint(_ipAddress, 22));
            }
            catch
            {
                s.Close();
                return(false);
            }

            try
            {
                _conn             = SSHConnection.Connect(connParameter, reader, s);
                reader.connection = _conn;
                Routrek.SSHC.SSHChannel ch = _conn.OpenShell(reader);
                reader.Channel = ch;
                SSHConnectionInfo ci = _conn.ConnectionInfo;
                reader.notify += new RcvdData(PrintResult);
                if (_conn.AuthenticationResult.ToString() == "Success")
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception connectionException)
            {
                Framework.Logger.LogError("Fail to connect to SSH Server, error: " + connectionException.Message);
                throw connectionException;
            }
        }
        private static void AgentForward()
        {
            SSHConnectionParameter f = new SSHConnectionParameter();
            f.EventTracer = new Tracer(); //to receive detailed events, set ISSHEventTracer
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            f.Protocol = SSHProtocol.SSH2; //this sample works on both SSH1 and SSH2
            string host_ip = "172.22.1.15"; //<--!!! [TO USERS OF Granados]
            f.UserName = "******";               //<--!!! if you try this sample, edit these values for your environment!
            string password = "";
            s.Connect(new IPEndPoint(IPAddress.Parse(host_ip), 22)); //22 is the default SSH port

            //former algorithm is given priority in the algorithm negotiation
            f.PreferableHostKeyAlgorithms = new PublicKeyAlgorithm[] { PublicKeyAlgorithm.RSA, PublicKeyAlgorithm.DSA };
            f.PreferableCipherAlgorithms = new CipherAlgorithm[] { CipherAlgorithm.Blowfish, CipherAlgorithm.TripleDES };
            f.WindowSize = 0x1000; //this option is ignored with SSH1
            f.AgentForward = new AgentForwardClient();
            Reader reader = new Reader(); //simple event receiver

            AuthenticationType at = AuthenticationType.Password;
            f.AuthenticationType = at;
            f.Password = password;

            //Creating a new SSH connection over the underlying socket
            _conn = SSHConnection.Connect(f, reader, s);
            reader._conn = _conn;

            //Opening a shell
            SSHChannel ch = _conn.OpenShell(reader);
            reader._pf = ch;

            while (!reader._ready)
                Thread.Sleep(100);

            Thread.Sleep(1000);
            ch.Transmit(Encoding.Default.GetBytes("ssh -A -l okajima localhost\r"));

            //Go to sample shell
            SampleShell(reader);
        }
Example #8
0
        //Tutorial: Connecting to a host and opening a shell
        private static void ConnectAndOpenShell()
        {
            SSHConnectionParameter f = new SSHConnectionParameter();

            f.EventTracer = new Tracer();             //to receive detailed events, set ISSHEventTracer
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            f.Protocol = SSHProtocol.SSH2;  //this sample works on both SSH1 and SSH2
            string host_ip = "172.22.1.15"; //<--!!! [TO USERS OF Granados]

            f.UserName = "******";         //<--!!! if you try this sample, edit these values for your environment!
            string password = "******";

            s.Connect(new IPEndPoint(IPAddress.Parse(host_ip), 22));             //22 is the default SSH port

            //former algorithm is given priority in the algorithm negotiation
            f.PreferableHostKeyAlgorithms = new PublicKeyAlgorithm[] { PublicKeyAlgorithm.RSA, PublicKeyAlgorithm.DSA };
            f.PreferableCipherAlgorithms  = new CipherAlgorithm[] { CipherAlgorithm.Blowfish, CipherAlgorithm.TripleDES };
            f.WindowSize = 0x1000;        //this option is ignored with SSH1
            Reader reader = new Reader(); //simple event receiver

            AuthenticationType at = AuthenticationType.PublicKey;

            f.AuthenticationType = at;

            if (at == AuthenticationType.KeyboardInteractive)
            {
                //Creating a new SSH connection over the underlying socket
                _conn        = SSHConnection.Connect(f, reader, s);
                reader._conn = _conn;
                Debug.Assert(_conn.AuthenticationResult == AuthenticationResult.Prompt);
                AuthenticationResult r = ((SSH2Connection)_conn).DoKeyboardInteractiveAuth(new string[] { password });
                Debug.Assert(r == AuthenticationResult.Success);
            }
            else
            {
                //NOTE: if you use public-key authentication, follow this sample instead of the line above:
                //f.AuthenticationType = AuthenticationType.PublicKey;
                f.IdentityFile = "C:\\P4\\tools\\keys\\aaa";
                f.Password     = password;
                f.KeyCheck     = delegate(SSHConnectionInfo info) {
                    byte[] h = info.HostKeyMD5FingerPrint();
                    foreach (byte b in h)
                    {
                        Debug.Write(String.Format("{0:x2} ", b));
                    }
                    return(true);
                };

                //Creating a new SSH connection over the underlying socket
                _conn        = SSHConnection.Connect(f, reader, s);
                reader._conn = _conn;
            }

            //Opening a shell
            SSHChannel ch = _conn.OpenShell(reader);

            reader._pf = ch;

            //you can get the detailed connection information in this way:
            SSHConnectionInfo ci = _conn.ConnectionInfo;

            //Go to sample shell
            SampleShell(reader);
        }
Example #9
0
        static void Main(string[] args)
        {
            /*
             * string cn = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
             * string t1 = Routrek.SSHC.Strings.GetString("NotSSHServer");
             * System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("ja");
             * Routrek.SSHC.Strings.Reload();
             * string t2 = Routrek.SSHC.Strings.GetString("NotSSHServer");
             */

#if false //RSA keygen
            //RSA KEY GENERATION TEST
            byte[]     testdata = Encoding.ASCII.GetBytes("CHRISTIAN VIERI");
            RSAKeyPair kp       = RSAKeyPair.GenerateNew(2048, new Random());
            byte[]     sig      = kp.Sign(testdata);
            kp.Verify(sig, testdata);

            new SSH2UserAuthKey(kp).WritePublicPartInOpenSSHStyle(new FileStream("C:\\IOPort\\newrsakey", FileMode.Create));
            //SSH2UserAuthKey newpk = SSH2PrivateKey.FromSECSHStyleFile("C:\\IOPort\\newrsakey", "nedved");
#endif

#if false //DSA keygen
            //DSA KEY GENERATION TEST
            byte[]     testdata = Encoding.ASCII.GetBytes("CHRISTIAN VIERI 0000");
            DSAKeyPair kp       = DSAKeyPair.GenerateNew(2048, new Random());
            byte[]     sig      = kp.Sign(testdata);
            kp.Verify(sig, testdata);
            new SSH2UserAuthKey(kp).WritePublicPartInOpenSSHStyle(new FileStream("C:\\IOPort\\newdsakey", FileMode.Create));
            //SSH2PrivateKey newpk = SSH2PrivateKey.FromSECSHStyleFile("C:\\IOPort\\newdsakey", "nedved");
#endif

            SSHConnectionParameter f = new SSHConnectionParameter();
            f.UserName = "******";
#if false //SSH1
            //SSH1
            f.Password                   = "";
            f.Protocol                   = SSHProtocol.SSH2;
            f.AuthenticationType         = AuthenticationType.Password;
            f.PreferableCipherAlgorithms = new CipherAlgorithm[] { CipherAlgorithm.Blowfish, CipherAlgorithm.TripleDES };
#else //SSH2
            f.Password           = "";
            f.Protocol           = SSHProtocol.SSH2;
            f.AuthenticationType = AuthenticationType.Password;
            f.WindowSize         = 0x1000;
#endif
            Reader reader = new Reader();
            Socket s      = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            //s.Blocking = false;
            s.Connect(new IPEndPoint(IPAddress.Parse("192.168.1.1"), 22));
            _conn        = SSHConnection.Connect(f, reader, s);
            reader._conn = _conn;
#if false   //Remote->Local
            _conn.ListenForwardedPort("0.0.0.0", 29472);
#elif false //Local->Remote
            SSHChannel ch = _conn.ForwardPort(reader, "www.yahoo.co.jp", 80, "localhost", 0);
            reader._pf = ch;
            while (!reader._ready)
            {
                System.Threading.Thread.Sleep(100);
            }
            reader._pf.Transmit(Encoding.ASCII.GetBytes("GET / HTTP/1.0\r\n\r\n"));
#elif false //SSH over SSH
            f.Password = "******";
            SSHConnection con2 = _conn.OpenPortForwardedAnotherConnection(f, reader, "kuromatsu", 22);
            reader._conn = con2;
            SSHChannel ch = con2.OpenShell(reader);
            reader._pf = ch;
#else //normal shell
            SSHChannel ch = _conn.OpenShell(reader);
            reader._pf = ch;
#endif

            //Debug.WriteLine(_conn.ConnectionInfo.DumpHostKeyInKnownHostsStyle());
            SSHConnectionInfo ci = _conn.ConnectionInfo;

            Thread.Sleep(1000);
            //((SSH2Connection)_conn).ReexchangeKeys();

            byte[] b = new byte[1];
            while (true)
            {
                int input = System.Console.Read();

                b[0] = (byte)input;
                //Debug.WriteLine(input);
                reader._pf.Transmit(b);
            }
        }
Example #10
0
        private static void AgentForward()
        {
            SSHConnectionParameter f = new SSHConnectionParameter("172.22.1.15", 22, SSHProtocol.SSH2, AuthenticationType.Password, "root", "");
            f.EventTracer = new Tracer(); //to receive detailed events, set ISSHEventTracer
            Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            s.Connect(new IPEndPoint(IPAddress.Parse(f.HostName), f.PortNumber)); //22 is the default SSH port

            //former algorithm is given priority in the algorithm negotiation
            f.PreferableHostKeyAlgorithms = new PublicKeyAlgorithm[] { PublicKeyAlgorithm.RSA, PublicKeyAlgorithm.DSA };
            f.PreferableCipherAlgorithms = new CipherAlgorithm[] { CipherAlgorithm.Blowfish, CipherAlgorithm.TripleDES };
            f.WindowSize = 0x1000; //this option is ignored with SSH1
            f.AgentForward = new AgentForwardClient();
            Reader reader = new Reader(); //simple event receiver

            //Creating a new SSH connection over the underlying socket
            _conn = SSHConnection.Connect(f, reader, s);
            reader._conn = _conn;

            //Opening a shell
            SSHChannel ch = _conn.OpenShell(reader);
            reader._pf = ch;

            while (!reader._ready)
                Thread.Sleep(100);

            Thread.Sleep(1000);
            ch.Transmit(Encoding.Default.GetBytes("ssh -A -l okajima localhost\r"));

            //Go to sample shell
            SampleShell(reader);
        }