示例#1
0
        private static void receive_ChannelJoinConfirm()
        {
            int       num;
            int       num2   = 0;
            int       num3   = 0;
            RdpPacket packet = ISO.ReceiveTPKTOrFastPath(out num);

            num2 = packet.ReadByte();
            if ((num2 >> 2) != CJCF)
            {
                throw new RDFatalException("Bad CJCF " + num2);
            }
            num3 = packet.ReadByte();
            if (num3 != 0)
            {
                throw new RDFatalException("Bad CJRQ " + num3);
            }
            packet.Position += 4L;
            if ((num2 & 2) != 0)
            {
                packet.Position += 2L;
            }
            if (packet.Position != packet.Length)
            {
                throw new RDFatalException("Incorrect CJCF length");
            }
        }
示例#2
0
        private static int receive_AttachUserConfirm()
        {
            int       num;
            int       num2   = 0;
            int       num3   = 0;
            int       num4   = 0;
            RdpPacket packet = ISO.ReceiveTPKTOrFastPath(out num);

            num2 = packet.ReadByte();
            if ((num2 >> 2) != AUCF)
            {
                throw new RDFatalException("Bad AUCF " + num2);
            }
            num3 = packet.ReadByte();
            if (num3 != 0)
            {
                throw new RDFatalException("Bad AURQ got " + num3);
            }
            if ((num2 & 2) != 0)
            {
                num4 = packet.ReadBigEndian16();
            }
            if (packet.Position != packet.Length)
            {
                throw new RDFatalException("Illegal Aucf packet length");
            }
            return(num4);
        }
示例#3
0
        internal static RdpPacket Receive()
        {
            byte[] buffer = new byte[0x3000];

            int       count  = Network.Receive(buffer);
            RdpPacket packet = new RdpPacket();

            packet.Write(buffer, 0, count);
            packet.Position = 0L;
            int num2 = 0;

            if (packet.ReadByte() == 3)
            {
                packet.ReadByte();
                num2 = packet.ReadBigEndian16();
                long position = packet.Position;
                while (num2 > count)
                {
                    int num4 = Network.Receive(buffer);
                    packet.Position = count;
                    packet.Write(buffer, 0, num4);
                    count += num4;
                }
                packet.Position = position;
                return(packet);
            }
            num2 = packet.ReadByte();
            if ((num2 & 0x80) != 0)
            {
                num2 &= -129;
                num2  = num2 << (8 + packet.ReadByte());
            }
            return(packet);
        }
示例#4
0
        private static int berParseHeader(RdpPacket data, BER_Header eTagVal)
        {
            int num  = 0;
            int num2 = 0;
            int num3 = 0;
            int num4 = (int)eTagVal;

            if (num4 > 0xff)
            {
                num = data.ReadBigEndian16();
            }
            else
            {
                num = data.ReadByte();
            }
            if (num != num4)
            {
                throw new RDFatalException("Bad tag " + num.ToString() + " but need " + eTagVal.ToString());
            }
            num3 = data.ReadByte();
            if (num3 <= 0x80)
            {
                return(num3);
            }
            num3 -= 0x80;
            num2  = 0;
            while (num3-- != 0)
            {
                num2 = (num2 << 8) + data.ReadByte();
            }
            return(num2);
        }
示例#5
0
        private static void receiveConnectResponse()
        {
            string[]  strArray = new string[] { "Successful", "Domain Merging", "Domain not Hierarchical", "No Such Channel", "No Such Domain", "No Such User", "Not Admitted", "Other User ID", "Parameters Unacceptable", "Token Not Available", "Token Not Possessed", "Too Many Channels", "Too Many Tokens", "Too Many Users", "Unspecified Failure", "User Rejected" };
            RdpPacket data     = ISO.Receive();

            data.ReadByte();
            int num = data.ReadByte();

            if (num != 240)
            {
                throw new RDFatalException("Bad connection response packet type " + num.ToString());
            }
            data.ReadByte();
            int index = 0;

            index = berParseHeader(data, BER_Header.CONNECT_RESPONSE);
            index = berParseHeader(data, BER_Header.BER_TAG_RESULT);
            index = data.ReadByte();

            if (index != 0)
            {
                throw new RDFatalException("MCS failed " + strArray[index].ToString());
            }
            index = berParseHeader(data, BER_Header.BER_TAG_INTEGER);
            index = data.ReadByte();
            parseDomainParams(data);
            index = berParseHeader(data, BER_Header.BER_TAG_OCTET_STRING);
            processMcsData(data);
        }
示例#6
0
        protected static int ReadInteger(RdpPacket packet)
        {
            if (packet.ReadByte() != 2)
            {
                throw new Exception("Data Error!");
            }
            int num2 = packet.ReadByte();

            byte[] buffer = new byte[4];
            switch (num2)
            {
            case 4:
                packet.Read(buffer, 0, 4);
                return(BitConverter.ToInt32(buffer, 0));

            case 3:
                packet.Read(buffer, 0, 3);
                return(BitConverter.ToInt32(buffer, 0));

            case 2:
                packet.Read(buffer, 0, 2);
                return(BitConverter.ToInt32(buffer, 0));
            }
            packet.Read(buffer, 0, 1);
            return(BitConverter.ToInt32(buffer, 0));
        }
示例#7
0
        internal static RdpPacket ReceiveTPKTOrFastPath(out int type)
        {
            int       num  = 0;
            int       num2 = 0;
            RdpPacket p    = Tcp_Receive(null, 4);

            p.Position = 0L;
            if (p.Length == 0L)
            {
                type = -1;
                return(null);
            }
            num2 = p.ReadByte();
            if (num2 == 3)
            {
                p.ReadByte();
                num  = p.ReadBigEndian16();
                type = 0;
            }
            else
            {
                num = p.ReadByte();
                if ((num & 0x80) != 0)
                {
                    num &= -129;
                    num  = (num << 8) + p.ReadByte();
                }
                FastPath_EncryptionFlags flags = (FastPath_EncryptionFlags)(num2 >> 6);
                if ((flags & FastPath_EncryptionFlags.FASTPATH_OUTPUT_ENCRYPTED) != ((FastPath_EncryptionFlags)0))
                {
                    type = 0xfe;
                }
                else
                {
                    type = 0xff;
                }
            }
            long position = p.Position;

            p.Position = 4L;
            p          = Tcp_Receive(p, num - 4);
            p.Position = position;
            if ((type != 0xff) && (type != 0xfe))
            {
                p.Position = 4L;
                p.ReadByte();
                type = p.ReadByte();
                if (type == 240)
                {
                    p.ReadByte();
                    return(p);
                }
                p.ReadBigEndian16();
                p.ReadBigEndian16();
                p.ReadByte();
            }
            return(p);
        }
示例#8
0
        protected static int ReadTag(RdpPacket packet, string Identifier)
        {
            int num = packet.ReadByte();

            ReadLength(packet, Identifier);
            return(num);
        }
示例#9
0
        private static int receiveConnectNegotiation()
        {
            RdpPacket packet = ISO.Receive();

            //Print(packet);
            //System.Windows.Forms.MessageBox.Show("Test");

            packet.Position += 7L;
            if (packet.Position >= packet.Length)
            {
                return(0);
            }
            switch (packet.ReadByte())
            {
            case 2:
                RDPClient.serverNegotiateFlags = (NegotiationFlags)packet.ReadByte();
                packet.getLittleEndian16();
                return(packet.getLittleEndian32());

            case 3:
                packet.ReadByte();
                packet.getLittleEndian16();
                switch (packet.getLittleEndian32())
                {
                case 1:
                    throw new RDFatalException("The server requires that the client support Enhanced RDP Security with TLS 1.0");

                case 2:
                    return(0x10000000);

                case 3:
                    throw new RDFatalException("The server does not possess a valid authentication certificate and cannot initialize the External Security Protocol Provider");

                case 4:
                    throw new RDFatalException("The list of requested security protocols is not consistent with the current security protocol in effect.");

                case 5:
                    throw new RDFatalException("The server requires that the client support Enhanced RDP Security with CredSSP");

                case 6:
                    throw new RDFatalException("The server requires that the client support Enhanced RDP Security and certificate-based client authentication");
                }
                throw new RDFatalException("Unknown Negotiation failure!");
            }

            throw new RDFatalException("Negotiation failed, requested security level not supported by server.");
        }
示例#10
0
        protected static int ReadTag(RdpPacket packet, int ExpectedTag, string Identifier)
        {
            int num = packet.ReadByte();

            if (num != ExpectedTag)
            {
                throw new Exception(string.Concat(new object[] { "Expected DER tag ", ExpectedTag, " but got ", num }));
            }
            return(ReadLength(packet, Identifier));
        }
示例#11
0
        private static void processMcsData(RdpPacket mcs_data)
        {
            int num  = 0;
            int num2 = 0;
            int num3 = 0;

            mcs_data.Position += 0x15L;
            if ((mcs_data.ReadByte() & 0x80) != 0)
            {
                mcs_data.ReadByte();
            }
            while (mcs_data.Position < mcs_data.Length)
            {
                num  = mcs_data.getLittleEndian16();
                num2 = mcs_data.getLittleEndian16();
                if (num2 <= 4)
                {
                    return;
                }
                num3 = (int)((mcs_data.Position + num2) - 4L);
                switch (((SRV)num))
                {
                case SRV.SEC_TAG_SRV_INFO:
                    processSrvInfo(mcs_data);
                    break;

                case SRV.SEC_TAG_SRV_CRYPT:
                    Secure.processCryptInfo(mcs_data);
                    break;

                case SRV.SEC_TAG_SRV_3:
                    break;

                case SRV.SEC_TAG_SRV_MSG_CHANNEL:
                    Channels.RegisteredChannels.Add(new NetworkCharacteristicsDetection(mcs_data.getLittleEndian16()));
                    break;

                default:
                    throw new RDFatalException("MSC data incorrect tag " + num.ToString());
                }
                mcs_data.Position = num3;
            }
        }
示例#12
0
        internal static RdpPacket ReceiveMCS(out int channel, out int type)
        {
            int       num    = 0;
            int       num2   = 0;
            RdpPacket packet = ReceiveTPKTOrFastPath(out type);

            if ((type == 0xff) || (type == 0xfe))
            {
                channel = MCS.MSC_GLOBAL_CHANNEL;
                return(packet);
            }
            if (type != 240)
            {
                throw new RDFatalException("Illegal data type " + ((int)type).ToString());
            }
            if (packet == null)
            {
                channel = -1;
                return(null);
            }
            num  = packet.ReadByte();
            num2 = num >> 2;
            if (num2 != MCS.SDIN)
            {
                if (num2 != MCS.DPUM)
                {
                    throw new RDFatalException("Illegal data opcode " + num.ToString());
                }
                throw new EndOfTransmissionException("End of transmission!");
            }
            packet.Position += 2L;
            channel          = packet.ReadBigEndian16();
            packet.ReadByte();
            if ((packet.ReadByte() & 0x80) != 0)
            {
                packet.Position += 1L;
            }
            return(packet);
        }
示例#13
0
        internal static void process(RdpPacket data)
        {
            int num = 0;

            num = data.ReadByte();
            data.ReadByte();
            data.getLittleEndian16();

            switch (num)
            {
            case 1:
                process_demand(data);
                return;

            case 2:
                process_authreq(data);
                return;

            case 3:
                process_issue(data);
                RDPClient.m_bLicensed = true;
                return;

            case 4:
                RDPClient.m_bLicensed = true;
                return;

            case 0xff:
                data.getLittleEndian32();
                data.getLittleEndian32();
                data.getLittleEndian16();
                data.getLittleEndian16();
                RDPClient.m_bLicensed = true;
                return;
            }
        }
示例#14
0
        // Вспомогательные методы
        internal static void Print(RdpPacket data)
        {
            data.Position = 0L;

            int count = 0;

            for (int i = 0; i < data.Length; i++)
            {
                if (count == 16)
                {
                    count = 0;

                    System.Diagnostics.Trace.Write(string.Format("0x{0:X02}", (short)data.ReadByte()).ToLower() + "\r\n");
                }
                else
                {
                    System.Diagnostics.Trace.Write(string.Format("0x{0:X02}", (short)data.ReadByte()).ToLower() + " ");
                }

                count++;
            }

            System.Diagnostics.Trace.Write("\r\n\r\n");
        }
示例#15
0
        protected static int ReadLength(RdpPacket packet, string Identifier)
        {
            int num;

            byte[] buffer = new byte[4];
            int    num2   = packet.ReadByte();

            switch (num2)
            {
            case 0x84:
                buffer[3] = (byte)packet.ReadByte();
                buffer[2] = (byte)packet.ReadByte();
                buffer[1] = (byte)packet.ReadByte();
                buffer[0] = (byte)packet.ReadByte();
                num       = BitConverter.ToInt32(buffer, 0);
                break;

            case 0x83:
                buffer[2] = (byte)packet.ReadByte();
                buffer[1] = (byte)packet.ReadByte();
                buffer[0] = (byte)packet.ReadByte();
                num       = BitConverter.ToInt32(buffer, 0);
                break;

            case 130:
                buffer[1] = (byte)packet.ReadByte();
                buffer[0] = (byte)packet.ReadByte();
                num       = BitConverter.ToInt32(buffer, 0);
                break;

            case 0x81:
                num = packet.ReadByte();
                break;

            default:
                num = num2;
                break;
            }
            RDPClient.m_Fixup.Add(Identifier, new Fixup(Identifier, packet.Position, num));
            return(num);
        }
示例#16
0
        internal static void processServerCapabilities(RdpPacket data, int numCaps)
        {
            RDPClient.m_bServerSupportsCacheV2 = false;
            while (numCaps-- > 0)
            {
                int num  = data.getLittleEndian16();
                int num2 = data.getLittleEndian16();

                switch (num)
                {
                case 1:
                {
                    // RDP_CAPSET_GENERAL
                    data.getLittleEndian16();     // osMajorType
                    num2 -= 2;
                    data.getLittleEndian16();     // osMinorType
                    num2 -= 2;
                    data.getLittleEndian16();
                    num2 -= 2;
                    data.getLittleEndian16();
                    num2 -= 2;
                    data.getLittleEndian16();
                    num2 -= 2;
                    data.getLittleEndian16();
                    num2 -= 2;
                    data.getLittleEndian16();
                    num2 -= 2;
                    data.getLittleEndian16();
                    num2 -= 2;
                    data.getLittleEndian16();
                    num2 -= 2;
                    data.ReadByte();
                    num2--;
                    int num3 = data.ReadByte();
                    num2--;
                    RDPClient.suppress_output_supported = num3 > 0;
                    break;
                }

                case 2:
                    // RDP_CAPSET_BITMAP
                    data.getLittleEndian16();
                    num2 -= 2;
                    data.getLittleEndian16();
                    num2 -= 2;
                    data.getLittleEndian16();
                    num2 -= 2;
                    data.getLittleEndian16();
                    num2 -= 2;
                    data.getLittleEndian16();
                    num2 -= 2;
                    data.getLittleEndian16();
                    num2 -= 2;
                    break;

                case 3:
                    // RDP_CAPSET_ORDER
                    break;

                case 4:
                    // RDP_CAPSET_BMPCACHE
                    break;

                case 5:
                    // RDP_CAPSET_CONTROL
                    break;

                case 8:
                    // RDP_CAPSET_POINTER
                    break;

                case 9:
                    // RDP_CAPSET_SHARE
                    break;

                case 10:
                    // RDP_CAPSET_COLCACHE
                    break;

                case 13:
                {
                    // RDP_CAPSET_INPUT
                    int num4 = data.getLittleEndian16();
                    num2 -= 2;
                    RDPClient.use_fastpath_input = false;
                    if ((num4 & 0x20) != 0)
                    {
                        RDPClient.use_fastpath_input = true;
                    }
                    if ((num4 & 8) != 0)
                    {
                        RDPClient.use_fastpath_input = true;
                    }
                    break;
                }

                case 14:
                    // RDP_CAPSET_FONT
                    break;

                case 0x12:
                    // RDP_CAPSET_BMPCACHE_HOSTSUPPORT
                    RDPClient.m_bServerSupportsCacheV2 = true;
                    break;

                case 20:
                    // RDP_CAPSET_VIRTUALCHANNEL
                    break;

                case 0x19:
                    // RDP_CAPSET_COMPDESK
                    break;

                case 0x1a:
                    // RDP_CAPSET_MULTIFRAGMENTUPDATE
                    break;

                case 0x1b:
                    // RDP_CAPSET_LARGE_POINTER
                    break;

                case 0x1c:
                    // RDP_CAPSET_SURFACE_COMMANDS
                    break;

                case 0x1d:
                    // RDP_CAPSET_BITMAP_CODECS
                    break;

                default:
                    // RDP_CAPSET unknown
                    break;
                }
                data.Position += num2 - 4;
            }
        }
示例#17
0
        private static bool processData(RdpPacket data)
        {
            int num3;
            int num = 0;

            data.Position += 6L;
            data.getLittleEndian16();
            num = data.ReadByte();
            data.ReadByte();
            data.getLittleEndian16();

            switch (num)
            {
            case 0x26:     // 38
                // RDP_DATA_PDU_SAVE_SESSION_INFO
                processLogonInfo(data);
                goto Label_015E;

            case 0x2f:     // 47
                // RDP_DATA_PDU_SET_ERROR_INFO
                num3 = data.getLittleEndian32();

                switch (num3)
                {
                case 0:
                case 12:
                    goto Label_015E;

                case 1:
                    throw new RDFatalException("The disconnection was initiated by an administrative tool on the server in another session.");

                case 2:
                    throw new RDFatalException("The disconnection was due to a forced logoff initiated by an administrative tool on the server in another session.");

                case 3:
                    throw new RDFatalException("The idle session limit timer on the server has elapsed.");

                case 4:
                    throw new RDFatalException("The active session limit timer on the server has elapsed.");

                case 5:
                    throw new RDFatalException("Another user connected to the server, forcing the disconnection of the current connection.");

                case 7:
                    throw new RDFatalException("The server denied the connection.");

                case 9:
                    throw new RDFatalException("The user cannot connect to the server due to insufficient access privileges.");

                case 11:
                    throw new RDFatalException("The disconnection was initiated by an administrative tool on the server running in the user's session.");

                case 0x102:
                    throw new RDFatalException("There are no Client Access Licenses available for the target remote computer, please contact your network administrator.");
                }
                break;

            case 2:
                // processUpdate
                return(false);

            case 0x1b:     // 27
                return(false);

            default:
                goto Label_015E;
            }
            throw new RDFatalException("Error code: " + num3.ToString("X8") + ", please contact Support with this error code");

Label_015E:
            return(false);
        }