Backdoor CTF 2015 team Writeup
TL;DR
- Format string
Given that this challenge was 600 points, I expected to be challenged with this one. But with 91 solves I think the people at SDSLabs kinda messed up on the points for this one lol.
Checking out what type of file we were dealing with here:
Alright 32 bit, let’s crack open IDA for this one then :D
Aside
This program is stripped, meaning that we do not have any labels for any of the functions (functions don’t have function names). IDA tries to search for patterns in the disassembly for where functions exist. For example, functions typically consist of a function prolog,
and at the very end you would see something like,
Looking at the code we can identify a function that IDA found to be the main function based on the parameters passed to __libc_start_main
:
My initial guess at what the vulnerability in this program was was a heap overflow because there were some calls to malloc
and free
which is very typical of a heap overflow sort of challenge. But looking a little more into this function, we see a call to another function call sub_80486AD
which consists of:
1) Opening the file “flag.txt”
2) Reading the contents into a stack based buffer
3) and…drum roll…a format string vulnerability :D
Now you may ask yourself why is this a format string vulnerabilty? OK, so there is only one parameter given to the printf
function and with our extensive C knowledge we know that the first parameter to the printf
function is the format specifier for the function. So if the format specifier is "%s"
and printf
goes to get the second parameter then it will go grab the next parameter given by the user as the second parameter, but since we only are giving it one parameter…what would happen? (read more here if you are unsure: stanford crypto). Let’s see which one of our inputs is actually the format string. If we look earlier in the program to see where this format
string is coming from…
Alright so it is the first parameter to this function that is called. And if we look at when this function is called…
So esp+18h
is where our buffer is located and that turns out to be…
So we know that what we enter into our teamname is the format string :D OK, so know we have the power to write and read to the stack and if we think about it for a second, our flag was read in from a file and put on a stack buffer… why don’t we just dump the stack and then get our flag? (We thought that there was a pointer to the flag that we could just do a direct parameter access ie. “%12$s” to print out the flag really easily instead of parsing the stack but after a while of bruteforcing the direct parameter to access we started printing out environment variables and we knew that we went too far lol).
Note
Since these challenges are still up, I just wrote down the steps to get the flag and not the actual flag itself
So there you have it :D
I would show the work that I did