Guessing Pro
2 files available
Description
The title says "Pro", but this is a baby challenge. Everybody likes guessing after all.
Solution
This is a baby-level heap challenge that has a double free vulnerability, which allows an attacker to get two references to the same chunk in different variables.
A menu with few options is shown:
- Take a guess
- Confirm guess
- Delete guess
- Generate new value
- Exit
By inspecting the binary, it can be seen that if "Delete guess" is chosen, a
free
is executed without any check, so here lies the most straightforward way
to exploit the binary. Moreover, the libc
used by the binary is version 2.27,
which is vulnerable to double free attacks.
The function profit
, if called, prints the flag, and this happens if the user
is able to "guess" a value that gets randomly generated.
The random value gets allocated on the heap with a malloc(50)
, but 50 is also
the same size that gets allocated to store the current guess. So that means that
the random value and the guess end up in the same heap bin.
With this knowledge, the following steps allow to win the guessing game:
- Take a guess, allocating a chunk that will be freed
- Delete the guess twice
- Generate a new value, so the chunk that was freed twice gets re-allocated
- Take a new guess, and since
malloc
is called, the input is actually being written in the same chunk where the random value was stored - Confirm the guess. At this point, the pointers to the guess and random value
are pointing to the same address, so the equality check passes and
profit
gets called