Beispiel #1
0
        public static byte[] LogonProof(IPacketReader packet)
        {
            byte[] A   = packet.ReadBytes(32);
            byte[] kM1 = packet.ReadBytes(20);
            byte[] rA  = A.Reverse().ToArray();
            byte[] AB  = A.Concat(B.GetBytes(32).Reverse()).ToArray();

            if (new BigInteger(A) % new BigInteger(N) == 0)
            {
                return(new byte[1]);
            }

            using (SHA1 sha1 = new SHA1CryptoServiceProvider())
            {
                // SS_Hash
                byte[] rU = sha1.ComputeHash(AB).Reverse().ToArray();
                var    s  = V.ModPow(new BigInteger(rU), new BigInteger(RN)) * new BigInteger(rA);
                s = s.ModPow(new BigInteger(RB), new BigInteger(RN));

                byte[] S1 = new byte[16], S2 = new byte[16];
                byte[] rS = s.GetBytes(32).Reverse().ToArray();
                for (int t = 0; t < 16; t++)
                {
                    S1[t] = rS[t * 2];
                    S2[t] = rS[(t * 2) + 1];
                }

                byte[] hashS1  = sha1.ComputeHash(S1), hashS2 = sha1.ComputeHash(S2);
                byte[] ss_hash = new byte[hashS1.Length + hashS2.Length];
                for (int t = 0; t < hashS1.Length; t++)
                {
                    ss_hash[t * 2]       = hashS1[t];
                    ss_hash[(t * 2) + 1] = hashS2[t];
                }

                // calc M1 & M2
                byte[] NHash = sha1.ComputeHash(N);
                byte[] GHash = sha1.ComputeHash(G.GetBytes());

                var tmp = Enumerable.Range(0, 20)
                          .Select(t => (byte)(NHash[t] ^ GHash[t]))
                          .Concat(sha1.ComputeHash(BUsername))
                          .Concat(Salt)
                          .Concat(A)
                          .Concat(B.GetBytes(32).Reverse())
                          .Concat(ss_hash);

                byte[] M1 = sha1.ComputeHash(tmp.ToArray());
                byte[] M2 = sha1.ComputeHash(A.Concat(M1).Concat(ss_hash).ToArray());

                // instantiate coders/cryptors
                PacketCrypt = new PacketCrypt(ss_hash, ClientBuild);

                // create packet data
                byte[] result = new byte[GetLogonProofSize()];
                result[0] = 1;
                Array.Copy(M2, 0, result, 2, M2.Length);
                return(result);
            }
        }
Beispiel #2
0
        public static byte[] LogonChallenge(IPacketReader packet)
        {
            packet.ReadBytes(32);                            //Skip to username
            BUsername = packet.ReadBytes(packet.ReadByte()); //Read username
            string username = Encoding.ASCII.GetString(BUsername);

            byte[] x;
            using (SHA1 sha = new SHA1CryptoServiceProvider())
            {
                byte[] user = Encoding.ASCII.GetBytes(username.ToUpper() + ":" + Password.ToUpper());
                byte[] res  = Salt.Concat(sha.ComputeHash(user, 0, user.Length)).ToArray();
                x = sha.ComputeHash(res, 0, res.Length).Reverse().ToArray();
            }

            byte[] b = new byte[20];
            new Random().NextBytes(b);
            RB = b.Reverse().ToArray();

            G = new BigInteger(new byte[] { 7 });
            V = G.ModPow(new BigInteger(x), new BigInteger(RN));

            K = new BigInteger(new byte[] { 3 });
            BigInteger temp = (K * V) + G.ModPow(new BigInteger(RB), new BigInteger(RN));

            B = temp % new BigInteger(RN);

            IEnumerable <byte> result = new byte[3]; //Opcode, 0, Success

            result = result.Concat(B.GetBytes(32).Reverse());
            result = result.Concat(new byte[] { 1, 7, 32 }); //1, G, 32
            result = result.Concat(N);
            result = result.Concat(Salt);
            result = result.Concat(new byte[16]); //unknown, Security Flag
            return(result.ToArray());
        }
        public void Read(IPacketReader reader)
        {
            Identifier = reader.ReadString().ToString();
            var data = reader.ReadBytes((int)reader.Buffer.Length);

            Data = new Memory <byte>(new byte[data.Length]);
            data.CopyTo(Data.Span);
        }
Beispiel #4
0
        public static byte[] LogonChallenge(IPacketReader packet)
        {
            packet.Position = 11;
            ClientBuild     = packet.ReadUInt16();

            packet.Position = 33;                                  // Skip to username
            BUsername       = packet.ReadBytes(packet.ReadByte()); // Read username
            string username = Encoding.ASCII.GetString(BUsername);

            byte[] x;
            using (SHA1 sha = new SHA1CryptoServiceProvider())
            {
                byte[] user = Encoding.ASCII.GetBytes(username.ToUpper() + ":" + Password.ToUpper());
                byte[] res  = Salt.Concat(sha.ComputeHash(user, 0, user.Length)).ToArray();
                x = sha.ComputeHash(res, 0, res.Length).Reverse().ToArray();
            }

            byte[] b = new byte[20];
            new Random().NextBytes(b);
            RB = b.Reverse().ToArray();

            G = new BigInteger(new byte[] { 7 });
            V = G.ModPow(new BigInteger(x), new BigInteger(RN));

            K = new BigInteger(new byte[] { 3 });
            BigInteger temp = (K * V) + G.ModPow(new BigInteger(RB), new BigInteger(RN));

            B = temp % new BigInteger(RN);

            int size = ClientBuild < 5428 ? 118 : 119;

            byte[] result = new byte[size];
            Array.Copy(B.GetBytes(32).Reverse().ToArray(), 0, result, 3, 32);
            result[35] = 1;
            result[36] = 7;
            result[37] = 32;
            Array.Copy(N, 0, result, 38, N.Length);
            Array.Copy(Salt, 0, result, 70, Salt.Length);
            return(result);
        }
Beispiel #5
0
        public static byte[] LogonChallenge(IPacketReader packet)
        {
            packet.Position = 11;
            ClientBuild     = packet.ReadUInt16();

            packet.Position = 33;                                  // Skip to username
            BUsername       = packet.ReadBytes(packet.ReadByte()); // Read username

            byte[] credshash;
            using (SHA1 sha = new SHA1CryptoServiceProvider())
            {
                string username    = Encoding.ASCII.GetString(BUsername);
                byte[] credentials = Encoding.ASCII.GetBytes(username.ToUpper() + ":" + Password.ToUpper());
                byte[] tmp         = Salt.Concat(sha.ComputeHash(credentials)).ToArray();
                credshash = sha.ComputeHash(tmp).Reverse().ToArray();
            }

            RB = new byte[20];
            new Random().NextBytes(RB);

            G = new BigInteger(new byte[] { 7 });
            V = G.ModPow(new BigInteger(credshash), new BigInteger(RN));

            K = new BigInteger(new byte[] { 3 });
            B = ((K * V) + G.ModPow(new BigInteger(RB), new BigInteger(RN))) % new BigInteger(RN);

            // create packet data
            byte[] result = new byte[GetLogonChallengeSize()];
            Array.Copy(B.GetBytes(32).Reverse().ToArray(), 0, result, 3, 32);
            result[35] = 1;
            result[36] = 7;
            result[37] = 32;
            Array.Copy(N, 0, result, 38, N.Length);
            Array.Copy(Salt, 0, result, 70, Salt.Length);
            return(result);
        }
Beispiel #6
0
        public static byte[] LogonProof(IPacketReader packet)
        {
            byte[] A   = packet.ReadBytes(32);
            byte[] kM1 = packet.ReadBytes(20);
            byte[] rA  = A.Reverse().ToArray();
            byte[] AB  = A.Concat(B.GetBytes(32).Reverse()).ToArray();

            if (new BigInteger(A) % new BigInteger(N) == 0)
            {
                return(new byte[1]);
            }

            SHA1 sha = new SHA1CryptoServiceProvider();

            byte[] rU = sha.ComputeHash(AB).Reverse().ToArray();

            //SS_Hash
            BigInteger s = V.ModPow(new BigInteger(rU), new BigInteger(RN));

            s *= new BigInteger(rA);
            s  = s.ModPow(new BigInteger(RB), new BigInteger(RN));

            byte[] S1 = new byte[16];
            byte[] S2 = new byte[16];
            byte[] S  = s.GetBytes(32);
            byte[] rS = S.Reverse().ToArray();
            for (int t = 0; t < 16; t++)
            {
                S1[t] = rS[t * 2];
                S2[t] = rS[(t * 2) + 1];
            }

            byte[] hashS1 = sha.ComputeHash(S1);
            byte[] hashS2 = sha.ComputeHash(S2);
            SS_Hash = new byte[hashS1.Length + hashS2.Length];
            for (int t = 0; t < hashS1.Length; t++)
            {
                SS_Hash[t * 2]       = hashS1[t];
                SS_Hash[(t * 2) + 1] = hashS2[t];
            }

            //calc M1
            byte[] M1;
            byte[] NHash   = sha.ComputeHash(N);
            byte[] GHash   = sha.ComputeHash(G.GetBytes());
            byte[] NG_Hash = new byte[20];
            for (int t = 0; t < 20; t++)
            {
                NG_Hash[t] = (byte)(NHash[t] ^ GHash[t]);
            }

            IEnumerable <byte> tmp = NG_Hash.Concat(sha.ComputeHash(BUsername));

            tmp = tmp.Concat(Salt);
            tmp = tmp.Concat(A);
            tmp = tmp.Concat(B.GetBytes(32).Reverse());
            tmp = tmp.Concat(SS_Hash);
            M1  = sha.ComputeHash(tmp.ToArray());

            //calc M2
            byte[] M2;
            tmp = A.Concat(M1);
            tmp = tmp.Concat(SS_Hash);
            M2  = sha.ComputeHash(tmp.ToArray());

            sha.Dispose();

            IEnumerable <byte> result = new byte[] { 1, 0 };

            result = result.Concat(M2);
            result = result.Concat(new byte[4]);
            return(result.ToArray());
        }
Beispiel #7
0
        public static byte[] LogonProof(IPacketReader packet)
        {
            byte[] A   = packet.ReadBytes(32);
            byte[] kM1 = packet.ReadBytes(20);
            byte[] rA  = A.Reverse().ToArray();
            byte[] AB  = A.Concat(B.GetBytes(32).Reverse()).ToArray();

            if (new BigInteger(A) % new BigInteger(N) == 0)
            {
                return(new byte[1]);
            }

            SHA1 sha1 = new SHA1CryptoServiceProvider();

            byte[] rU = sha1.ComputeHash(AB).Reverse().ToArray();

            // SS_Hash
            BigInteger s = V.ModPow(new BigInteger(rU), new BigInteger(RN));

            s *= new BigInteger(rA);
            s  = s.ModPow(new BigInteger(RB), new BigInteger(RN));

            byte[] S1 = new byte[16];
            byte[] S2 = new byte[16];
            byte[] S  = s.GetBytes(32);
            byte[] rS = S.Reverse().ToArray();
            for (int t = 0; t < 16; t++)
            {
                S1[t] = rS[t * 2];
                S2[t] = rS[(t * 2) + 1];
            }

            byte[] hashS1  = sha1.ComputeHash(S1);
            byte[] hashS2  = sha1.ComputeHash(S2);
            byte[] ss_hash = new byte[hashS1.Length + hashS2.Length];
            for (int t = 0; t < hashS1.Length; t++)
            {
                ss_hash[t * 2]       = hashS1[t];
                ss_hash[(t * 2) + 1] = hashS2[t];
            }

            // calc M1
            byte[] M1;
            byte[] NHash   = sha1.ComputeHash(N);
            byte[] GHash   = sha1.ComputeHash(G.GetBytes());
            byte[] NG_Hash = new byte[20];

            for (int t = 0; t < 20; t++)
            {
                NG_Hash[t] = (byte)(NHash[t] ^ GHash[t]);
            }

            var tmp = NG_Hash.Concat(sha1.ComputeHash(BUsername))
                      .Concat(Salt)
                      .Concat(A)
                      .Concat(B.GetBytes(32).Reverse())
                      .Concat(ss_hash);

            M1 = sha1.ComputeHash(tmp.ToArray());

            // calc M2
            byte[] M2;
            tmp = A.Concat(M1).Concat(ss_hash);
            M2  = sha1.ComputeHash(tmp.ToArray());
            sha1.Dispose();

            // instantiate coders/cryptors
            PacketCrypt = new PacketCrypt(ss_hash, ClientBuild);

            // additional information, always zeroed
            int extradata = 0;

            if (ClientBuild < 6178 || ClientBuild == 6180)
            {
                extradata = 04; // uint unk
            }
            else if (ClientBuild < 8089)
            {
                extradata = 06; // uint unk, ushort unkFlags
            }
            else
            {
                extradata = 10; // uint account flag, uint surveyId, ushort unkFlags
            }
            byte[] result = new byte[22 + extradata];
            result[0] = 1;
            Array.Copy(M2, 0, result, 2, M2.Length);
            return(result);
        }