Forky
Last updated
Was this helpful?
Last updated
Was this helpful?
In this program, identify the last integer value that is passed as parameter to the function doNothing(). The binary is also found in /problems/forky_5_4f100885e708548a54f8c5668f9821c1 on the shell server.
Reverse the binary file using (). main()
function:
doNothing()
function:
So this program recursively forks itself and calls doNothing()
. We need to identify last integer value that is passed as parameter to doNothing()
.
The first process forks itself, creating 2 child processes. Those two children fork, creating 4 child processes. We have now executed 2 of the 4 calls to fork()
. We fork the 4 children, doubling again to create 8 child processes. Now we only have 1 call to fork()
left. We fork the 8 children, resulting in 16 child processes. More info about fork()
on . The diagram below shows this happening (each 0
is a process):
Therefore, all we need to do is calculate 1000000000 + (16 * 0x499602d2)
. The program creates 16 processes, each of which adds 0x499602d2
to the initial value 1000000000
.
Run the calculation using python: python -c "from numpy import int32;print(int32(1000000000) + int32(16)*int32(0x499602d2))"
to get -721750240
. Here, we use the numpy.int32 datatype (generic unsigned integer) since it overflows just like in C. More info on () and ().
Another way to use python to compute the answer is to use ctypes
:
picoCTF{-721750240}