Showing posts with label CrackMe 1. Show all posts
Showing posts with label CrackMe 1. Show all posts

Friday, April 24, 2009

CrackMe #1 Ver.2.00 :: C++ :: Difficulty : 2

KeyGenMe Location : CrackMe #1 Ver.2.00 @ Crackmes.de
Solution Location : Not Solved Yet

So, here is my first CrackMe. It's coded in ANSI C++. Features :
(*) NOT Packed
(*) NOT Encrypted
(*) Nice Konsole look with Double Sided Arrow Animation.

The Rules :
(*) NO Patching
(*) NO Brute-forcing

The Tasks :
1. a) Find the secret code that would pass security phase 1.
b) Find the secret code that would pass security phase 2.
2. Reverse the complete algorithm for checking the code.
3. Write a descent tutorial.

Readers, if you solve this, please upload your solution to CrackMes.de.

Tuesday, April 21, 2009

How To #1 :: Flushing input stream in C++

As I was telling in my last post (CrackMe #1), the solution by DoomsDay forced me to re-check my code for errors. I had not expected negative numbers to be valid secret codes. I had implemented the following method to reject the negative numbers from Test #1 itself. See the code below :
ReEnterCode:
XXXXInKey = getchar();
XXXXwhile( InKey != '\n' )
XXXX{
XXXXXXXXif( ( InKey >= '0' ) && ( InKey <= '9' ) )
XXXXXXXX{
XXXXXXXXXXXX// Key gets accepted and stored
XXXXXXXX}
XXXXXXXXelse
XXXXXXXXXXXXgoto ReEnterCode;

XXXXXXXInKey = getchar();XXXXXXXX// Get the next key from user
XXXX}
XXXXprintf("Test #1 : PASSED");


At first sight of the code, everything seems OK. Gets a char from user, checks if it's a digit. If it is, accepts it; else prompts user for Re-Input. But, this code fails.

Lets see why. Let's analyze for input -8.
Program receives '-'. Does not accept it. Goes to the label ReEnterCode.
There, it gets the next instruction : InKey = getchar();
And what's the next char ? '8'.
So, it continues execution with '8', which gets accepted later.

The problem occurs because the input stream is not flushed before jumping to ReEnterCode. It can be solved this way :
ReEnterCode:
XXXXInKey = getchar();
XXXXwhile( InKey != '\n' )
XXXX{
XXXXXXXXif( ( InKey >= '0' ) && ( InKey <= '9' ) )
XXXXXXXX{
XXXXXXXXXXXX// Key gets accepted and stored
XXXXXXXX}

XXXXXXXXelse
xxxxxxxx{
xxxxxxxxxxxxwhile( ( (InKey = getchar()) != '\n' ) || InKey != EOF );
XXXXXXXXXXXXgoto ReEnterCode;
xxxxxxxx}

XXXXXXXInKey = getchar();XXXXXXXX// Get the next key from user
XXXX}
XXXXprintf("Test #1 : PASSED");


I uploaded Ver.2.00 of CrackMe #1 with this problem corrected.