C# for MySQL => 4.1.0 16 Byte

Is It 1? .... NO!
Is It 2? .... NO!
Is It 3? .... Bingo!
Admin
Site Admin
Posts: 955
Joined: Thu Aug 23, 2007 10:35 am

C# for MySQL => 4.1.0 16 Byte

Postby Admin » Tue Sep 17, 2013 8:13 pm

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace deleteMeSql
{
    class Program
    {
        static void Main(string[] args)
        {
            StartMain(null);
        }

        public List<string> GetAlphaLists(int iLimit)
        {
            List<string> _l = new List<string>();
            List<string> _AtoZ = new List<string>();
            int asciiStart = 65;
            int asciiEnd = 90;

            for (int i = asciiStart; i <= asciiEnd; i++)
            {
                _AtoZ.Add(((char)i).ToString());
            }

            for (int i = asciiStart; i <= asciiEnd; i++)
            {
                for (int j = 0; j < iLimit; j++)
                {
                    _l.Add(_AtoZ[j] + ((char)i).ToString());
                }
            }

            _l = _l.Union(_AtoZ).OrderBy(x => x).ToList();

            return _l;
        }

        public static string mysql_old_password(string sPassword)
        {
            UInt32[] result = new UInt32[2];
            bool bDebug = false;
            UInt32 nr = (UInt32)1345345333, add = (UInt32)7, nr2 = (UInt32)0x12345671;
            UInt32 tmp;

            char[] password = sPassword.ToCharArray();
            int i;

            for (i = 0; i < sPassword.Length; i++)
            {
                if (password[i] == ' ' || password[i] == '\t')
                    continue;

                tmp = (UInt32)password[i];
                nr ^= (((nr & 63) + add) * tmp) + (nr << 8);
                nr2 += (nr2 << 8) ^ nr;
                add += tmp;
            }

            result[0] = nr & (((UInt32)1 << 31) - (UInt32)1);
            UInt32 val = (((UInt32)1 << 31) - (UInt32)1);
            result[1] = nr2 & val;
            string hash = String.Format("{0:X}{1:X}", result[0], result[1]);
            return hash.ToLower();
        }

        public static IEnumerable<string> GetAlphabetCollection()
        {
            const string alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
            int length = 0;
            char[] chars = null;
            int[] indexes = null;
            while (true)
            {
                int position = length - 1;
                // Try to increment the least significant
                // value.
                while (position >= 0)
                {
                    indexes[position]++;
                    if (indexes[position] == alphabet.Length)
                    {
                        for (int i = position; i < length; i++)
                        {
                            indexes[i] = 0;
                            chars[i] = alphabet[0];
                        }
                        position--;
                    }
                    else
                    {
                        chars[position] = alphabet[indexes[position]];
                        break;
                    }
                }
                // If we got all the way to the start of the array,
                // we need an extra value
                if (position == -1)
                {
                    length++;
                    chars = new char[length];
                    indexes = new int[length];
                    for (int i = 0; i < length; i++)
                    {
                        chars[i] = alphabet[0];
                    }
                }
                yield return new string(chars);
            }
        }

        #region Private variables

        // the secret password which we will try to find via brute force
        private static string password = "MYSQL PASSWORD HASH HERE";
        private static string result;

        private static bool isMatched = false;

        /* The length of the charactersToTest Array is stored in a
         * additional variable to increase performance  */
        private static int charactersToTestLength = 0;
        private static long computedKeys = 0;

        /* An array containing the characters which will be used to create the brute force keys,
         * if less characters are used (e.g. only lower case chars) the faster the password is matched  */
        private static char[] charactersToTest =
    {
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
        'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
        'u', 'v', 'w', 'x', 'y', 'z','A','B','C','D','E',
        'F','G','H','I','J','K','L','M','N','O','P','Q','R',
        'S','T','U','V','W','X','Y','Z','1','2','3','4','5',
        '6','7','8','9','0','!','$','#','@','-'
    };

        #endregion

        static void StartMain(string[] args)
        {
            var timeStarted = DateTime.Now;
            Console.WriteLine("Started - {0}", timeStarted.ToString());

            // The length of the array is stored permanently during runtime
            charactersToTestLength = charactersToTest.Length;

            // The length of the password is unknown, so we have to run trough the full search space
            var estimatedPasswordLength = 0;

            while (!isMatched)
            {
                /* The estimated length of the password will be increased and every possible key for this
                 * key length will be created and compared against the password */
                estimatedPasswordLength++;
                startBruteForce(estimatedPasswordLength);
            }

            Console.WriteLine("Password matched. - {0}", DateTime.Now.ToString());
            Console.WriteLine("Time passed: {0}s", DateTime.Now.Subtract(timeStarted).TotalSeconds);
            Console.WriteLine("Resolved password: {0}", result);
            Console.WriteLine("Computed keys: {0}", computedKeys);

            Console.ReadLine();
        }


        /// <summary>
        /// Starts the recursive method which will create the keys via brute force
        /// </summary>
        /// <param name="keyLength">The length of the key</param>
        private static void startBruteForce(int keyLength)
        {
            var keyChars = createCharArray(keyLength, charactersToTest[0]);
            // The index of the last character will be stored for slight perfomance improvement
            var indexOfLastChar = keyLength - 1;
            createNewKey(0, keyChars, keyLength, indexOfLastChar);
        }

        /// <summary>
        /// Creates a new char array of a specific length filled with the defaultChar
        /// </summary>
        /// <param name="length">The length of the array</param>
        /// <param name="defaultChar">The char with whom the array will be filled</param>
        /// <returns></returns>
        private static char[] createCharArray(int length, char defaultChar)
        {
            return (from c in new char[length] select defaultChar).ToArray();
        }

        /// <summary>
        /// This is the main workhorse, it creates new keys and compares them to the password until the password
        /// is matched or all keys of the current key length have been checked
        /// </summary>
        /// <param name="currentCharPosition">The position of the char which is replaced by new characters currently</param>
        /// <param name="keyChars">The current key represented as char array</param>
        /// <param name="keyLength">The length of the key</param>
        /// <param name="indexOfLastChar">The index of the last character of the key</param>
        private static void createNewKey(int currentCharPosition, char[] keyChars, int keyLength, int indexOfLastChar)
        {
            var nextCharPosition = currentCharPosition + 1;
            // We are looping trough the full length of our charactersToTest array
            for (int i = 0; i < charactersToTestLength; i++)
            {
                /* The character at the currentCharPosition will be replaced by a
                 * new character from the charactersToTest array => a new key combination will be created */
                keyChars[currentCharPosition] = charactersToTest[i];

                // The method calls itself recursively until all positions of the key char array have been replaced
                if (currentCharPosition < indexOfLastChar)
                {
                    createNewKey(nextCharPosition, keyChars, keyLength, indexOfLastChar);
                }
                else
                {
                    // A new key has been created, remove this counter to improve performance
                    computedKeys++;

                    /* The char array will be converted to a string and compared to the password. If the password
                     * is matched the loop breaks and the password is stored as result. */
                    if (mysql_old_password((new String(keyChars))) == password)
                    {
                        if (!isMatched)
                        {
                            isMatched = true;
                            result = new String(keyChars);
                        }
                        return;
                    }
                }
            }
        }
    }
}

Admin
Site Admin
Posts: 955
Joined: Thu Aug 23, 2007 10:35 am

Re: C# for MySQL => 4.1.0 16 Byte

Postby Admin » Tue Sep 24, 2013 11:05 pm

http://www.nitrxgen.net/hashgen/

Code: Select all

using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
using System.Diagnostics;

namespace CSharpMySqlHash
{
    class Program
    {

        static void Main(string[] args)
        {
            Debug.WriteLine(GenerateMySQLHash("password"));
            Debug.WriteLine(mysql_old_password("password"));
        }

        public static string GenerateMySQLHash(string key)
        {
            byte[] keyArray = Encoding.UTF8.GetBytes(key);
            SHA1Managed enc = new SHA1Managed();
            byte[] encodedKey = enc.ComputeHash(enc.ComputeHash(keyArray));
            StringBuilder myBuilder = new StringBuilder(encodedKey.Length);

            foreach (byte b in encodedKey)
                myBuilder.Append(b.ToString("X2"));

            return "*" + myBuilder.ToString();
        }

        static string mysql_old_password(string sPassword)
        {
            UInt32[] result = new UInt32[2];
            bool bDebug = false;
            UInt32 nr = (UInt32)1345345333, add = (UInt32)7, nr2 = (UInt32)0x12345671;
            UInt32 tmp;

            char[] password = sPassword.ToCharArray();
            int i;

            for (i = 0; i < sPassword.Length; i++)
            {
                if (password[i] == ' ' || password[i] == '\t')
                    continue;

                tmp = (UInt32)password[i];
                nr ^= (((nr & 63) + add) * tmp) + (nr << 8);
                nr2 += (nr2 << 8) ^ nr;
                add += tmp;
            }

            result[0] = nr & (((UInt32)1 << 31) - (UInt32)1);
            UInt32 val = (((UInt32)1 << 31) - (UInt32)1);
            result[1] = nr2 & val;
            string hash = String.Format("{0:X}{1:X}", result[0], result[1]);
            return hash.ToLower();
        }
    }
}


Return to “Brute Forcing”

Who is online

Users browsing this forum: No registered users and 1 guest