bof
bof is the 3rd challenge of Toddler's Bottle at pwnable.kr
Last updated
Was this helpful?
bof is the 3rd challenge of Toddler's Bottle at pwnable.kr
Last updated
Was this helpful?
Running checksec against the binary we see that it's full of protections, probably meant to avoid uninteded solutions:
Running the program and feeding it some A's we can see it's vulnerable to a buffer overflow.
Reading the source code we see it has two functions, func() and main():
main is executed when we run the program and it simply runs the func() function with 0xdeadbeef as the argument.
The func() function prompts the user to input data (that's where our overflow is). Then the function checks if the value received from the main() function equals 0xcafebabe and if does the program calls /bin/sh and drops us into a shell.
Opening the program in gdb and disassambling the func() function we can see exactly where the comparison happens.
Now we want to set a breakpoint in that address so we can see how far overwrote the stack and what's the exact amount of junk we want to send until we overwrite the address where 0xdeadbeef is stored.
x/60gx $esp
shows:
So if we send 52 bytes of junk, the 8 following bytes will overwrite the address where the argument to func() is stored, which we know it's ebp + 8, so it's 0xffffcf80.
Finally, all we need to do is send 52 bytes of junk followed by 0xcafebabe and we'll get a shell.
Here is my exploit code: