Skiddyana Pwnz and the Loom of Fate
pointer overwrite and ret2win
Problem
Solution
Analysis
Here's the decompile main code from ghidra, some parts that are deemed unnecessary or irrelevant are removed.
The program simply loop through and provide three functionalities. The second option is simply going to print what ever the src is pointing to. For the other two we will take a look further below.
This function will be triggered if we pick the first option. It provide us with the ability to change the content of src as long we satisfy the content is less than 256. If not then it will simply retain whatever src was pointing without changing it.
This function will be triggered if we pick the third option. It will only move the data pointed by src to its local variable. Here lies the main vulnerability, because our buffer that is being pointed by src has the potential to copy the amount that will exceeds the limit of dest and overwriting the RIP. Luckily there's a function call theVoid() that acts as the win function. However in order for the function to executes, there's a check to a password that needs to be passed beforehand.
Exploitation
Although the password is hardcoded and we already see it in the main function, the remote server seem to contain a password that is different from that was given to us. So we need to leak the password on the remote server.
To leak the password we will use the 2nd option which prints anything as a string that is being pointer by src. So we need to control whatever src is pointing, to achieve this we will take a look at the loomRoom() once more...
Notice even though it checks the length of our buffer to be less than 256, we are still able to write 286 bytes, enough to overwrite the src. Since PIE is not enabled, the address of the password is hardcoded and we can overwrite src with the password address and call the option to print it.


Next we will simply abuse the strcpy() to trigger a buffer overflow and change the code execution to call the win function.
So, to summary here's what our exploit should do:
First, corrupt the src to point to the password address
call the print functionality to leak the password
prepare our payload with loomRoom()
trigger buffer overflow with fatesRoom()

Flag
flag{d0nt_f0rg3t_y0ur_h4t}
Last updated