This one is stripped and built with optimization. It guards a row of lockers:
printf '104\n1234\n' | ./challLocker number: Combination: Access denied.One of the lockers is not a locker. Make the program print The vault is open.
Stuck? Open one hint at a time.
main from the entry point. If the address Ghidra shows there is a label and not a function, click it and press F to create one..rodata and find where the records start and how long each one is.mainThe binary is stripped, so we start at entry:
1void processEntry entry(undefined8 param_1,undefined8 param_2,undefined1 param_3)
2{
3 undefined1 auStack_8 [8];
4
The first argument to __libc_start_main is main, as always, but here Ghidra shows &LAB_004003a0, a label, where earlier binaries had a FUN_ name. Ghidra's analysis did not mark the code at that address as a function. This happens now and then, and the fix is one key: double-click the label, then press F in the Listing to create a function there. The Decompiler fills in.
main1 uVar2 = 0;
2 do {
3 if ((ushort)(&Before this, two scanf calls fill auStack_10[0] with the locker number and auStack_10[1] with the combination. Then there is a loop that runs five times, and inside it everything is an offset from DAT_00401280. This is the pattern from Data & Types: a table of structs, accessed by pointer arithmetic.
Work out the layout from how each offset is used. The loop index is multiplied by 0x10, so each record is 16 bytes.
| Offset | Address of the first one | Size | How it is used |
|---|---|---|---|
0x0 | 0x401280 | 2 | Compared with the locker number |
0x2 | 0x401282 | 2 | Compared with the combination, after an XOR |
0x4 | 0x401284 | 11 | Printed with %s |
0xf | 0x40128f | 1 | Decides between the two messages |
The name field shows up as "mallory" + lVar3, because Ghidra recognized the first record's name as a string and expressed the others as offsets from it. The last field is the one we care about. When it is zero, the program reports an empty locker. When it is not, the vault opens.
Now the two checks. The first compares the record's number with ours. The second is:
(ushort)((&DAT_00401280)[uVar2 * 8] ^ (ushort)auStack_10[1]) == *(ushort *)(The record's number is XORed with the combination we typed, and the result must equal the second field. Written out: number ^ combination == stored. XOR undoes itself, so combination == stored ^ number.
The table is constant data, so it is in the file:
objdump -s -j .rodata chall | tail -n 5 401280 68003a1f 6d616c6c 6f727900 00000000 h.:.mallory..... 401290 d900c170 7472656e 74000000 00000000 ...ptrent....... 4012a0 5601e74b 70656767 79000000 00000001 V..Kpeggy....... 4012b0 ca01d029 76696374 6f720000 00000000 ...)victor...... 4012c0 3102a566 77616c74 65720000 00000000 1..fwalter......Five rows of 16 bytes, one per record, each with a name in the middle. Look at the last byte of each row. Four end in 00. The row for peggy ends in 01. That is the vault.
Its first four bytes are 5601 e74b. Both fields are 2-byte numbers stored little-endian, so the locker number is 0x0156 and the stored value is 0x4be7:
echo $((0x156)) $((0x4be7 ^ 0x156))342 19121printf '342\n19121\n' | ./challLocker number: Combination: The vault is open.Nothing in the program's output ever mentions locker 342 or hints that one locker is special. The only way to learn it is from the data.
Next is Crackme 3, where the answer is not stored anywhere.