예제 #1
0
        public void crack(byte[] receive, byte[] send, out string Hash, out string Seed, out string DBUser)
        {
            Hash = ""; Seed = ""; DBUser = "";
            if (receive == null)
            {
                return;
            }
            if (send == null)
            {
                return;
            }

            try
            {
                MemoryStream ms     = new MemoryStream(receive);
                MySqlStream  stream = new MySqlStream(ms, _Codec);

                // read off the welcome packet and parse out it's values
                stream.OpenPacket();
                int       protocol       = stream.ReadByte();
                string    versionString  = stream.ReadString();
                DBVersion version        = DBVersion.Parse(versionString);
                int       threadId       = stream.ReadInteger(4);
                string    encryptionSeed = stream.ReadString();

                int serverCaps = 0;
                if (stream.HasMoreData)
                {
                    serverCaps = stream.ReadInteger(2);
                }
                if (version.isAtLeast(4, 1, 1))
                {
                    /* New protocol with 16 bytes to describe server characteristics */
                    int serverCharSetIndex = stream.ReadInteger(1);

                    int serverStatus = stream.ReadInteger(2);
                    stream.SkipBytes(13);
                    string seedPart2 = stream.ReadString();
                    encryptionSeed += seedPart2;
                }
                stream.Close();
                ms.Close();
                ms.Dispose();

                if (version.isAtLeast(4, 1, 1))
                {
                    string msg = _Codec.GetString(send);
                    int    i   = msg.IndexOf("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
                    if (i != -1)
                    {
                        string user = msg.Remove(0, i + 23);
                        i = user.IndexOf('\0');
                        string hash1 = user.Remove(0, i + 1);
                        if (hash1 == "\0")
                        {
                            hash1 = "";
                        }
                        user = user.Substring(0, i);
                        //CLIENT:  recv(public_seed)
                        //         hash_stage1=sha1("password")
                        //         hash_stage2=sha1(hash_stage1)
                        //         reply=xor(hash_stage1, sha1(public_seed,hash_stage2)
                        //         send(reply)
                        //SERVER:  recv(reply)
                        //         hash_stage1=xor(reply, sha1(public_seed,hash_stage2))
                        //         candidate_hash2=sha1(hash_stage1)
                        //         check(candidate_hash2==hash_stage2)
                        Seed   = StringToHex(encryptionSeed, true);
                        Hash   = StringToHex(hash1.Substring(0, 21), true);
                        DBUser = user;
                    }
                }
                else
                {
                    throw (new Exception("MYSQL ERROR VERSION INCOMPATIBLE, MUST BE >4.1.1"));
                }
            }
            catch { }
        }
예제 #2
0
        public void crack(byte[] receive, byte[] send, out string Hash, out string Seed, out string DBUser)
        {
            Hash = ""; Seed = ""; DBUser = "";
            if (receive == null) return;
            if (send == null) return;

            try
            {
                MemoryStream ms = new MemoryStream(receive);
                MySqlStream stream = new MySqlStream(ms, _Codec);

                // read off the welcome packet and parse out it's values
                stream.OpenPacket();
                int protocol = stream.ReadByte();
                string versionString = stream.ReadString();
                DBVersion version = DBVersion.Parse(versionString);
                int threadId = stream.ReadInteger(4);
                string encryptionSeed = stream.ReadString();

                int serverCaps = 0;
                if (stream.HasMoreData) serverCaps = stream.ReadInteger(2);
                if (version.isAtLeast(4, 1, 1))
                {
                    /* New protocol with 16 bytes to describe server characteristics */
                    int serverCharSetIndex = stream.ReadInteger(1);

                    int serverStatus = stream.ReadInteger(2);
                    stream.SkipBytes(13);
                    string seedPart2 = stream.ReadString();
                    encryptionSeed += seedPart2;
                }
                stream.Close();
                ms.Close();
                ms.Dispose();

                if (version.isAtLeast(4, 1, 1))
                {
                    string msg = _Codec.GetString(send);
                    int i = msg.IndexOf("\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
                    if (i != -1)
                    {
                        string user = msg.Remove(0, i + 23);
                        i = user.IndexOf('\0');
                        string hash1 = user.Remove(0, i + 1);
                        if (hash1 == "\0") hash1 = "";
                        user = user.Substring(0, i);
                        //CLIENT:  recv(public_seed)
                        //         hash_stage1=sha1("password")
                        //         hash_stage2=sha1(hash_stage1)
                        //         reply=xor(hash_stage1, sha1(public_seed,hash_stage2)
                        //         send(reply)
                        //SERVER:  recv(reply)
                        //         hash_stage1=xor(reply, sha1(public_seed,hash_stage2))
                        //         candidate_hash2=sha1(hash_stage1)
                        //         check(candidate_hash2==hash_stage2)                            
                        Seed = StringToHex(encryptionSeed, true);
                        Hash = StringToHex(hash1.Substring(0, 21), true);
                        DBUser = user;
                    }
                }
                else
                {
                    throw (new Exception("MYSQL ERROR VERSION INCOMPATIBLE, MUST BE >4.1.1"));
                }
            }
            catch { }
        }