Esempio n. 1
0
        private static SSHConnection ConnectMain(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, ProtocolNegotiationHandler pnh, AbstractSocket s)
        {
            pnh.Wait();

            if (pnh.State != ReceiverState.Ready)
            {
                throw new SSHException(pnh.ErrorMessage);
            }

            string sv = pnh.ServerVersion;

            SSHConnection con = null;

            if (param.Protocol == SSHProtocol.SSH1)
            {
                con = new SSH1Connection(param, receiver, sv, SSHUtil.ClientVersionString(param.Protocol));
            }
            else
            {
                con = new SSH2Connection(param, receiver, sv, SSHUtil.ClientVersionString(param.Protocol));
            }

            s.SetHandler(con.PacketBuilder);
            SendMyVersion(s, param);

            if (con.Connect(s) != AuthenticationResult.Failure)
            {
                return(con);
            }
            else
            {
                s.Close();
                return(null);
            }
        }
 protected SSHChannel(SSHConnection con, ChannelType type, int local_id)
 {
     con.RegisterChannel(local_id, this);
     _connection = con;
     _type = type;
     _localID = local_id;
 }
 protected SSHChannel(SSHConnection con, ChannelType type, int local_id)
 {
     con.RegisterChannel(local_id, this);
     _connection = con;
     _type       = type;
     _localID    = local_id;
 }
Esempio n. 4
0
 public SSH2Channel(SSHConnection con, ChannelType type, int local_id, int remote_id, int maxpacketsize)
     : base(con, type, local_id)
 {
     _windowSize = _leftWindowSize = con.Param.WindowSize;
     Debug.Assert(type==ChannelType.ForwardedRemoteToLocal);
     _remoteID = remote_id;
     _serverMaxPacketSize = maxpacketsize;
     _negotiationStatus = 0;
 }
Esempio n. 5
0
        /**
         * opens another SSH connection via port-forwarded connection
         */
        public SSHConnection OpenPortForwardedAnotherConnection(SSHConnectionParameter param, ISSHConnectionEventReceiver receiver, string host, int port)
        {
            ProtocolNegotiationHandler pnh = new ProtocolNegotiationHandler(param);
            ChannelSocket s = new ChannelSocket(pnh);

            SSHChannel ch = ForwardPort(s, host, port, "localhost", 0);

            s.SSHChennal = ch;
            return(SSHConnection.Connect(param, receiver, pnh, s));
        }
Esempio n. 6
0
 public SSH2Channel(SSHConnection con, ChannelType type, int local_id)
     : base(con, type, local_id)
 {
     _windowSize = _leftWindowSize = con.Param.WindowSize;
     _negotiationStatus = type==ChannelType.Shell? 3 : type==ChannelType.ForwardedLocalToRemote? 1 : type==ChannelType.Session? 1 : 0;
 }
Esempio n. 7
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;
        }
 public SSH1Channel(SSHConnection con, ChannelType type, int local_id, int remote_id)
     : base(con, type, local_id)
 {
     _remoteID = remote_id;
 }
 public SSH1Channel(SSHConnection con, ChannelType type, int local_id)
     : base(con, type, local_id)
 {
 }
Esempio n. 10
0
        public void start()
        {
            try
            {
                SSHConnectionParameter f = new SSHConnectionParameter();
                f.UserName = userName;

                f.Password = passwordWord;
                f.Protocol = SSHProtocol.SSH2;
                f.AuthenticationType = AuthenticationType.Password;
                f.WindowSize = 0x1000;
                _objTmp = new Dictionary<TextBox, StringBuilder>();
                Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                //s.Blocking = false;
                s.Connect(new IPEndPoint(IPAddress.Parse(ip), _port));

                _conn = SSHConnection.Connect(f, this, s);

                this._conn = _conn;

                SSHChannel ch = _conn.OpenShell(this);
                this._pf = ch;
                _linePool = new List<string>();
                SSHConnectionInfo ci = _conn.ConnectionInfo;
            }
            catch (Exception e1)
            {
                SetText(_objTmp, form.consoleBox, e1.Message);
            }
        }
Esempio n. 11
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);
            }
        }