247CTF - The Flag Lottery
Guess a random number to win the flag lottery. The server generates the winning number using a seeded PRNG.
Vulnerability
The server seeds the random number generator with the current Unix timestamp, which is predictable. Additionally, Python 2 and Python 3 have different PRNG implementations and string conversion behaviors.
Solution
The server code is vulnerable because:
- Predictable seed: Unix timestamp is public knowledge
- Time window: Even if time is slightly off, we can try nearby timestamps
- Version differences: Python 2's
str()truncates floats, making predictions consistent
Use Python 2 to generate predictions for timestamps around the server's current time:
1 | import subprocess |
Helper script (get_legacy_random.py), specifically for
Python 2 syntax; it is not Python 3 source. The server-side generator
and Python 2 runtime are unavailable, so neither prediction equality nor
the timing window has been reproduced:
1 | import random |
Key Insight
PRNGs seeded with time are not cryptographically secure. Use
secrets or os.urandom() for security-sensitive
randomness. Additionally, always be aware of version-specific
differences in language implementations when predicting values.
The returned flag belongs to the launched service instance; no cross-instance invariance is established. Record the generation/retrieval method and use the current instance response instead of a fixed-answer spoiler.