Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C++ Simple Algorithm To Crack CRC32 Hashes

This algorithm bruteforces the entire keyspace of input strings, hashing them with CRC32 algorithm and comparing it to the target hash. If target hash matches the created hash, a collision is logged.

Now this algorithm is really just a proof of concept, and won't be useful in most cases. But it can be useful to nail down possible password hashes, or something like that.
Project on Github: https://github.com/Zer0Memory/CrackCRC32

Code
#include <iostream>
#include <string>

#include <Windows.h>

#include "CRC.h"

using namespace std;

//
string numerals = "0123456789";
string alphabetLower = "abcdefghijklmnopqrstuvwxyz";
string alphabetUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string specialAnsi = "!\"#¤%&/()=?`^¨*';:_,.";


void CrackHash(string source, unsigned int hash, string seed, size_t length)
{
    // this is used to measure time
    static const int startTick = GetTickCount64();

    static int iterations; // store the count of iterations
    static int collisions; // store the count of collisions/hash

    iterations++; // increment iteration count each time function is executed.

    if (length == 0) // if the length is reached
    {
        if (CRC32(seed.c_str(), seed.length()) == hash) // if the hash created from seed matches the input
        {
            // calculate the time the operation took
            double endTick = GetTickCount64() - startTick;
            collisions++; // increment collisions

            cout << "Collision #" << collisions << ", Source: " << seed << ", Hash: 0x" << StrCRC32(seed)
                 << ", Iterations: " << iterations << endl << "Ticks: " << endTick << ", Seconds: "
                 << endTick / 1000 << ", Minutes: " << endTick / 1000 / 60 << ", Hours: " << endTick / 1000 / 60 / 60;
            cout << endl << endl;
        }
        return;
    }

    // loop through the provided characters
    for (size_t i = 0; i < source.length(); i++)
    {
        string appended = seed + source[i];

        CrackHash(source, hash, appended, length - 1);
    }
}


int main()
{
    // our target hash is 'test' hashed
    unsigned int targetHash = 0xd87f7e0c;
    //cout << "CRC32 hash of 'test' is: " << StrCRC32("test") << endl;
    //cin.get();

    // now let's try to crack the hash of test
    while (1)
    {
        // the length of string that the algorithm starts from
        static unsigned int strlen = 1;
        CrackHash(alphabetLower + alphabetUpper + numerals + specialAnsi, targetHash, "", strlen);
        strlen++;
    }
}


Possibly Related Threads...
Thread / Author Replies Views Last Post
by WakeJul 3, 2019 12:58 PM 7 397 Jul 3, 2019 12:58 PM
Last Post: Last_viking
by DrBrxdAug 25, 2015 12:21 PM 3 260 Aug 25, 2015 12:21 PM
Last Post: Cirdica
by ZerFallenMar 22, 2014 07:48 PM 7 265 Mar 22, 2014 07:48 PM
Last Post: ZerFallen