Pwn - cookie-monster
153 solves | 406 points
Last updated
153 solves | 406 points
Last updated
Do you like cookies? I like cookies.
First, let's check the binary security in place.
Next, decompile the binary in Ghidra. The main logic of the program is in the bakery()
function.
Here, line 17 is particularly interesting because it is a system call but the argument is not what we want. After exploring the binary further in Ghidra, we found an interesting string /bin/sh
.
So we can pretty much formulate our attack plan now. The plan is to make use of the buffer overflow in line 19 to ret
to system and passing the /bin/sh
argument into the system call. However, since stack canary is enabled, we would first need to make use of the format string vulnerability in line 13 to leak the canary before proceeding with our buffer overflow.
We shall first find out how to leak the canary in gdb
. Set a breakpoint at 0x804859e
so that we can inspect the canary value which is to be stored in the EAX
register.
Continue execution in gdb and we can see that our canary value is 0xce359b00
.
The next step requires a little trial and error but since the fgets
function only reads in 32 characters, we shall try printing %p
15 times (30 characters in total).
We will see that indeed, we can leak the canary 0xce359b00
on the 15th %p
. Now that we have everything we need, its time to write the exploit script.
Flag: dam{s74CK_c00k13S_4r3_d3L1C10Us}