Exemple #1
0
 private static void sendColorcacheCaps(RdpPacket data)
 {
     data.WriteLittleEndian16((short)10);
     data.WriteLittleEndian16((short)8);
     data.WriteLittleEndian16((short)6);
     data.WriteLittleEndian16((short)0);
 }
        internal void clientFormatList()
        {
            // Формируем строку, содержащую нулевой байт после каждого символа
            string tempStr = "";

            foreach (var ch in ClipboardFormatName)
            {
                tempStr += ch + "\0";
            }

            // Получаем байты строки
            var bytes = ASCIIEncoding.GetBytes(tempStr, false).ToList();

            RdpPacket packet = new RdpPacket();

            packet.WriteLittleEndian16((short)MsgType.CB_FORMAT_LIST);
            packet.WriteLittleEndian16((short)MsgFlags.NOT_SET);
            packet.WriteLittleEndian32(bytes.Count + 4 + FourButesAlignLen); // length

            // Устанавливаем Clipboard Format ID
            packet.WriteLittleEndian32(ClipboardFormatID);
            packet.Write(bytes.ToArray(), 0, bytes.Count);

            packet.WritePadding(FourButesAlign); // Add four bytes

            send(packet);
        }
        internal void clientClipboardCapabilities()
        {
            RdpPacket packet = new RdpPacket();

            packet.WriteLittleEndian16((short)MsgType.CB_CLIP_CAPS);
            packet.WriteLittleEndian16((short)MsgFlags.NOT_SET);
            packet.WriteLittleEndian32(16 + FourButesAlignLen); // length

            packet.WriteLittleEndian16(1);                      // Колл-во cCapabilitiesSets
            packet.WritePadding(2);                             // Padding 2

            packet.WriteLittleEndian16((short)CapsType.CB_CAPSTYPE_GENERAL);
            packet.WriteLittleEndian16(12); // lengthCapability
            packet.WriteLittleEndian32((int)CapsVersion.CB_CAPS_VERSION_2);

            if (ServerGeneralFlags.HasFlag(GeneralFlags.CB_STREAM_FILECLIP_ENABLED))
            {
                packet.WriteLittleEndian32((int)ServerGeneralFlags);
            }
            else
            {
                packet.WriteLittleEndian32((int)(GeneralFlags.CB_STREAM_FILECLIP_ENABLED | GeneralFlags.CB_USE_LONG_FORMAT_NAMES));
            }

            packet.WritePadding(FourButesAlign); // Add four bytes

            send(packet);
        }
Exemple #4
0
 private static void sendSoundCaps(RdpPacket packet)
 {
     packet.WriteLittleEndian16((short)12);
     packet.WriteLittleEndian16((short)8);
     packet.WriteLittleEndian16((short)0);
     packet.WriteLittleEndian16((short)0);
 }
        internal void clientFileContentsResponse()
        {
            // Вычисляем часть файла
            byte[] tempArr = null;
            if ((FileData.Length - Position) > 0)
            {
                if ((FileData.Length - Position) >= BufferNextPart)
                {
                    tempArr = new byte[BufferNextPart];
                    Array.Copy(FileData, Position, tempArr, 0, BufferNextPart);
                    Position += BufferNextPart;
                }
                else
                {
                    tempArr = new byte[(FileData.Length - Position)];
                    Array.Copy(FileData, Position, tempArr, 0, (FileData.Length - Position));
                    BufferNextPart = 0;
                    Position       = 0;
                }
            }
            else if ((FileData.Length - Position) == 0)
            {
                BufferNextPart = 0;
                Position       = 0;
                return;
            }

            // Формируем пакет
            RdpPacket packet = new RdpPacket();

            packet.WriteLittleEndian16((short)MsgType.CB_FILECONTENTS_RESPONSE);
            packet.WriteLittleEndian16((short)MsgFlags.CB_RESPONSE_OK);

            // Устанавливаем длину сообщения
            if (FileCanLoad)
            {
                packet.WriteLittleEndian32(tempArr.Length + 4); // length
            }
            else
            {
                packet.WriteLittleEndian32(8 + 4); // length
            }

            // Stream ID
            packet.WriteLittleEndian32(StreamID);

            // Устанавливаем размер или байты самого файла, в зависимости от значения FileCanLoad
            if (FileCanLoad && FileData != null)
            {
                // requestedFileContentsData
                packet.Write(tempArr, 0, tempArr.Length);
            }
            else
            {
                // requestedFileContentsData
                packet.WriteLittleEndianU64(FileSize);
            }

            send(packet);
        }
Exemple #6
0
 private static void sendFontCaps(RdpPacket packet)
 {
     packet.WriteLittleEndian16((short)14);
     packet.WriteLittleEndian16((short)8);
     packet.WriteLittleEndian16((short)1);
     packet.WriteLittleEndian16((short)0);
 }
Exemple #7
0
 private static void sendPointerCaps(RdpPacket packet)
 {
     packet.WriteLittleEndian16((short)8);
     packet.WriteLittleEndian16((short)10);
     packet.WriteLittleEndian16((short)1);
     packet.WriteLittleEndian16((short)20);
     packet.WriteLittleEndian16((short)0x15);
 }
Exemple #8
0
        private static void sendSynchronize()
        {
            RdpPacket packet = new RdpPacket();

            packet.WriteLittleEndian16((short)1);
            packet.WriteLittleEndian16((short)0x3ea);

            IsoLayer.SendPDU(packet, IsoLayer.PDUType2.PDUTYPE2_SYNCHRONIZE, Secure.RDPEncrypted() ? (int)(MCS.TS_SECURITY_HEADER.SEC_ENCRYPT) : 0);
        }
Exemple #9
0
        private static void sendFontList()
        {
            RdpPacket packet = new RdpPacket();

            packet.WriteLittleEndian16((short)0);
            packet.WriteLittleEndian16((short)0);
            packet.WriteLittleEndian16((short)3);
            packet.WriteLittleEndian16((short)50);
            IsoLayer.SendPDU(packet, IsoLayer.PDUType2.PDUTYPE2_FONTLIST, Secure.RDPEncrypted() ? (int)(MCS.TS_SECURITY_HEADER.SEC_ENCRYPT) : 0);
        }
Exemple #10
0
        private static void sendControl(int action)
        {
            RdpPacket packet = new RdpPacket();

            packet.WriteLittleEndian16((short)action);
            packet.WriteLittleEndian16((short)0);
            packet.WriteLittleEndian32(0);

            IsoLayer.SendPDU(packet, IsoLayer.PDUType2.PDUTYPE2_CONTROL, Secure.RDPEncrypted() ? (int)(MCS.TS_SECURITY_HEADER.SEC_ENCRYPT) : 0);
        }
Exemple #11
0
        /// <summary>
        /// Disconnect packet
        /// </summary>
        public static void Disconnect()
        {
            RdpPacket packet = new RdpPacket();

            packet.WriteLittleEndian16((short)1);
            packet.WriteLittleEndian16((short)0x3ea);
            IsoLayer.SendPDU(packet, IsoLayer.PDUType2.PDUTYPE2_SHUTDOWN_REQUEST, Secure.RDPEncrypted() ? (int)(MCS.TS_SECURITY_HEADER.SEC_ENCRYPT) : 0);
            packet = new RdpPacket();
            packet.WriteByte((byte)(DPUM << 2));
            packet.WriteByte(3);

            IsoLayer.SendTPKT(packet);
        }
        internal void clientFormatDataResponse()
        {
            RdpPacket packet = new RdpPacket();

            packet.WriteLittleEndian16((short)MsgType.CB_FORMAT_DATA_RESPONSE);
            packet.WriteLittleEndian16((short)MsgFlags.CB_RESPONSE_OK);
            packet.WriteLittleEndian32(520 + 76 + FourButesAlignLen); // length

            // cItems
            packet.WriteLittleEndian32(1); // 1 файл в списке файлов буфера обмена

            // File Descriptor
            packet.WriteLittleEndian32((int)(FD_FLAGS.FD_ATTRIBUTES));
            packet.WritePadding(32);                        // Padding 32
            packet.WriteLittleEndian32((int)(FILE_ATTRIBUTE.FILE_ATTRIBUTE_NORMAL));
            packet.WritePadding(16);                        // Padding 16
            packet.WriteLittleEndian64(DateTime.Now.Ticks); // lastWriteTime
            packet.WriteLittleEndianU32((uint)FileSizeHigh);
            packet.WriteLittleEndianU32((uint)FileSizeLow);

            // Формируем строку, содержащую нулевой байт после каждого символа
            string tempStr = "";

            foreach (var ch in FileName)
            {
                tempStr += ch + "\0";
            }

            // Получаем байты строки
            var bytes = ASCIIEncoding.GetBytes(tempStr, false).ToList();

            if (bytes.Count > 520)
            {
                packet.Write(bytes.ToArray(), 0, 520);
            }
            else
            {
                int endPos = 520 - bytes.Count;

                for (int i = 0; i < endPos; i++)
                {
                    bytes.Add(0x00);
                }

                packet.Write(bytes.ToArray(), 0, bytes.Count);
            }

            packet.WritePadding(FourButesAlign); // Add four bytes

            send(packet);
        }
Exemple #13
0
 // Input Capability Set (TS_INPUT_CAPABILITYSET)
 private static void sendInputCaps(RdpPacket packet)
 {
     packet.WriteLittleEndian16((short)Capstype.CAPSTYPE_INPUT);
     packet.WriteLittleEndian16((short)0x58);
     packet.WriteLittleEndian16((short)(
                                    InputFlags.INPUT_FLAG_FASTPATH_INPUT |
                                    InputFlags.INPUT_FLAG_FASTPATH_INPUT2 |
                                    InputFlags.INPUT_FLAG_SCANCODES |
                                    InputFlags.INPUT_FLAG_UNICODE));
     packet.WriteLittleEndian16((short)0);
     packet.WriteLittleEndian32(Options.Keyboard); // Клавиатура
     packet.WriteLittleEndian32(0x00000004);       // IBM enhanced (101- or 102-key) keyboard
     packet.WriteLittleEndian32(0);
     packet.WriteLittleEndian32(12);               // Функциональные клавиши (F1-F12)
     packet.Position += 0x40L;
 }
Exemple #14
0
        internal static void send_authresp(byte[] token, byte[] crypt_hwid, byte[] signature)
        {
            int       num    = 0x80;
            int       num2   = 0x3a;
            RdpPacket packet = new RdpPacket();

            packet.WriteLittleEndian32(num);
            packet.WriteByte(0x15);
            packet.WriteByte(2);
            packet.WriteLittleEndian16((short)num2);
            packet.WriteLittleEndian16((short)1);
            packet.WriteLittleEndian16((short)10);
            packet.Write(token, 0, 10);
            packet.WriteLittleEndian16((short)1);
            packet.WriteLittleEndian16((short)20);
            packet.Write(crypt_hwid, 0, 20);
            packet.Write(signature, 0, 0x10);

            IsoLayer.SendMCS(packet, MCS.MSC_GLOBAL_CHANNEL);
        }
Exemple #15
0
        private static void sendSupressOutput(bool bAllowDisplayUpdates)
        {
            if (Options.suppress_output_supported)
            {
                RdpPacket packet = new RdpPacket();
                packet.WriteByte(bAllowDisplayUpdates ? ((byte)1) : ((byte)0));
                packet.WriteByte(0);
                packet.WriteByte(0);
                packet.WriteByte(0);

                if (bAllowDisplayUpdates)
                {
                    packet.WriteLittleEndian16((short)0);
                    packet.WriteLittleEndian16((short)0);
                    packet.WriteLittleEndian16((ushort)Options.width);
                    packet.WriteLittleEndian16((ushort)Options.height);
                }

                IsoLayer.SendPDU(packet, IsoLayer.PDUType2.PDUTYPE2_SUPPRESS_OUTPUT, Secure.RDPEncrypted() ? (int)(MCS.TS_SECURITY_HEADER.SEC_ENCRYPT) : 0);
            }
        }
Exemple #16
0
        // Data
        internal static void RefreshRect(Rectangle[] Rectangles)
        {
            if (Network.ConnectionAlive)
            {
                RdpPacket packet = new RdpPacket();
                packet.WriteByte((byte)Rectangles.Length);
                packet.WriteByte(0);
                packet.WriteByte(0);
                packet.WriteByte(0);

                foreach (Rectangle rectangle in Rectangles)
                {
                    packet.WriteLittleEndian16((short)rectangle.Left);
                    packet.WriteLittleEndian16((short)rectangle.Top);
                    packet.WriteLittleEndian16((short)rectangle.Right);
                    packet.WriteLittleEndian16((short)rectangle.Bottom);
                }

                SendPDU(packet, PDUType2.PDUTYPE2_REFRESH_RECT, Secure.RDPEncrypted() ? (int)(MCS.TS_SECURITY_HEADER.SEC_ENCRYPT) : 0);
            }
        }
Exemple #17
0
        internal static void SendPDU(RdpPacket packet, PDUType2 type, int sec_flags)
        {
            RdpPacket packet2 = new RdpPacket();

            packet.Position = 0L;
            int num = ((int)packet.Length) + 0x12;

            packet2.WriteLittleEndian16((short)num);
            packet2.WriteLittleEndian16((short)Main.SecureValue7);
            packet2.WriteLittleEndian16((short)(MCS.McsUserID + 0x3e9));
            packet2.WriteLittleEndian32(ControlFlow.rdp_shareid);
            packet2.WriteByte(0);
            packet2.WriteByte(1);
            packet2.WriteLittleEndian16((short)(num - 14));
            packet2.WriteByte((byte)type);
            packet2.WriteByte(0);
            packet2.WriteLittleEndian16((short)0);
            packet2.copyToByteArray(packet);

            SendToGlobalChannel(packet2, sec_flags);
        }
        internal void clientTemporaryDirectory()
        {
            RdpPacket packet = new RdpPacket();

            packet.WriteLittleEndian16((short)MsgType.CB_TEMP_DIRECTORY);
            packet.WriteLittleEndian16((short)MsgFlags.NOT_SET);
            packet.WriteLittleEndian32(520 + FourButesAlignLen); // length

            // Формируем строку, содержащую нулевой байт после каждого символа
            string tempStr = "";

            foreach (var ch in ClientTempDir)
            {
                tempStr += ch + "\0";
            }

            // Получаем байты строки
            var bytes = ASCIIEncoding.GetBytes(tempStr, false).ToList();

            if (bytes.Count > 520)
            {
                packet.Write(bytes.ToArray(), 0, 520);
            }
            else
            {
                int endPos = 520 - bytes.Count;

                for (int i = 0; i < endPos; i++)
                {
                    bytes.Add(0x00);
                }

                packet.Write(bytes.ToArray(), 0, bytes.Count);
            }

            packet.WritePadding(FourButesAlign); // Add four bytes

            send(packet);
        }
Exemple #19
0
        public byte[] Negotiate()
        {
            RdpPacket packet   = new RdpPacket();
            uint      num      = (((((((0xe2000000 | NTLMSSP_NEGOTIATE_EXTENDED_SESSION_SECURITY) | NTLMSSP_NEGOTIATE_ALWAYS_SIGN) | NTLMSSP_NEGOTIATE_NTLM) | NTLMSSP_NEGOTIATE_SEAL) | NTLMSSP_NEGOTIATE_SIGN) | NTLMSSP_REQUEST_TARGET) | NTLMSSP_NEGOTIATE_OEM) | NTLMSSP_NEGOTIATE_UNICODE;
            int       position = (int)packet.Position;

            packet.WriteString("NTLMSSP", false);
            packet.WriteByte(0);
            packet.WriteLittleEndian32(1);
            packet.WriteLittleEndian32(num);
            int num3 = ((int)packet.Position) - position;

            num3 += 8;
            num3 += 8;

            if ((num & 0x2000000) != 0)
            {
                num3 += 8;
            }

            packet.WriteLittleEndian16((short)0);
            packet.WriteLittleEndian16((short)0);
            packet.WriteLittleEndian32(0);
            packet.WriteLittleEndian16((short)0);
            packet.WriteLittleEndian16((short)0);
            packet.WriteLittleEndian32(0);

            if ((num & 0x2000000) != 0)
            {
                this.WriteVersion(packet);
            }

            packet.Position     = 0L;
            this.m_NegotiateMsg = new byte[packet.Length];
            packet.Read(this.m_NegotiateMsg, 0, this.m_NegotiateMsg.Length);

            return(this.m_NegotiateMsg);
        }
Exemple #20
0
 private static void sendActivateCaps(RdpPacket data)
 {
     data.WriteLittleEndian16((short)7);
     data.WriteLittleEndian16((short)12);
     data.WriteLittleEndian16((short)0);
     data.WriteLittleEndian16((short)0);
     data.WriteLittleEndian16((short)0);
     data.WriteLittleEndian16((short)0);
 }
Exemple #21
0
 private static void sendControlCaps(RdpPacket packet)
 {
     packet.WriteLittleEndian16((short)5);
     packet.WriteLittleEndian16((short)12);
     packet.WriteLittleEndian16((short)0);
     packet.WriteLittleEndian16((short)0);
     packet.WriteLittleEndian16((short)2);
     packet.WriteLittleEndian16((short)2);
 }
Exemple #22
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);
        }
Exemple #23
0
        internal static void SlowSendInput(int time, int message_type, int device_flags, uint param1, uint param2)
        {
            if (Network.ConnectionAlive || (message_type == 0))
            {
                RdpPacket packet = new RdpPacket();
                packet.WriteLittleEndian16((short)1);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian32(time);
                packet.WriteLittleEndian16((short)message_type);
                packet.WriteLittleEndian16((short)device_flags);
                packet.WriteLittleEndian16((ushort)param1);
                packet.WriteLittleEndian16((ushort)param2);

                SendPDU(packet, PDUType2.PDUTYPE2_INPUT, Secure.RDPEncrypted() ? (int)MCS.TS_SECURITY_HEADER.SEC_ENCRYPT : 0);
            }
        }
Exemple #24
0
        internal static void send_request(byte[] client_random, byte[] rsa_data, byte[] username, byte[] host)
        {
            int       num    = 0x80;
            int       num2   = (username.Length == 0) ? 0 : (username.Length + 1);
            int       num3   = (host.Length == 0) ? 0 : (host.Length + 1);
            int       num4   = (0x80 + num2) + num3;
            RdpPacket packet = new RdpPacket();

            packet.WriteLittleEndian32(num);
            packet.WriteByte(0x13);
            packet.WriteByte(2);
            packet.WriteLittleEndian16((short)num4);
            packet.WriteLittleEndian32(1);
            packet.WriteLittleEndianU32(0xff010000);
            packet.Write(client_random, 0, 0x20);
            packet.WriteLittleEndian16((short)0);
            packet.WriteLittleEndian16((short)(Secure.modulus_size + 8));
            packet.Write(rsa_data, 0, Secure.modulus_size);
            packet.Position += 8L;
            packet.WriteLittleEndian16((short)15);
            packet.WriteLittleEndian16((short)num2);

            if (num2 != 0)
            {
                packet.Write(username, 0, num2 - 1);
                packet.WriteByte(0);
            }

            packet.WriteLittleEndian16((short)0x10);
            packet.WriteLittleEndian16((short)num3);

            if (num3 != 0)
            {
                packet.Write(host, 0, num3 - 1);
                packet.WriteByte(0);
            }

            IsoLayer.SendMCS(packet, MCS.MSC_GLOBAL_CHANNEL);
        }
Exemple #25
0
        private static void sendConfirmActive()
        {
            int num  = 390;
            int num2 = 0;

            if (Secure.RDPEncrypted())
            {
                num2 |= (int)(MCS.TS_SECURITY_HEADER.SEC_ENCRYPT);
            }

            RdpPacket data = new RdpPacket();

            data.WriteLittleEndian16((short)((0x10 + num) + RDP_SOURCE.Length));
            data.WriteLittleEndian16((short)0x13);
            data.WriteLittleEndian16((short)(MCS.McsUserID + 0x3e9));
            data.WriteLittleEndian32(rdp_shareid);
            data.WriteLittleEndian16((short)0x3ea);
            data.WriteLittleEndian16((short)RDP_SOURCE.Length);
            data.WriteLittleEndian16((short)num);
            data.Write(RDP_SOURCE, 0, RDP_SOURCE.Length);
            data.WriteLittleEndian16((short)13);
            data.Position += 2L;
            sendGeneralCaps(data);
            sendBitmapCaps(data);
            sendOrderCaps(data);
            sendBitmapcacheCaps(data);
            sendColorcacheCaps(data);
            sendActivateCaps(data);
            sendControlCaps(data);
            sendPointerCaps(data);
            sendShareCaps(data);
            sendInputCaps(data);
            sendSoundCaps(data);
            sendFontCaps(data);
            sendGlyphCacheCaps(data);

            IsoLayer.SendToGlobalChannel(data, num2);
        }
Exemple #26
0
 private static void sendGlyphCacheCaps(RdpPacket packet)
 {
     packet.WriteLittleEndian16((short)0x10);
     packet.WriteLittleEndian16((short)0x34);
     packet.WriteLittleEndian16((short)0xfe);
     packet.WriteLittleEndian16((short)4);
     packet.WriteLittleEndian16((short)0xfe);
     packet.WriteLittleEndian16((short)4);
     packet.WriteLittleEndian16((short)0xfe);
     packet.WriteLittleEndian16((short)8);
     packet.WriteLittleEndian16((short)0xfe);
     packet.WriteLittleEndian16((short)8);
     packet.WriteLittleEndian16((short)0xfe);
     packet.WriteLittleEndian16((short)0x10);
     packet.WriteLittleEndian16((short)0xfe);
     packet.WriteLittleEndian16((short)0x20);
     packet.WriteLittleEndian16((short)0xfe);
     packet.WriteLittleEndian16((short)0x40);
     packet.WriteLittleEndian16((short)0xfe);
     packet.WriteLittleEndian16((short)0x80);
     packet.WriteLittleEndian16((short)0xfe);
     packet.WriteLittleEndian16((short)0x100);
     packet.WriteLittleEndian16((short)0x40);
     packet.WriteLittleEndian16((short)0x800);
     packet.WriteLittleEndian32(0x10000);
     packet.WriteLittleEndian16((short)3);
     packet.WriteLittleEndian16((short)0);
 }
Exemple #27
0
 private static void sendOrderCaps(RdpPacket data)
 {
     byte[] buffer = new byte[0x20];
     buffer[0]    = 1;
     buffer[1]    = 1;
     buffer[2]    = 1;
     buffer[3]    = 1;
     buffer[4]    = 1;
     buffer[7]    = 0;
     buffer[8]    = 1;
     buffer[9]    = 0;
     buffer[11]   = 1;
     buffer[15]   = 0;
     buffer[0x10] = 1;
     buffer[0x11] = 0;
     buffer[0x12] = 1;
     buffer[0x13] = 0;
     buffer[20]   = 0;
     buffer[0x15] = 0;
     buffer[0x16] = 1;
     buffer[0x18] = 0;
     buffer[0x19] = 0;
     buffer[0x1a] = 0;
     buffer[0x1b] = 1;
     data.WriteLittleEndian16((short)3);
     data.WriteLittleEndian16((short)0x58);
     data.Position += 20L;
     data.WriteLittleEndian16((short)1);
     data.WriteLittleEndian16((short)20);
     data.WriteLittleEndian16((short)0);
     data.WriteLittleEndian16((short)1);
     data.WriteLittleEndian16((short)0);
     data.WriteLittleEndian16((short)170);
     data.Write(buffer, 0, 0x20);
     data.WriteLittleEndian16((short)0x6a1);
     data.WriteLittleEndian16((short)2);
     data.Position += 4L;
     data.WriteLittleEndian32(0x38400);
     data.WriteLittleEndian32(0);
     data.WriteLittleEndian16((short)0x4e4);
     data.WriteLittleEndian16((short)0);
 }
Exemple #28
0
        private static void sendPersistKeyList()
        {
            int num   = 0;
            int num2  = 0;
            int num3  = 0;
            int num4  = 0;
            int num5  = 0;
            int num6  = 0;
            int num7  = 0;
            int num8  = 0;
            int num9  = 0;
            int num10 = 0;

            Cache.TotalBitmapCache(out num, out num2, out num3, out num4, out num5);
            int offset = 0;

            while ((((num6 < num) || (num7 < num2)) || ((num8 < num3) || (num9 < num4))) || (num10 < num5))
            {
                int          num12     = 0;
                int          num13     = 0;
                int          num14     = 0;
                int          num15     = 0;
                int          num16     = 0;
                bool         bMoreKeys = false;
                List <ulong> list      = Cache.GetBitmapCache(offset, 0xff, out num12, out num13, out num14, out num15, out num16, out bMoreKeys);
                RdpPacket    packet    = new RdpPacket();
                packet.WriteLittleEndian16((ushort)num12);
                packet.WriteLittleEndian16((ushort)num13);
                packet.WriteLittleEndian16((ushort)num14);
                packet.WriteLittleEndian16((ushort)num15);
                packet.WriteLittleEndian16((ushort)num16);
                packet.WriteLittleEndian16((ushort)num);
                packet.WriteLittleEndian16((ushort)num2);
                packet.WriteLittleEndian16((ushort)num3);
                packet.WriteLittleEndian16((ushort)num4);
                packet.WriteLittleEndian16((ushort)num5);
                byte num17 = 0;
                if (offset == 0)
                {
                    num17 = (byte)(num17 | 1);
                }
                if (!bMoreKeys)
                {
                    num17 = (byte)(num17 | 2);
                }
                packet.WriteByte(num17);
                packet.WriteByte(0);
                packet.WriteLittleEndian16((short)0);
                foreach (ulong num18 in list)
                {
                    packet.Write(BitConverter.GetBytes(num18), 0, 8);
                }
                IsoLayer.SendPDU(packet, IsoLayer.PDUType2.PDUTYPE2_BITMAPCACHE_PERSISTENT_LIST, Secure.RDPEncrypted() ? (int)(MCS.TS_SECURITY_HEADER.SEC_ENCRYPT) : 0);
                offset += list.Count;
                num6   += num12;
                num7   += num13;
                num8   += num14;
                num9   += num15;
                num10  += num16;
            }
        }
Exemple #29
0
        /// <summary>
        /// Client Info PDU
        /// </summary>
        private static RdpPacket getLoginInfo(string domain, string username, string password, string command, string directory, bool bAutoReconnect)
        {
            int num1 = 2 * "127.0.0.1".Length;
            int num2 = 2 * @"C:\WINNT\System32\mstscax.dll".Length;
            int num3 = 2 * domain.Length;
            int num4 = 2 * username.Length;
            int num5 = 2 * password.Length;
            int num6 = 2 * command.Length;
            int num7 = 2 * directory.Length;

            //int num8 = 0x213b;

            int num8 = (int)(
                ClientInfoFlags.INFO_AUTOLOGON |
                ClientInfoFlags.INFO_DISABLECTRLALTDEL |
                ClientInfoFlags.INFO_LOGONERRORS |
                ClientInfoFlags.INFO_LOGONNOTIFY |
                ClientInfoFlags.INFO_ENABLEWINDOWSKEY |
                ClientInfoFlags.INFO_MOUSE |
                ClientInfoFlags.INFO_NOAUDIOPLAYBACK |
                ClientInfoFlags.INFO_UNICODE);

            RdpPacket packet = new RdpPacket();

            packet.WriteLittleEndian32(0);
            packet.WriteLittleEndian32(num8);
            packet.WriteLittleEndian16((short)num3);
            packet.WriteLittleEndian16((short)num4);

            if ((num8 & 8) != 0)
            {
                packet.WriteLittleEndian16((short)num5);
            }
            else
            {
                packet.WriteLittleEndian16((short)0);
            }

            packet.WriteLittleEndian16((short)num6);
            packet.WriteLittleEndian16((short)num7);

            if (0 < num3)
            {
                packet.WriteUnicodeString(domain);
            }
            else
            {
                packet.WriteLittleEndian16((short)0);
            }

            packet.WriteUnicodeString(username);

            if ((num8 & 8) != 0)
            {
                packet.WriteUnicodeString(password);
            }
            else
            {
                packet.WriteLittleEndian16((short)0);
            }

            if (0 < num6)
            {
                packet.WriteUnicodeString(command);
            }
            else
            {
                packet.WriteLittleEndian16((short)0);
            }

            if (0 < num7)
            {
                packet.WriteUnicodeString(directory);
            }
            else
            {
                packet.WriteLittleEndian16((short)0);
            }

            packet.WriteLittleEndian16((short)2);
            packet.WriteLittleEndian16((short)(num1 + 2));
            packet.WriteUnicodeString("127.0.0.1");
            packet.WriteLittleEndian16((short)(num2 + 2));
            packet.WriteUnicodeString(@"C:\WINNT\System32\mstscax.dll");
            TimeZoneInfo info = TimeZoneInfo.Local;

            packet.WriteLittleEndian32((int)info.BaseUtcOffset.TotalMinutes);
            packet.WriteUnicodeString(info.StandardName);
            packet.Position += 0x3e - (2 * info.StandardName.Length);

            if (info.SupportsDaylightSavingTime)
            {
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((ushort)10);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)30);
                packet.WriteLittleEndian16((short)2);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian32(0);
            }
            else
            {
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian32(0);
            }

            packet.WriteUnicodeString(info.DaylightName);
            packet.Position += 0x3e - (2 * info.DaylightName.Length);

            if (info.SupportsDaylightSavingTime)
            {
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((ushort)3);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0x1b);
                packet.WriteLittleEndian16((short)1);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian32((int)(info.BaseUtcOffset.TotalMinutes + 1.0));
            }
            else
            {
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian16((short)0);
                packet.WriteLittleEndian32(0);
            }

            packet.WriteLittleEndianU32(0);
            PerformanceFlags flags = (PerformanceFlags)0;

            if (!Options.IsHostFlagSet(HostFlags.DesktopBackground))
            {
                flags |= PerformanceFlags.PERF_DISABLE_WALLPAPER;
            }

            if (Options.IsHostFlagSet(HostFlags.FontSmoothing))
            {
                flags |= PerformanceFlags.PERF_ENABLE_FONT_SMOOTHING;
            }

            if (Options.IsHostFlagSet(HostFlags.DesktopComposition))
            {
                flags |= PerformanceFlags.PERF_ENABLE_DESKTOP_COMPOSITION;
            }

            if (!Options.IsHostFlagSet(HostFlags.ShowWindowContents))
            {
                flags |= PerformanceFlags.PERF_DISABLE_FULLWINDOWDRAG;
            }

            if (!Options.IsHostFlagSet(HostFlags.MenuAnimation))
            {
                flags |= PerformanceFlags.PERF_DISABLE_MENUANIMATIONS;
            }

            if (!Options.IsHostFlagSet(HostFlags.VisualStyles))
            {
                flags |= PerformanceFlags.PERF_DISABLE_THEMING;
            }

            packet.WriteLittleEndian32((int)flags);

            if (bAutoReconnect)
            {
                packet.WriteLittleEndian32(0x1c);
                packet.WriteLittleEndian32(0x1c);
                packet.WriteLittleEndian32(1);
                packet.WriteLittleEndian32(Options.LogonID);
                HMACT64 hmact = new HMACT64(Options.ReconnectCookie);
                hmact.update(Secure.GetClentRandom());
                byte[] buffer = hmact.digest();
                packet.Write(buffer, 0, buffer.Length);
                return(packet);
            }

            packet.WriteLittleEndian32(0);

            return(packet);
        }
Exemple #30
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);
        }