Example #1
0
        public void Authenticate(string username, string password)
        {
            PacketGeneral packet_auth = new PacketGeneral(Packet.SSH_MSG_USERAUTH_REQUEST);
            packet_auth.GetStreamWriter().WriteString("ssh-userauth");
            SendPacket(crypto_encryptor, packet_auth);
            Packet packet = RecvPacket(crypto_decryptor);
            if (packet.Message == Packet.SSH_MSG_SERVICE_ACCEPT)
            {
                Console.WriteLine("SSH_MSG_SERVICE_ACCEPT");
            }

            packet_auth = new PacketGeneral(50);
            NetworkByteWriter nbw_cache = packet_auth.GetStreamWriter();
            //SSH_MSG_USERAUTH_REQUEST
            nbw_cache.WriteString(username);
            nbw_cache.WriteString("ssh-connection");
            nbw_cache.WriteString("password");
            nbw_cache.WriteByte((byte)0);
            nbw_cache.WriteString(password);

            SendPacket(crypto_encryptor, packet_auth);

            packet = RecvPacket(crypto_decryptor);

            if (Packet.SSH_MSG_USERAUTH_SUCCESS == packet.Message)
            {
                Console.WriteLine("oh ya!");
            }
        }
Example #2
0
        public void Authenticate(string username, string password)
        {
            PacketGeneral packet_auth = new PacketGeneral(Packet.SSH_MSG_USERAUTH_REQUEST);

            packet_auth.GetStreamWriter().WriteString("ssh-userauth");
            SendPacket(crypto_encryptor, packet_auth);
            Packet packet = RecvPacket(crypto_decryptor);

            if (packet.Message == Packet.SSH_MSG_SERVICE_ACCEPT)
            {
                Console.WriteLine("SSH_MSG_SERVICE_ACCEPT");
            }

            packet_auth = new PacketGeneral(50);
            NetworkByteWriter nbw_cache = packet_auth.GetStreamWriter();

            //SSH_MSG_USERAUTH_REQUEST
            nbw_cache.WriteString(username);
            nbw_cache.WriteString("ssh-connection");
            nbw_cache.WriteString("password");
            nbw_cache.WriteByte((byte)0);
            nbw_cache.WriteString(password);

            SendPacket(crypto_encryptor, packet_auth);

            packet = RecvPacket(crypto_decryptor);

            if (Packet.SSH_MSG_USERAUTH_SUCCESS == packet.Message)
            {
                Console.WriteLine("oh ya!");
            }
        }
Example #3
0
        public void KeyExchange(string algorithm)
        {
            DiffieHellman dh = new DiffieHellman(2);
            BigInteger    e  = dh.GenerateExchangeValue();

            verify_e = e;
            PacketGeneral packet_dhkex = new PacketGeneral(Packet.SSH_MSG_KEXDH_INIT);

            packet_dhkex.GetStreamWriter().WriteMPInt(e);
            SendPacket(null, packet_dhkex);

            Packet packet = RecvPacket(null);

            PacketKeyExchangeDHReply packet_dhkex_reply = new PacketKeyExchangeDHReply(packet);

            packet_dhkex_reply.Parse();
            verify_k_s = packet_dhkex_reply.GetCertificates();
            verify_sig = packet_dhkex_reply.GetSignature();
            BigInteger f = packet_dhkex_reply.GetExchangeValue();

            verify_f = f;
            BigInteger K = dh.ComputeKey(f);

            verify_k = K;
        }
Example #4
0
        public void OpenChannel(VideoTerminal x)
        {
            PacketGeneral packet_openchannel = new PacketGeneral(90);
            NetworkByteWriter nbw = packet_openchannel.GetStreamWriter();
            nbw.WriteString("session");
            nbw.WriteUInt32(0);
            nbw.WriteUInt32(1048576);
            nbw.WriteUInt32(16384);

            SendPacket(crypto_encryptor, packet_openchannel);

            Packet packet = RecvPacket(crypto_decryptor);
            NetworkByteReader nbr = packet.GenerateReader();

            nbr.ReadByte();
            uint recipient_channel = nbr.ReadUInt32();

            uint sender_channel = nbr.ReadUInt32();
            uint initial_window_size = nbr.ReadUInt32();
            uint maximum_packet_size = nbr.ReadUInt32();

            PacketGeneral packet_pty = new PacketGeneral(Packet.SSH_MSG_CHANNEL_REQUEST);
            nbw = packet_pty.GetStreamWriter();
            nbw.WriteUInt32(recipient_channel);
            nbw.WriteString("pty-req");
            nbw.WriteByte(0);
            nbw.WriteString("vt100");
            nbw.WriteUInt32(80);
            nbw.WriteUInt32(24);
            nbw.WriteUInt32(640);
            nbw.WriteUInt32(480);
            nbw.WriteString("");
            SendPacket(crypto_encryptor, packet_pty);

            PacketGeneral packet_shell = new PacketGeneral(Packet.SSH_MSG_CHANNEL_REQUEST);
            nbw = packet_shell.GetStreamWriter();
            nbw.WriteUInt32(recipient_channel);
            nbw.WriteString("shell");
            nbw.WriteByte(0);
            SendPacket(crypto_encryptor, packet_shell);

            while (true)
            {

                if (RecvAvailable())
                {
                    packet = RecvPacket(crypto_decryptor);
                    switch (packet.Message)
                    {
                        case Packet.SSH_MSG_CHANNEL_WINDOW_ADJUST:
                            break;
                        case Packet.SSH_MSG_CHANNEL_DATA:
                            PacketChannelData p = new PacketChannelData(packet);
                            p.Parse();
                            x.HandleServerData(p.data);
                            break;
                        default:
                            break;
                    }
                }
                else
                {
                    string data = x.GetClientData();
                    if (data.Length!= 0) {
                        PacketGeneral packet_key = new PacketGeneral(Packet.SSH_MSG_CHANNEL_DATA);
                        nbw = packet_key.GetStreamWriter();
                        nbw.WriteUInt32(recipient_channel);
                        nbw.WriteString(data);
                        SendPacket(crypto_encryptor, packet_key);
                    }
                }
            }
        }
Example #5
0
        public void KeyExchange(string algorithm)
        {
            DiffieHellman dh = new DiffieHellman(2);
            BigInteger e = dh.GenerateExchangeValue();
            verify_e = e;
            PacketGeneral packet_dhkex = new PacketGeneral(Packet.SSH_MSG_KEXDH_INIT);
            packet_dhkex.GetStreamWriter().WriteMPInt(e);
            SendPacket(null, packet_dhkex);

            Packet packet = RecvPacket(null);

            PacketKeyExchangeDHReply packet_dhkex_reply = new PacketKeyExchangeDHReply(packet);
            packet_dhkex_reply.Parse();
            verify_k_s = packet_dhkex_reply.GetCertificates();
            verify_sig = packet_dhkex_reply.GetSignature();
            BigInteger f = packet_dhkex_reply.GetExchangeValue();
            verify_f = f;
            BigInteger K = dh.ComputeKey(f);
            verify_k = K;
        }
Example #6
0
        public void OpenChannel(VideoTerminal x)
        {
            PacketGeneral     packet_openchannel = new PacketGeneral(90);
            NetworkByteWriter nbw = packet_openchannel.GetStreamWriter();

            nbw.WriteString("session");
            nbw.WriteUInt32(0);
            nbw.WriteUInt32(1048576);
            nbw.WriteUInt32(16384);

            SendPacket(crypto_encryptor, packet_openchannel);

            Packet            packet = RecvPacket(crypto_decryptor);
            NetworkByteReader nbr    = packet.GenerateReader();

            nbr.ReadByte();
            uint recipient_channel = nbr.ReadUInt32();

            uint sender_channel      = nbr.ReadUInt32();
            uint initial_window_size = nbr.ReadUInt32();
            uint maximum_packet_size = nbr.ReadUInt32();


            PacketGeneral packet_pty = new PacketGeneral(Packet.SSH_MSG_CHANNEL_REQUEST);

            nbw = packet_pty.GetStreamWriter();
            nbw.WriteUInt32(recipient_channel);
            nbw.WriteString("pty-req");
            nbw.WriteByte(0);
            nbw.WriteString("vt100");
            nbw.WriteUInt32(80);
            nbw.WriteUInt32(24);
            nbw.WriteUInt32(640);
            nbw.WriteUInt32(480);
            nbw.WriteString("");
            SendPacket(crypto_encryptor, packet_pty);

            PacketGeneral packet_shell = new PacketGeneral(Packet.SSH_MSG_CHANNEL_REQUEST);

            nbw = packet_shell.GetStreamWriter();
            nbw.WriteUInt32(recipient_channel);
            nbw.WriteString("shell");
            nbw.WriteByte(0);
            SendPacket(crypto_encryptor, packet_shell);


            while (true)
            {
                if (RecvAvailable())
                {
                    packet = RecvPacket(crypto_decryptor);
                    switch (packet.Message)
                    {
                    case Packet.SSH_MSG_CHANNEL_WINDOW_ADJUST:
                        break;

                    case Packet.SSH_MSG_CHANNEL_DATA:
                        PacketChannelData p = new PacketChannelData(packet);
                        p.Parse();
                        x.HandleServerData(p.data);
                        break;

                    default:
                        break;
                    }
                }
                else
                {
                    string data = x.GetClientData();
                    if (data.Length != 0)
                    {
                        PacketGeneral packet_key = new PacketGeneral(Packet.SSH_MSG_CHANNEL_DATA);
                        nbw = packet_key.GetStreamWriter();
                        nbw.WriteUInt32(recipient_channel);
                        nbw.WriteString(data);
                        SendPacket(crypto_encryptor, packet_key);
                    }
                }
            }
        }