Warmup PWN Challenge: babyflow Writeup
In this writeup, we'll walk through solving the "Warmup" PWN challenge step by step. The goal is to exploit a buffer overflow vulnerability to bypass a password check and reveal the flag.
Analyzing the Binary
We start by running binary ninja to decompile the file.
We examine the decompiled code snippet:
Trying to use the password
The program asks for a password input and checks it using strncmp against the hardcoded string "SuPeRsEcUrEPaSsWoRd123".
If the password is correct, it checks the value of var_c.
If var_c is still 0, it prints a message asking if you are the admin.
If var_c is non-zero, it reveals the flag.
Step 2: Crafting the Exploit
We need to:
Input the correct password to pass the check.
Overflow the buffer to modify var_c and set it to a non-zero value, which will reveal the flag.
Buffer Overflow:
The buffer size is 50 bytes, and the password takes up the first 22 bytes.
That leaves 28 bytes for padding and overflow.
We need to overflow into var_c (a 4-byte integer) and set it to 1.
Step 3: Writing the Python Exploit
Now, let's write a Python script to send the payload to the server.
Step 4: Running the Exploit
Once the script is ready, simply run it using:
If the exploit is successful, the program will print the flag:
This challenge demonstrates a classic buffer overflow attack. We bypass the password check by inputting the correct password, then overflow the buffer to manipulate a local variable (var_c). When var_c is changed from 0 to 1, the program reveals the flag.
By following these steps, we successfully exploited the vulnerability and obtained the flag. This writeup covers the basic principles of exploiting buffer overflows in C programs and how to automate the process using Python.