Example #1
0
        public void DumpError(Packet packet)
        {
            MemoryStream      ms  = new MemoryStream(packet.GetPayload());
            NetworkByteReader nbr = new NetworkByteReader(ms);

            nbr.ReadByte();
            nbr.ReadUInt32();
            string xxx = nbr.ReadString();
        }
Example #2
0
        override public void Parse()
        {
            MemoryStream      ms  = new MemoryStream(payload);
            NetworkByteReader nbr = new NetworkByteReader(ms);

            nbr.ReadByte();
            nbr.ReadUInt32();
            data = nbr.ReadString();
            Console.Write(data);
        }
Example #3
0
        override public void Parse()
        {
            MemoryStream      ms  = new MemoryStream(payload);
            NetworkByteReader nbr = new NetworkByteReader(ms);

            nbr.ReadByte();
            cookie                                  = nbr.ReadBytes(16);
            kex_algorithms                          = nbr.ReadNameList();
            server_host_key_algorithms              = nbr.ReadNameList();
            encryption_algorithms_client_to_server  = nbr.ReadNameList();
            encryption_algorithms_server_to_client  = nbr.ReadNameList();
            mac_algorithms_client_to_server         = nbr.ReadNameList();
            mac_algorithms_server_to_client         = nbr.ReadNameList();
            compression_algorithms_client_to_server = nbr.ReadNameList();
            compression_algorithms_server_to_client = nbr.ReadNameList();
            languages_client_to_server              = nbr.ReadNameList();
            languages_server_to_client              = nbr.ReadNameList();
            first_kex_packet_follows                = nbr.ReadBoolean();
            reserved                                = nbr.ReadUInt32();
        }
Example #4
0
        public Packet RecvPacket(ICryptoTransform decryptor)
        {
            if (decryptor == null)
            {
                Packet packet = new Packet();
                uint packet_length = reader.ReadUInt32();
                byte padding_length = reader.ReadByte();
                byte[] payload = reader.ReadBytes(packet_length - padding_length - 1);
                byte[] padding = reader.ReadBytes(padding_length);
                packet.SetPayload(payload);
                return packet;
            }
            else
            {
                int blocksize = Math.Max(decryptor.InputBlockSize, 8);
                MemoryStream ms_packet = new MemoryStream();
                NetworkByteWriter writer_packet = new NetworkByteWriter(ms_packet);

                byte[] buffer = new byte[blocksize];

                bool first = true;
                int more = 0;
                while (true)
                {
                    // read a block
                    int ret = reader.ReadBytes(buffer, 0, blocksize);
                    // must be a real block size;
                    if (ret != blocksize) return null;
                    decryptor.TransformBlock(buffer, 0, buffer.Length, buffer, 0);
                    writer_packet.WriteBytes(buffer);

                    if (first) // it's first time, need parse packet_length and padding_length
                    {
                        NetworkByteReader reader_buffer = new NetworkByteReader(new MemoryStream(buffer));
                        uint packet_length_t = reader_buffer.ReadUInt32();
                        first = false;

                        more = (int)packet_length_t + 4 - blocksize;
                        if (more % blocksize != 0) return null;
                    }
                    else
                    {
                        more -= blocksize;
                    }
                    if (more <= 0) break;
                }

                byte[] mac = reader.ReadBytes(20);

                ms_packet.Seek(0, SeekOrigin.Begin);
                NetworkByteReader reader_packet = new NetworkByteReader(ms_packet);

                Packet packet = new Packet();
                uint packet_length = reader_packet.ReadUInt32();
                byte padding_length = reader_packet.ReadByte();
                byte[] payload = reader_packet.ReadBytes(packet_length - padding_length - 1);
                byte[] padding = reader_packet.ReadBytes(padding_length);
                packet.SetPayload(payload);

                return packet;
            }
        }
Example #5
0
 public void DumpError(Packet packet)
 {
     MemoryStream ms = new MemoryStream(packet.GetPayload());
     NetworkByteReader nbr = new NetworkByteReader(ms);
     nbr.ReadByte();
     nbr.ReadUInt32();
     string xxx = nbr.ReadString();
 }
Example #6
0
 public override void Parse()
 {
     MemoryStream ms = new MemoryStream(payload);
     NetworkByteReader nbr = new NetworkByteReader(ms);
     nbr.ReadByte();
     cookie = nbr.ReadBytes(16);
     kex_algorithms = nbr.ReadNameList();
     server_host_key_algorithms = nbr.ReadNameList();
     encryption_algorithms_client_to_server = nbr.ReadNameList();
     encryption_algorithms_server_to_client = nbr.ReadNameList();
     mac_algorithms_client_to_server = nbr.ReadNameList();
     mac_algorithms_server_to_client = nbr.ReadNameList();
     compression_algorithms_client_to_server = nbr.ReadNameList();
     compression_algorithms_server_to_client = nbr.ReadNameList();
     languages_client_to_server = nbr.ReadNameList();
     languages_server_to_client = nbr.ReadNameList();
     first_kex_packet_follows = nbr.ReadBoolean();
     reserved = nbr.ReadUInt32();
 }
Example #7
0
 public override void Parse()
 {
     MemoryStream ms = new MemoryStream(payload);
     NetworkByteReader nbr = new NetworkByteReader(ms);
     nbr.ReadByte();
     nbr.ReadUInt32();
     data = nbr.ReadString();
     Console.Write(data);
 }
Example #8
0
        public Packet RecvPacket(ICryptoTransform decryptor)
        {
            if (decryptor == null)
            {
                Packet packet         = new Packet();
                uint   packet_length  = reader.ReadUInt32();
                byte   padding_length = reader.ReadByte();
                byte[] payload        = reader.ReadBytes(packet_length - padding_length - 1);
                byte[] padding        = reader.ReadBytes(padding_length);
                packet.SetPayload(payload);
                return(packet);
            }
            else
            {
                int               blocksize     = Math.Max(decryptor.InputBlockSize, 8);
                MemoryStream      ms_packet     = new MemoryStream();
                NetworkByteWriter writer_packet = new NetworkByteWriter(ms_packet);

                byte[] buffer = new byte[blocksize];

                bool first = true;
                int  more  = 0;
                while (true)
                {
                    // read a block
                    int ret = reader.ReadBytes(buffer, 0, blocksize);
                    // must be a real block size;
                    if (ret != blocksize)
                    {
                        return(null);
                    }
                    decryptor.TransformBlock(buffer, 0, buffer.Length, buffer, 0);
                    writer_packet.WriteBytes(buffer);

                    if (first) // it's first time, need parse packet_length and padding_length
                    {
                        NetworkByteReader reader_buffer = new NetworkByteReader(new MemoryStream(buffer));
                        uint packet_length_t            = reader_buffer.ReadUInt32();
                        first = false;

                        more = (int)packet_length_t + 4 - blocksize;
                        if (more % blocksize != 0)
                        {
                            return(null);
                        }
                    }
                    else
                    {
                        more -= blocksize;
                    }
                    if (more <= 0)
                    {
                        break;
                    }
                }

                byte[] mac = reader.ReadBytes(20);


                ms_packet.Seek(0, SeekOrigin.Begin);
                NetworkByteReader reader_packet = new NetworkByteReader(ms_packet);

                Packet packet         = new Packet();
                uint   packet_length  = reader_packet.ReadUInt32();
                byte   padding_length = reader_packet.ReadByte();
                byte[] payload        = reader_packet.ReadBytes(packet_length - padding_length - 1);
                byte[] padding        = reader_packet.ReadBytes(padding_length);
                packet.SetPayload(payload);

                return(packet);
            }
        }
Example #9
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);
                    }
                }
            }
        }