Forky
Problem
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.
Solution
So this program recursively forks itself and calls
doNothing()
. We need to identify last integer value that is passed as parameter todoNothing()
.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 tofork()
left. We fork the 8 children, resulting in 16 child processes. More info aboutfork()
on GeeksforGeeks. The diagram below shows this happening (each0
is a process):Therefore, all we need to do is calculate
1000000000 + (16 * 0x499602d2)
. The program creates 16 processes, each of which adds0x499602d2
to the initial value1000000000
.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 this blog post from Loïc Pefferkorn (Archive) and this StackOverflow answer (Archive).Another way to use python to compute the answer is to use
ctypes
:
Flag
picoCTF{-721750240}
Last updated