Beispiel #1
0
        /// <summary>
        /// Client MCS Erect Domain Request PDU
        /// </summary>
        private static void send_ErectDomainRequest()
        {
            RdpPacket data = new RdpPacket();

            data.WriteByte((byte)(EDRQ << 2));
            data.WriteBigEndian16((short)1);
            data.WriteBigEndian16((short)1);
            IsoLayer.SendTPKT(data);
        }
Beispiel #2
0
        /// <summary>
        /// Client MCS Channel Join Request PDU
        /// </summary>
        private static void send_ChannelJoinRequest(int channelId)
        {
            RdpPacket data = new RdpPacket();

            data.WriteByte((byte)(CJRQ << 2));
            data.WriteBigEndian16((short)McsUserID);
            data.WriteBigEndian16((short)channelId);
            IsoLayer.SendTPKT(data);
        }
Beispiel #3
0
        internal static void SendMCS(RdpPacket packet, int channel)
        {
            int       length = (int)(packet.Length | 0x8000);
            RdpPacket data   = new RdpPacket();

            data.WriteByte((byte)(MCS.SDRQ << 2));
            data.WriteBigEndian16((short)MCS.McsUserID);
            data.WriteBigEndian16((short)channel);
            data.WriteByte(0x70);
            data.WriteBigEndian16((short)length);
            data.copyToByteArray(packet);

            SendTPKT(data);
        }
Beispiel #4
0
        /// <summary>
        /// Client X.224 Connection Request PDU
        /// </summary>
        private static void sendConnectNegotiation(NegotiationProtocol NegotiationFlags, byte[] loadBalanceToken)
        {
            string domainAndUsername = Options.DomainAndUsername;

            if (domainAndUsername.Length > 9)
            {
                domainAndUsername = domainAndUsername.Substring(0, 9);
            }

            RdpPacket packet = new RdpPacket();

            packet.WriteByte(3);
            packet.WriteByte(0);
            long position = packet.Position;

            packet.WriteBigEndian16((short)0);
            packet.WriteByte(0);
            packet.WriteByte(0xe0);
            packet.WriteBigEndian16((short)0);
            packet.WriteBigEndian16((short)0);
            packet.WriteByte(0);

            if (loadBalanceToken != null)
            {
                packet.Write(loadBalanceToken, 0, loadBalanceToken.Length);
                packet.WriteString("\r\n", false);
            }
            else
            {
                packet.WriteString("Cookie: mstshash=" + domainAndUsername + "\r\n", true);
            }

            // RDP Negotiation Request
            packet.WriteByte(0x01);
            packet.WriteByte(0);
            packet.WriteLittleEndian16((short)8);
            packet.WriteLittleEndian32((int)NegotiationFlags); // Standard RDP Security, TLS 1.0, CredSSP

            long num2 = packet.Position;

            packet.Position = position;
            packet.WriteBigEndian16((short)num2);
            packet.WriteByte((byte)(num2 - 5L));

            IsoLayer.Write(packet);
        }
Beispiel #5
0
        public static void SendMessage(int type)
        {
            short num = 0x12;

            byte[]    buffer = new byte[11];
            RdpPacket packet = new RdpPacket();

            packet.WriteByte(3);
            packet.WriteByte(0);
            packet.WriteBigEndian16(num);
            packet.WriteByte(6);
            packet.WriteByte((byte)type);
            packet.WriteByte(0x80);
            packet.WriteBigEndian16((short)0);
            packet.WriteBigEndian16((short)0);
            packet.WriteByte(0);
            packet.Write(buffer, 0, buffer.Length);

            Write(packet);
        }
Beispiel #6
0
        internal static void sendBerHeader(RdpPacket data, BER_Header berHeader, int param)
        {
            int num = (int)berHeader;

            if (num > 0xff)
            {
                data.WriteBigEndian16((short)num);
            }
            else
            {
                data.WriteByte((byte)num);
            }
            if (param >= 0x80)
            {
                data.WriteByte(130);
                data.WriteBigEndian16((short)param);
            }
            else
            {
                data.WriteByte((byte)param);
            }
        }
Beispiel #7
0
        public static void SendTPKT(RdpPacket data)
        {
            short num = (short)(data.Length + 7L);

            data.Position = 0L;
            RdpPacket packet = new RdpPacket();

            packet.WriteByte(3);
            packet.WriteByte(0);
            packet.WriteBigEndian16(num);
            packet.WriteByte(2);
            packet.WriteByte((byte)Main.SecureValue8);
            packet.WriteByte(0x80);
            packet.copyToByteArray(data);
            Write(packet);
        }
Beispiel #8
0
        internal static void sendBerInteger(RdpPacket buffer, int value)
        {
            int num = 1;

            if (value > 0xff)
            {
                num = 2;
            }

            sendBerHeader(buffer, BER_Header.BER_TAG_INTEGER, num);

            if (value > 0xff)
            {
                buffer.WriteBigEndian16((short)value);
            }
            else
            {
                buffer.WriteByte((byte)value);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Client MCS Connect Initial PDU
        /// Part 2
        ///
        /// Create packet
        /// </summary>
        internal static RdpPacket sendMcsData(bool useRdp5, int num_channels, int serverSelectedProtocol)
        {
            RdpPacket packet = new RdpPacket();

            // Проверка длины Client Name
            string clientName = Options.ClientName;

            if (clientName.Length > 15)
            {
                clientName = clientName.Substring(0, 15);
            }

            int num  = 2 * clientName.Length;
            int num2 = 0x9e;

            if (useRdp5)
            {
                num2 += 0x60;
            }

            if (useRdp5 && (num_channels > 0))
            {
                num2 += (num_channels * 12) + 8;
            }

            if (Options.serverNegotiateFlags.HasFlag(NegotiationFlags.EXTENDED_CLIENT_DATA_SUPPORTED))
            {
                num2 += 8;
            }

            packet.WriteBigEndian16((short)5);
            packet.WriteBigEndian16((short)20);
            packet.WriteByte(0x7c);
            packet.WriteBigEndian16((short)1);
            packet.WriteBigEndian16((short)(num2 | 0x8000));
            packet.WriteBigEndian16((short)8);
            packet.WriteBigEndian16((short)0x10);
            packet.WriteByte(0);
            packet.WriteLittleEndian16((ushort)0xc001);
            packet.WriteByte(0);
            packet.WriteLittleEndian32(0x61637544);
            packet.WriteBigEndian16((short)((num2 - 14) | 0x8000));

            // Client Core Data (TS_UD_CS_CORE)
            packet.WriteLittleEndian16((ushort)CLIENT.CS_CORE);
            packet.WriteLittleEndian16(useRdp5 ? ((short)0xd8) : ((short)0x88));
            packet.WriteLittleEndian16(useRdp5 ? ((short)4) : ((short)1));
            packet.WriteLittleEndian16((short)8);
            packet.WriteLittleEndian16((short)Options.width);  // Width
            packet.WriteLittleEndian16((short)Options.height); // Height
            packet.WriteLittleEndian16((ushort)0xca01);
            packet.WriteLittleEndian16((ushort)0xaa03);
            packet.WriteLittleEndian32(Options.Keyboard);        // Клавиатура
            packet.WriteLittleEndian32(useRdp5 ? 0xa28 : 0x1a3); // Client Build
            packet.WriteUnicodeString(clientName);               // Client Name
            packet.Position += 30 - num;
            packet.WriteLittleEndian32(0x00000004);              // IBM enhanced (101- or 102-key) keyboard
            packet.WriteLittleEndian32(0);
            packet.WriteLittleEndian32(12);                      // Функциональные клавиши (F1-F12)
            packet.Position += 0x40L;
            packet.WriteLittleEndian16((ushort)0xCA01);          // NS_UD_COLOR_8BPP
            packet.WriteLittleEndian16(useRdp5 ? ((short)1) : ((short)0));

            if (useRdp5)
            {
                packet.WriteLittleEndian32(0);
                packet.WriteLittleEndian16((short)((byte)Options.server_bpp));
                packet.WriteLittleEndian16((short)7);
                packet.WriteLittleEndian16((short)1);
                packet.Position += 0x40L;
                packet.WriteByte(0);
                packet.WriteByte(0);
                packet.WriteLittleEndian32(serverSelectedProtocol);

                // Client Cluster Data (TS_UD_CS_CLUSTER)
                packet.WriteLittleEndian16((ushort)CLIENT.CS_CLUSTER);
                packet.WriteLittleEndian16((short)12);
                int num3 = 13;

                if (Options.flags.HasFlag(HostFlags.ConsoleSession) || (Options.sessionID != 0))
                {
                    num3 |= 2;
                }

                packet.WriteLittleEndian32(num3);
                packet.WriteLittleEndian32(Options.sessionID);
            }

            // Client Security Data (TS_UD_CS_SEC)
            packet.WriteLittleEndian16((ushort)CLIENT.CS_SECURITY);
            packet.WriteLittleEndian16(useRdp5 ? ((short)12) : ((short)8));

            int num4 = 0;

            if (serverSelectedProtocol == 0)
            {
                num4 |= 3;
            }

            packet.WriteLittleEndian32(num4);

            if (useRdp5)
            {
                packet.WriteLittleEndian32(0);
            }

            // Client Network Data (TS_UD_CS_NET)
            if (useRdp5 && (num_channels > 0))
            {
                packet.WriteLittleEndian16((ushort)CLIENT.CS_NET);
                packet.WriteLittleEndian16((short)((num_channels * 12) + 8));
                packet.WriteLittleEndian32(num_channels);

                foreach (IVirtualChannel channel in Channels.RegisteredChannels)
                {
                    Debug.WriteLine("Client Network Data. Channel name length: " + channel.ChannelName.Length);

                    packet.WriteString(channel.ChannelName, false);
                    packet.WriteBigEndian32((uint)(CHANNEL_DEF.CHANNEL_OPTION_INITIALIZED));
                }
            }

            // Client Message Channel Data (TS_UD_CS_MCS_MSGCHANNEL)
            if (Options.serverNegotiateFlags.HasFlag(NegotiationFlags.EXTENDED_CLIENT_DATA_SUPPORTED))
            {
                packet.WriteLittleEndian16((ushort)CLIENT.CS_MCS_MSGCHANNEL);
                packet.WriteLittleEndian16((short)8);
                packet.WriteLittleEndian32(0);
            }

            return(packet);
        }