Compiled
Strings can only help you so far. - by nerrorsec
Last updated
Strings can only help you so far. - by nerrorsec
Last updated
The following post by 0xb0b is licensed under CC BY 4.0
For this challenge, we get a compiled binary, which we have to analyze to find the flag. On the first attempt, we just used strings and got mocked that "Strings is for Noob"
, but we also got some other interesting printable strings like "Password"
, "DoYouEven%sCTF"
, "__dso_handle"
, "_init"
, "Correct!"
and "Try again!"
. Somewhere here lies the password, which will also be the flag.
The next step is to use Ghidra to analyze the source of the file.
We see that the program prompts the user for a password and checks if it matches the exact string "_init"
and is not equal to the string "__dso_handle"
. If the input meets these conditions, it prints "Correct!"
; otherwise, it prints "Try again!"
.
Let's check out the manpage of scanf
:
Recalling __isoc99_scanf("DoYouEven%sCTF",local_28);
we have to provide a string matching the ordinary character sequence "DoYouEven"
followed by an arbitrary sequence of characters "%s"
. The format requires ending with "CTF"
after the arbitrary sequence of characters. Meeting the correct input conditions to resolve to the value "_init"
implies the password.
Lets use a simple C program to check the behaviour of __isoc99_scanf
:
Matching failure, the input is empty because the directive fails and the input is not further processed:
We have a match without "CTF"
as an ending, by looking at the return value of scanf
we get a 1
. By recalling the manpage: "If processing of a directive fails, no further input is read, and scanf() returns" does this not appear to happen here. There is a successful match. Maybe %s
contradicts with the following sequence of ordinary characters after. However, now we know how to build our password to pass:
Running the provided binary on our machine with the correct password we get the desired respones: