Пример #1
0
        internal static RdpPacket Secure_Receive(out bool bFastPath)
        {
            int       num;
            int       num2;
            int       num3   = 0;
            RdpPacket packet = null;

Label_0004:
            bFastPath = false;
            packet    = ReceiveMCS(out num, out num2);
            if (packet == null)
            {
                return(null);
            }
            switch (num2)
            {
            case 0xff:
                bFastPath = true;
                return(packet);

            case 0xfe:
                packet    = Secure.DecryptPacket(packet);
                bFastPath = true;
                return(packet);
            }
            if (Secure.RDPEncrypted() || Licence.IsLicensePacket(packet))
            {
                num3 = packet.getLittleEndian32();
                if ((num3 & MCS.SEC_ENCRYPT) != 0)
                {
                    packet = Secure.DecryptPacket(packet);
                }
                if ((num3 & 0x80) != 0)
                {
                    Licence.process(packet);
                    goto Label_0004;
                }
                if ((num3 & MCS.SEC_REDIRECTION_PKT) != 0)
                {
                    ControlFlow.processRedirection(packet, true);
                    goto Label_0004;
                }
            }
            if (num != MCS.MSC_GLOBAL_CHANNEL)
            {
                Channels.channel_process(num, packet);
                goto Label_0004;
            }
            return(packet);
        }
Пример #2
0
 internal static void internal_sendInput(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);
         sendDataPDU(packet, PDUType2.PDUTYPE2_INPUT, Secure.RDPEncrypted() ? MCS.SEC_ENCRYPT : 0);
     }
 }
Пример #3
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;
            }
        }
Пример #4
0
        private static void sendConfirmActive()
        {
            int num  = 390;
            int num2 = 0;

            if (Secure.RDPEncrypted())
            {
                num2 |= MCS.SEC_ENCRYPT;
            }
            RdpPacket data = new RdpPacket();

            data.WriteLittleEndian16((short)((0x10 + num) + RDP_SOURCE.Length));
            data.WriteLittleEndian16((short)0x13);
            data.WriteLittleEndian16((short)(RDPClient.McsUserID + 0x3e9));
            data.WriteLittleEndian32(RDPClient.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.SendMCS_GlobalChannel(data, num2);
        }
Пример #5
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;
            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;
                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);

                IsoLayer.sendDataPDU(packet, IsoLayer.PDUType2.PDUTYPE2_BITMAPCACHE_PERSISTENT_LIST, Secure.RDPEncrypted() ? MCS.SEC_ENCRYPT : 0);
                num6  += num12;
                num7  += num13;
                num8  += num14;
                num9  += num15;
                num10 += num16;
            }
        }
Пример #6
0
        public static void Disconnect()
        {
            RdpPacket packet = new RdpPacket();

            packet.WriteLittleEndian16((short)1);
            packet.WriteLittleEndian16((short)0x3ea);
            IsoLayer.sendDataPDU(packet, IsoLayer.PDUType2.PDUTYPE2_SHUTDOWN_REQUEST, Secure.RDPEncrypted() ? SEC_ENCRYPT : 0);
            packet = new RdpPacket();
            packet.WriteByte((byte)(DPUM << 2));
            packet.WriteByte(3);
            IsoLayer.SendTPKT(packet);
        }
Пример #7
0
        private static RdpPacket getLoginInfo(string domain, string username, string password, string command, string directory, bool bAutoReconnect)
        {
            int       num    = 2 * "127.0.0.1".Length;
            int       num2   = 2 * @"C:\WINNT\System32\mstscax.dll".Length;
            int       num1   = _p;
            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;
            RdpPacket packet = new RdpPacket();
            int       num8   = 0x213b;

            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)(num + 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 (!RDPClient.IsHostFlagSet(HostFlags.DesktopBackground))
            {
                flags |= PerformanceFlags.PERF_DISABLE_WALLPAPER;
            }
            if (RDPClient.IsHostFlagSet(HostFlags.FontSmoothing))
            {
                flags |= PerformanceFlags.PERF_ENABLE_FONT_SMOOTHING;
            }
            if (RDPClient.IsHostFlagSet(HostFlags.DesktopComposition))
            {
                flags |= PerformanceFlags.PERF_ENABLE_DESKTOP_COMPOSITION;
            }
            if (!RDPClient.IsHostFlagSet(HostFlags.ShowWindowContents))
            {
                flags |= PerformanceFlags.PERF_DISABLE_FULLWINDOWDRAG;
            }
            if (!RDPClient.IsHostFlagSet(HostFlags.MenuAnimation))
            {
                flags |= PerformanceFlags.PERF_DISABLE_MENUANIMATIONS;
            }
            if (!RDPClient.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(RDPClient.LogonID);
                HMACT64 hmact = new HMACT64(RDPClient.ReconnectCookie);
                hmact.update(Secure.GetClentRandom());
                byte[] buffer = hmact.digest();
                packet.Write(buffer, 0, buffer.Length);
                return(packet);
            }
            packet.WriteLittleEndian32(0);
            return(packet);
        }
Пример #8
0
        internal static void send_connection_request(byte[] loadBalanceToken, bool bAutoReconnect)
        {
            int num;

            RDPClient.dec_count     = 0;
            RDPClient.enc_count     = 0;
            Network.ConnectionStage = RDPClient.eConnectionStage.Negotiating;
            if (RDPClient.enableNLA)
            {
                sendConnectNegotiation(3, loadBalanceToken);
                num = receiveConnectNegotiation();

                if (num == 0x10000000)
                {
                    Network.Close();
                    Network.Connect(RDPClient.Host, RDPClient.Port);
                    sendConnectNegotiation(0, loadBalanceToken);
                    num = receiveConnectNegotiation();

                    if (num != 0)
                    {
                        throw new RDFatalException("Security negotiation failed!");
                    }
                }
                else
                {
                    if (((num & 1) != 0) || ((num & 2) != 0))
                    {
                        Network.ConnectionStage = RDPClient.eConnectionStage.Securing;
                        Network.ConnectSSL();
                    }
                    if ((num & 2) != 0)
                    {
                        Network.ConnectionStage = RDPClient.eConnectionStage.Authenticating;
                        CredSSP.Negotiate(Network.GetSSLPublicKey());
                    }
                }
            }
            else
            {
                sendConnectNegotiation(0, loadBalanceToken);
                num = receiveConnectNegotiation();
                if (num != 0)
                {
                    throw new RDFatalException("Security negotiation failed!");
                }
            }

            Network.ConnectionStage = RDPClient.eConnectionStage.Establishing;
            IsoLayer.SendTPKT(sendConnectInitial(sendMcsData(true, Channels.RegisteredChannels.Count, num)));
            receiveConnectResponse();
            send_ErectDomainRequest();
            send_AttachUserRequest();
            RDPClient.McsUserID = receive_AttachUserConfirm();
            send_ChannelJoinRequest(RDPClient.McsUserID + MCS_USERCHANNEL_BASE);
            receive_ChannelJoinConfirm();
            send_ChannelJoinRequest(MSC_GLOBAL_CHANNEL);
            receive_ChannelJoinConfirm();
            foreach (IVirtualChannel channel in Channels.RegisteredChannels)
            {
                send_ChannelJoinRequest(channel.ChannelID);
                receive_ChannelJoinConfirm();
            }
            int num2 = 0x40;

            if (Secure.RDPEncrypted())
            {
                Network.ConnectionStage = RDPClient.eConnectionStage.SecureAndLogin;
                RdpPacket packet = Secure.establishKey();
                packet.Position = 0L;
                IsoLayer.SendMCS(packet, MSC_GLOBAL_CHANNEL);
                num2 |= SEC_ENCRYPT;
            }
            else
            {
                Network.ConnectionStage = RDPClient.eConnectionStage.Login;
            }
            IsoLayer.SendMCS_GlobalChannel(getLoginInfo(RDPClient.Domain, RDPClient.Username, RDPClient.Password, "", "", bAutoReconnect), num2);
        }