All writeups
Reverse engineeringEasyKarak Studio practice files

First sip: reading a password check

A beginner crackme solved by reading strings, following a cross-reference and reading the check in C. No guessing, no patching.

Karak Studio#crackme#strings#x64#windows

Spoiler: this reveals the password for First sip, the first practice crackme that ships with Karak Studio. Try it yourself first if you want the fun of solving it.

The challenge

first-sip.exe is a 64-bit Windows command-line program. It asks for a password and prints Correct! Well done. or Wrong. Try again. The goal is to find the password without running it.

File first-sip.exe, 13,824 bytes
Type PE, 64-bit x86, console
Functions 56
Imports 40

1. Triage

The first look is always the same: what is this file, and what can it do?

The imports list ReadFile, WriteFile and VirtualProtect. That sounds like a lot for a password prompt, but a console program reads the keyboard and writes to the screen through ReadFile and WriteFile, and VirtualProtect comes from the MinGW start-up code the compiler adds. Nothing here is the author’s own idea.

Lesson: an import tells you what a program can do. You still have to work out why it is there.

2. Strings

61 readable strings, and the first six are the program’s own:

karak-chai
Wrong. Try again.
Correct! Well done.
Press Enter to close.
First sip
Password:

Everything after them (Argument domain error, Mingw-w64 runtime failure, …) is compiler boilerplate. Two of the six are obviously messages. One is not a message at all: karak-chai. Worth remembering.

3. Follow the “Wrong” message

The standard move: take a string you recognise and find the code that uses it.

Wrong. Try again. has exactly one cross-reference, inside sub_1400014C6. Decompiled:

void sub_1400014C6(i64 arg1)
{
sub_140001481((u8)arg1 != 0 ? "Correct! Well done." : "Wrong. Try again.", ...);
sub_140001481("Press Enter to close.", 0x17);
...
ExitProcess((u8)((u8)arg1 ^ 1));
}

This function does not decide anything. It is handed a verdict (arg1, non-zero means correct) and prints the matching message. Renamed: report_result, and sub_140001481 becomes print.

4. Walk up to the caller

report_result has one caller, the entry point:

void entry_point()
{
...
print("First sip", 0x15);
v1 = sub_140001525(&var_48, 0x40);
v2 = sub_140001432(&var_48, v1);
report_result(v2);
}

Read it as a story. Fill a 64-byte buffer and get a length (read_line). Pass the buffer and the length to a function that returns the verdict. That function, sub_140001432, is the password check.

5. Read the check

if (arg2 != 0xA) {
v1 = 0; // wrong length: fail
}
var_8 = "karak-chai";
v5 = 0;
do {
v1 = arg1[v5] == v2[v5];
if (arg1[v5] != v2[v5]) {
break; // first mismatch: fail
}
...
v5++;
} while (v6);

Two conditions:

  1. The input length (arg2) must be 0xA, which is 10.
  2. Every character must match the stored string, compared one byte at a time.

karak-chai is exactly 10 characters. The control-flow graph agrees: one length test, then one loop with a back edge.

6. Confirm in the bytes

The string sits at 0x140004000. In the hex view:

6B 61 72 61 6B 2D 63 68 61 69 00 karak-chai.

Ten bytes and a null terminator, stored in plain text where anyone can read it.

Answer

The password is karak-chai.

Takeaways

  • Separate the program from its compiler. Most strings and imports in a small binary are runtime boilerplate.
  • Strings → cross-reference → caller finds the decision in almost any check-the-input program.
  • Name things as soon as you understand them. Every rename makes the next function easier to read.
  • Plain-text comparisons are the weakest kind of check. The next practice files hide the password and add arithmetic, which is where it gets interesting.