Пример #1
0
 public static BigInteger Getx(BigInteger Salt, byte[] LogonHash)
 {
     Sha1Hash h = new Sha1Hash();
     h.Update(Salt);
     h.Update(LogonHash);
     return new BigInteger(h.Final());
 }
Пример #2
0
 public static byte[] GetM2(BigInteger A, BigInteger M, BigInteger K)
 {
     Sha1Hash h = new Sha1Hash();
     h.Update(A);
     h.Update(M);
     return h.Final(K);
 }
Пример #3
0
 public static byte[] GetLogonHash(string Username, string Password)
 {
     Sha1Hash h = new Sha1Hash();
     string sI = String.Format("{0}:{1}", Username, Password.ToUpper());
     h.Update(sI);
     return h.Final();
 }
Пример #4
0
        public Sha1Warden(byte[] buff, UInt32 size)
        {
            sh = new Sha1Hash();
            taken = size / 2;

            byte[] buff2 = new byte[taken];
            memcopy(buff2, buff);

            sh.Initialize();
            sh.Update(buff2);
            memcopy(o1, sh.Final());

            byte[] buff3 = new byte[20];
            memcopy(buff3, buff, 20);

            sh.Initialize();
            sh.Update(buff3);
            memcopy(o2, sh.Final());

            memset(o0, 0x00);

            FillUp();
        }
Пример #5
0
        // Converts S to K
        // K is the Key which is passed to the Crypt class
        public static byte[] ShaInterleave(BigInteger S)
        {
            byte[] t = S;
            int HalfSize = t.Length / 2; // Untested.  I previously hard coded this as 16
            byte[] t1 = new byte[HalfSize];

            for (int i = 0; i < HalfSize; i++)
                t1[i] = t[i*2];

            Sha1Hash sha = new Sha1Hash();
            byte[] t1hash = sha.Final(t1);

            byte[] vK = new byte[40];
            for (int i = 0; i < 20; i++)
                vK[i*2] = t1hash[i];

            for (int i = 0; i < HalfSize; i++)
                t1[i] = t[i*2+1];

            sha = new Sha1Hash();
            t1hash = sha.Final(t1);

            for (int i = 0; i < 20; i++)
                vK[i*2+1] = t1hash[i];

            return vK;
        }
Пример #6
0
 // HandleLogonProof stuff
 public static BigInteger Getu(BigInteger A, BigInteger B)
 {
     Sha1Hash h = new Sha1Hash();
     h.Update(A);
     return new BigInteger(h.Final(B));
 }
Пример #7
0
        public BigInteger GetM(string Username, BigInteger s, BigInteger A, BigInteger B, BigInteger K)
        {
            Sha1Hash sha;

            sha = new Sha1Hash();
            byte[] hash = sha.Final(N);

            sha = new Sha1Hash();
            byte[] ghash = sha.Final(g);

            for (int i = 0; i < 20; ++i)
                hash[i] ^= ghash[i];

            // TODO: do t2 and t4 need to be BigInts?  Could we just use the byte[]?
            BigInteger t3 = new BigInteger(hash);

            sha = new Sha1Hash();
            sha.Update(Username);
            BigInteger t4 = new BigInteger(sha.Final());

            sha = new Sha1Hash();
            sha.Update(t3);
            sha.Update(t4);
            sha.Update(s);
            sha.Update(A);
            sha.Update(B);
            return new BigInteger(sha.Final(K));
        }
Пример #8
0
        private byte[] GenerateCrc(byte[] crcsalt)
        {
            Sha1Hash sha;
            string[] files = { "WoW.bin", "DivxDecoder.bin", "Unicows.bin" };

            byte[] buffer1 = new byte[0x40];
            byte[] buffer2 = new byte[0x40];

            for (int i = 0; i < 0x40; ++i)
            {
                buffer1[i] = 0x36;
                buffer2[i] = 0x5c;
            }

            for (int i = 0; i < crcsalt.Length; ++i)
            {
                buffer1[i] ^= crcsalt[i];
                buffer2[i] ^= crcsalt[i];
            }

            sha = new Sha1Hash();
            sha.Update(buffer1);

            foreach (string filename in files)
            {
                if (!File.Exists(@"crc\" + filename))
                {
                    Log.WriteLine(LogType.Error, "CRC File {0} doesn't exist!", filename);
                }

                FileStream fs = new FileStream(@"crc\" + filename, FileMode.Open, FileAccess.Read);
                byte[] Buffer = new byte[fs.Length];
                fs.Read(Buffer, 0, (int)fs.Length);
                sha.Update(Buffer);
            }
            byte[] hash1 = sha.Final();

            sha = new Sha1Hash();
            sha.Update(buffer2);
            sha.Update(hash1);
            return sha.Final();
        }
Пример #9
0
        public void AuthChallangeRequest(PacketIn packetIn)
        {
            packetIn.ReadByte();
            byte error = packetIn.ReadByte();
            if (error != 0x00)
            {
                Log.WriteLine(LogType.Error, "Authentication error: {0}", (AccountStatus)error);
                Disconnect();
                return;
            }

            B = new BigInteger(packetIn.ReadBytes(32));               // Varies
            byte glen = packetIn.ReadByte();                          // Length = 1
            g = packetIn.ReadBytes(glen);                             // g = 7
            byte Nlen = packetIn.ReadByte();                          // Length = 32
            N = packetIn.ReadBytes(Nlen);                             // N = B79B3E2A87823CAB8F5EBFBF8EB10108535006298B5BADBD5B53E1895E644B89
            Salt = new BigInteger(packetIn.ReadBytes(32));            // Salt = 3516482AC96291B3C84B4FC204E65B623EFC2563C8B4E42AA454D93FCD1B56BA
            crcsalt = packetIn.ReadBytes(16);                         // Varies

            BigInteger S;
            srp = new Srp6(new BigInteger(N), new BigInteger(g));

            do
            {
                a = BigInteger.Random(19 * 8);
                A = srp.GetA(a);

                I = Srp6.GetLogonHash(mUsername, mPassword);

                BigInteger x = Srp6.Getx(Salt, I);
                BigInteger u = Srp6.Getu(A, B);
                S = srp.ClientGetS(a, B, x, u);
            }
            while (S < 0);

            mKey = Srp6.ShaInterleave(S);
            M = srp.GetM(mUsername, Salt, A, B, new BigInteger(mKey));

            packetIn.ReadByte();

            Sha1Hash sha;
            byte[] files_crc;

            // Generate CRC/hashes of the Game Files
            if (Config.Retail)
                files_crc = GenerateCrc(crcsalt);
            else
                files_crc = new byte[20];

            // get crc_hash from files_crc
            sha = new Sha1Hash();
            sha.Update(A);
            sha.Update(files_crc);
            byte[] crc_hash = sha.Final();

            PacketOut packet = new PacketOut(LogonServerOpCode.AUTH_LOGON_PROOF);
            packet.Write(A); // 32 bytes
            packet.Write(M); // 20 bytes
            packet.Write(crc_hash); // 20 bytes
            packet.Write((byte)0); // number of keys
            packet.Write((byte)0); // unk (1.11.x)
            Send(packet);
        }
Пример #10
0
        public void DoAuthSession()
        {
            try
            {
                PacketOut packet = new PacketOut(WorldServerOpCode.CMSG_AUTH_SESSION);

                Sha1Hash sha = new Sha1Hash();
                sha.Update(mUsername);
                sha.Update(new byte[4]); // t
                sha.Update(ClientSeed);
                sha.Update(ServerSeed);
                sha.Update(mKey);

                byte[] Digest = sha.Final();

                packet.Write((UInt32)Config.Version.build);
                packet.Write((UInt32)0);
                packet.Write(mUsername);
                packet.Write((UInt32)0);
                packet.Write(ClientSeed);
                packet.Write((UInt64)0);
                packet.Write(Digest);

                bool WantToCrash = false;
                if (WantToCrash)
                {
                    byte[] addons = { (byte)0x00 };
                    byte[] buffer2 = mClient.Shared.Compression.Compress(addons);
                    UInt32 Size = (UInt32)addons.Length;
                    packet.Write(Size);
                    packet.Write(buffer2);

                }
                else
                {
                    byte[] addon_data = { 0x56, 0x01, 0x00, 0x00, 0x78, 0x9c, 0x75, 0xcc, 0xbd, 0x0e, 0xc2, 0x30, 0x0c, 0x04, 0xe0, 0xf2, 0x1e, 0xbc, 0x0c, 0x61, 0x40, 0x95, 0xc8, 0x42, 0xc3, 0x8c, 0x4c, 0xe2, 0x22, 0x0b, 0xc7, 0xa9, 0x8c, 0xcb, 0x4f, 0x9f, 0x1e, 0x16, 0x24, 0x06, 0x73, 0xeb, 0x77, 0x77, 0x81, 0x69, 0x59, 0x40, 0xcb, 0x69, 0x33, 0x67, 0xa3, 0x26, 0xc7, 0xbe, 0x5b, 0xd5, 0xc7, 0x7a, 0xdf, 0x7d, 0x12, 0xbe, 0x16, 0xc0, 0x8c, 0x71, 0x24, 0xe4, 0x12, 0x49, 0xa8, 0xc2, 0xe4, 0x95, 0x48, 0x0a, 0xc9, 0xc5, 0x3d, 0xd8, 0xb6, 0x7a, 0x06, 0x4b, 0xf8, 0x34, 0x0f, 0x15, 0x46, 0x73, 0x67, 0xbb, 0x38, 0xcc, 0x7a, 0xc7, 0x97, 0x8b, 0xbd, 0xdc, 0x26, 0xcc, 0xfe, 0x30, 0x42, 0xd6, 0xe6, 0xca, 0x01, 0xa8, 0xb8, 0x90, 0x80, 0x51, 0xfc, 0xb7, 0xa4, 0x50, 0x70, 0xb8, 0x12, 0xf3, 0x3f, 0x26, 0x41, 0xfd, 0xb5, 0x37, 0x90, 0x19, 0x66, 0x8f };
                    packet.Write(addon_data);
                }

                Send(packet);

                mCrypt = new PacketCrypt(mKey);
                mCrypt.Init();
            }
            catch (Exception e)
            {
                Log.WriteLine(LogType.Error, e.StackTrace);
            }
        }