13.8 — Project: make and crack your own crackme

📘 Chapter 13⏱ about 4 min read✍️ Beginner friendly
Read one box at a time. No rush.

A crackme is a small program that asks for a secret, made on purpose to be reversed. Let's make our own and crack it in three levels.

Level 1: the password in plain sight#

C++▶ Run
#include <iostream>#include <string> int main(){    std::cout << "Password: ";    std::string guess {};    std::cin >> guess;     if (guess == "c0ffee42")        std::cout << "Access granted!\n";    else        std::cout << "Wrong password.\n";    return 0;}

Compile it, then pretend you've forgotten the password. Run strings on the program:

text
strings ./crackme1
Output
...Password:c0ffee42Access granted!Wrong password....

Cracked in one second! The password sits right next to the messages.

Key idea

Never store secrets as plain text inside a program. Anyone can read them.

Level 2: hide the password#

Let's store the password scrambled with XOR (^), so strings can't see it:

C++▶ Run
#include <iostream>#include <string> // "c0ffee42" with every byte XOR-ed with 0x5Aconstexpr unsigned char hidden[] { 0x39, 0x6a, 0x3c, 0x3c, 0x3f, 0x3f, 0x6e, 0x68 };constexpr unsigned char key { 0x5A }; bool check(const std::string& guess){    if (guess.size() != sizeof(hidden))        return false;    for (std::size_t i { 0 }; i < guess.size(); ++i)    {        if ((static_cast<unsigned char>(guess[i]) ^ key) != hidden[i])            return false;    }    return true;} int main(){    std::cout << "Password: ";    std::string guess {};    std::cin >> guess;     if (check(guess))        std::cout << "Access granted!\n";    else        std::cout << "Wrong password.\n";    return 0;}
XOR

A bit operation (^ in C++). Doing x ^ key scrambles a byte, and doing ^ key again un-scrambles it. Simple to use, but also simple to undo once you spot it.

Now strings shows the messages, but not the password. Time for real tools.

Level 3: crack it with Ghidra#

  1. Open the program in Ghidra and find main.
  2. The decompiler shows a call to a function that is checked before "Access granted!" — that's check (or an unnamed FUN_... if names were stripped).
  3. Open it. You'll find a loop that XORs each character with 0x5a and compares it to bytes in a table.
  4. Double-click the table to see its bytes: 39 6a 3c 3c 3f 3f 6e 68.
  5. XOR each one with 0x5a (by hand, or with a tiny C++ program) to get the password back.

Here's that tiny program:

C++▶ Run
#include <iostream> int main(){    const unsigned char hidden[] { 0x39, 0x6a, 0x3c, 0x3c, 0x3f, 0x3f, 0x6e, 0x68 };    for (unsigned char b : hidden)        std::cout << static_cast<char>(b ^ 0x5A);    std::cout << '\n';    return 0;}
Output
c0ffee42

Level 4: change the program's mind (patching)#

Instead of finding the password, you can change the program — this is called patching. Do this only on your own programs and crackmes.

  1. Open your program in x64dbg (Windows) or gdb (Linux).
  2. Find the string reference "Access granted!" and look just above it.
  3. You'll see the result of check being tested, then a conditional jump (je or jne) that skips to "Wrong password".
  4. Change that jump to the opposite one (or to nops). Save the patched copy.
  5. Now any password is accepted.
Key idea

This is why real software never trusts checks inside the program alone. Important checks (like licences or logins) must also happen on a server the user can't change.

Tip

Ideas to make your crackme harder: compute the key instead of storing it, check the length last, or split the check across several functions. Then swap with a friend and crack each other's!

Finished reading? Tick it off. Your progress is saved in this browser.

Tip: press ← / → to move between lessons, / to search.