Upon connecting to the netcat listener, we’re prompted to guess a number. Initially, I tried bruteforcing it for a few minutes, because why not? While it is possible for this challenge, it would take forever, so it’s better if we analyze the sillygoose.py file that’s attached with the challenge.
from random import randint import time ans = randint(0, pow(10, 100)) start_time = int(time.time()) turns = 0 whileTrue: turns += 1
inp = input()
ifint(time.time()) > start_time + 60: print("you ran out of time you silly goose") break
if"q"in inp: print("you are no fun you silly goose") break
ifnot inp.isdigit(): print("give me a number you silly goose") continue
inp = int(inp) if inp > ans: print("your answer is too large you silly goose") elif inp < ans: print("your answer is too small you silly goose") else: print("congratulations you silly goose") f = open("/flag.txt", "r") print(f.read())
if turns > 500: print("you have a skill issue you silly goose")
The rules are simple:
If the number is too large, we’re prompted with "your answer is too large you silly goose"
If the number is too small, we’re prompted with "your number is too small you silly goose"
If we run out of time (60 seconds), we’re prompted with "you run out of time you silly goose"
If we guess over 500 times, we’re prompted with "you have a skill issue you silly goose"
print(f"Guess: {guess}, Response: {response}") # Debugging line
if"congratulations"in response: print("Flag found!") print("Response content might contain the flag.") break elif"too large"in response: high = guess - 1 elif"too small"in response: low = guess + 1 elif"you have a skill issue"in response: print("Skill issue") break elif"you ran out of time"in response: print("Ran out of time") break elif"you are no fun"in response: print("No fun") break elif"give me a number"in response: print("Invalid input")
# Try to fetch more data if the flag might be hidden try: additional_response = p.recvall().decode('utf-8').strip() print("Additional response:", additional_response) except: print("Failed to fetch additional response")
# Close connection p.close()
For each iteration, we halve the search space, which is what guess = (low + high) // 2 does. This isn’t necessary, but helps to optimize the runtime of the code.
If you want to better understand binary searches, this is a great article explaining it in better detail.