Finding a Serial Key in a Binary and Patching It
Today we’ll analyze a simple crackme from crackinglessons.com – Crackme #1
Objective
- Identify the correct serial key.
- Patch the binary so it always displays the “Congrats!” message when the Check button is clicked.
Understanding the Program Behavior
When we run the program, it asks:
“Please enter the serial key”
If we enter an incorrect value, a message box appears:
“Wrong serial key. Try again.”
So our first goal is simple: find where that message is triggered and trace backward to locate the comparison logic.
Locating the Failure Message
Using x64dbg, we search for the string:
| |
This leads us to address:
| |
Scrolling up from that location reveals the surrounding control flow. We can see two clear branches:
- One path pushes
"Congrats!"and"Well done!" - The other pushes
"Sorry"and"Wrong serial key. Try again."
That means somewhere above this section, the program performs a comparison and decides which message to display.
Here is the critical portion:
| |
This is where things get interesting.
Identifying the Hardcoded Serial
At address:
| |
Looking at the memory at 411AD8, we see:
| |
That means:
ECX→ points to the hardcoded correct serialEAX→ points to the user input buffer ([ebp-30])
Immediately after that, we see:
| |
This is a classic byte-by-byte string comparison.
Understanding the Comparison Loop
The program compares:
| |
It does this two bytes at a time:
| |
What this means:
- If any character differs -> jump to failure
- If the null terminator is reached and all bytes matched -> success
This is like:
| |
So the valid serial key is:
| |
Entering this value results in:
Congrats! Well done!
The crackme is now solved.
Patching the Binary
Now for the second objective: make it always show “Congrats!” regardless of input.
We look at this conditional jump:
| |
Interpretation:
eax == 0→ correct serialeax != 0→ wrong serial
The jne instruction jumps to the failure message.
Patch Strategy
We can modify:
| |
Into:
| |
or change it to:
| |
This forces execution to always continue to the success block.
After patching and saving the binary, clicking Check will always display:
- Congrats!
- Well done!
Even with incorrect input.