Skip to the content ForoHackers
Log inJoin

Practice crackme: when the check is a XOR table, invert it, do not brute force it

Binary analysisCTFReverse engineering
#1107 · cr4ckm3_c4t · · Report

A beginner pattern worth recognising, from a crackme I wrote for myself. The validation function does this:

static const unsigned char want[11] = {
    0x15, 0x0a, 0x1f, 0x14, 0x77, 0x09, 0x1f, 0x09, 0x1b, 0x17, 0x1f
};

int check(const char *s) {
    for (int i = 0; i < 11; i++)
        if ((s[i] ^ 0x5a) != want[i])
            return 0;
    return s[11] == '\0';
}

In the disassembly you see a loop with xor eax, 0x5a, a cmp against bytes from a table in .rodata, and a counter up to 11. Do not run a brute force: each position is independent, and XOR is its own inverse. Just apply the same XOR to the table:

want = bytes([0x15,0x0a,0x1f,0x14,0x77,0x09,0x1f,0x09,0x1b,0x17,0x1f])
print(bytes(b ^ 0x5a for b in want).decode())

It prints the 11-character password. The general lesson: when the check is per character and reversible, you read the transformation and invert it. The checks that deserve a SAT solver or a debugger are the ones where every output byte depends on all the input bytes.

The cat, for the record, has not solved it. She sat on the keyboard and typed zzzzzzzzzzz. Eleven characters, wrong password, but I admire the length.

#1774 · hexdump_hermit · · Report

Find the table first: strings -t x will not show it (not printable), but a hex view of .rodata next to the function's lea will. Then the answer falls out in one line. Also look at the 12th byte compare, the terminator check. Beginners forget it and "solve" it with trailing garbage accepted.

#1775 · ArepaConAssembly · · Report

Muy didáctico. En los crackmes de práctica que he hecho, la cosa se complica cuando la clave de XOR cambia con el índice (0x5a + i, por ejemplo). Misma idea: se invierte con el mismo cálculo, solo hay que reproducir el índice.

Log in or join to reply.