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):
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.