Table of Contents
IronForgeCyber
Courses
Resources
Blog
Log In


IronForgeCyber

AboutPrivacyTerms

© 2026 IronForgeCyber. All rights reserved.

  1. courses
  2. re-static-analysis
  3. crackme-03
5 min read

Crackme 3: Chained

A stripped binary that wants a flag:

chall
$ echo hello | ./challFlag: Nope.

The flag is not stored in the file. Something derived from it is. Recover the flag.

Try it yourself first
The solution is below. Open the binary and work at it before reading on.

Stuck? Open one hint at a time.

Hint 1
Find main and look at what happens to your input between the read and the memcmp. The length check tells you how long the flag is.
Hint 2
The encoding function looks each byte up in a 256-byte table. A lookup table can be reversed if every entry in it is different: build a second table that maps each value back to its position.
Hint 3
Each byte is combined with something before the lookup. Check carefully what that something is: it is not the previous output.
Hint 4
Decode from left to right. Once you know the first character of the flag, you have what you need for the second.

Solution

The Check

entry gives us main at FUN_0040051b. The part that matters:

Ghidra
1    sVar4 = strlen(local_48);
2    if (sVar4 == 0x18) {
3      FUN_004004b6(local_48,

The input must be 0x18 characters, which is 24. It is passed through FUN_004004b6 and then compared with 24 bytes at DAT_00401400. This is an encoded check, as in Obfuscation: modify, then compare. Rename the function encode and the data target.

The Encoding

Ghidra
1void FUN_004004b6(long param_1,ulong param_2)
2{
3  byte bVar1;
4  ulong local_18;

Go through one trip of the loop:

  1. bVar1 is the input byte at this position, saved before anything changes it.
  2. It is XORed with local_9, and the result is used as an index into a table at DAT_00401300. The value found there replaces the input byte.
  3. local_9 is set to bVar1, the original input byte, for the next trip.

local_9 starts at 0x42. So, calling the table sbox:

out[0] = sbox[in[0] ^ 0x42]
out[i] = sbox[in[i] ^ in[i - 1]]

Each output byte depends on the input byte at that position and the one before it. That is the difference from the Obfuscation lesson, and it closes the shortcut that lesson offered. You cannot solve position 10 alone, because you need to know the flag's ninth character to do it.

A table used this way is called a substitution box. It runs from 0x401300 up to 0x401400, where target starts, so it has 256 entries, one for every possible byte.

Inverting It

Two steps were applied: an XOR, then a table lookup. Undo them in reverse order.

The lookup is reversible if no value appears in the table twice, because then each output could only have come from one index. Build an inverse table by going through sbox and recording, for each value, the index it was found at. If the table had repeats, the inverse would have gaps, and a script will show that at once.

With the inverse table, inverse[out[i]] gives back in[i] ^ in[i - 1]. XOR that with in[i - 1] and in[i] is left. For the first byte, the "previous" value is 0x42. After that it is the character we just decoded. So the flag has to be recovered in order, from the left.

The Script

Both tables are in the file, and the script can read them straight from it. This binary is not position-independent and loads at 0x400000, so an address like 0x401300 is at offset 0x1300 in the file:

solve.py
1data = open("chall", "rb").read()
2sbox = data[0x1300:0x1400]
3
$ python3 solve.pyIFC{ch41n3d_t0_th3_l4st}$ python3 solve.py | ./challFlag: Correct!

The first few characters coming out as IFC{ is the sign that every piece is right: the table, its inverse, the starting value and the order. If the output were garbage from the first byte, the starting value or the table would be wrong. If it began well and then fell apart, the chaining would be.

Next is Crackme 4, the last and the hardest.

0x18
)
;
4 iVar1 = memcmp(local_48,&DAT_00401400,0x18);
5 if (iVar1 == 0) {
6 puts("Correct!");
7 }
5
byte local_9
;
6
7 local_9 = 0x42;
8 for (local_18 = 0; local_18 < param_2; local_18 = local_18 + 1) {
9 bVar1 = *(byte *)(local_18 + param_1);
10 *(undefined *)(local_18 + param_1) = (&DAT_00401300)[(int)(uint)(bVar1 ^ local_9)];
11 local_9 = bVar1;
12 }
13 return;
14}
target
=
data
[
0x1400
:
0x1418
]
4
5inverse = [0] * 256
6for index, value in enumerate(sbox):
7 inverse[value] = index
8
9flag = ""
10prev = 0x42
11for byte in target:
12 plain = inverse[byte] ^ prev
13 flag += chr(plain)
14 prev = plain
15
16print(flag)