Beispiel #1
0
        private static void DoStuff(string aesKey, string packetHex)
        {
            Console.WriteLine($"=========== Login packet inspection #{_packetCount++} ======================================");

            var packet      = HexUtil.StringToByteArray(packetHex);
            var firstPacket = new PacketReader(packet, packet.Length);

            var decryptme1 = firstPacket.ReadBytes(16);
            var decryptme2 = firstPacket.ReadBytes(16);

            var username = Utils.GetASCIIZ(Crypto.DecryptStaticBuffer(decryptme1));

            Console.WriteLine($"{"Username:"******"{username}\"");

            var secondPacket = new PacketReader(Crypto.DecryptStaticBuffer(decryptme2), 16);

            secondPacket.Seek(0, SeekOrigin.Begin);

            Console.WriteLine("SecondPacket:");
            Console.WriteLine(HexUtil.HexDump(secondPacket.Buffer));

            var authDword = secondPacket.ReadUInt32();
            var unknown   = secondPacket.ReadBytes(12);

            Console.WriteLine($"{"AuthRandom:",-20}\"{authDword}\"");
            Console.WriteLine("Unknown:");
            Console.WriteLine(HexUtil.HexDump(unknown));

            var secondPacketCrypto = new Crypto(aesKey);

            var input  = firstPacket.ReadBytes(32);
            var output = new byte[24];

            Console.WriteLine("Decrypt input:");
            Console.WriteLine(HexUtil.HexDump(input));

            if (!secondPacketCrypto.PacketDecrypt(input, ref output, 4114))
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Login decryption failed.");
                Console.ResetColor();
            }
            else
            {
                Console.WriteLine("Decrypt output:");
                Console.WriteLine(HexUtil.HexDump(output));

                var packetReader2 = new PacketReader(output, output.Length);
                packetReader2.Seek(0, SeekOrigin.Begin);

                var password = Utils.GetASCIIZ(packetReader2.ReadBytes(20));

                Console.WriteLine($"{"Password:"******"{password}\"");

                var clientVer = packetReader2.ReadUInt32();
                Console.WriteLine($"{"ClientVer:",-20}\"{clientVer}\"");
            }
        }
        // Server
        private void ServerPacketProcessorOnPacketReceived(object sender, PacketReceivedEventArgs e)
        {
            var result = _packetModifier.ModifyPacket <PacketOutgoing>(e.Packet, out var manualDiscard);

            if (result != null)
            {
                // Log.
                Logger.Debug($"Server packet received [{e.Packet.Header,-4}] {result.PacketModified.HeaderType}");

                if (result.ExtraPackets != null)
                {
                    foreach (var packet in result.ExtraPackets)
                    {
                        Logger.Debug($"Server packet extra for {result.PacketModified.HeaderType} > {packet.HeaderType}.");
                    }
                }

                // Send.
                Task.Run(() => SendToClientAsync(result.PacketModified));

                if (result.ExtraPackets != null)
                {
                    foreach (var packet in result.ExtraPackets)
                    {
                        Task.Run(() => SendToClientAsync(packet));
                    }
                }
            }
            else if (manualDiscard)
            {
                Logger.Debug("Server packet {header} has been discarded manually.", e.Packet.Header);
            }
            else
            {
                Logger.Warning("Server packet {header} has been discarded, release {release}. Hex:\n" +
                               HexUtil.HexDump(e.Packet.GetPacket().ToArray()), e.Packet.Header, e.Packet.Release);
            }
        }