Weak seed: time-based search
A computer cannot generate true randomness by itself. It uses a pseudorandom number generator (PRNG): a single starting number — the seed — is provided, then the generator produces an entire sequence from it according to a strict formula. If the seed is the same, the sequence will always be exactly the same.
The most common mistake is taking the current time as the seed: random.seed(int(time.time())). Time is not a secret! If an attacker knows approximately when a request was sent, they can test every second in that interval and fully replicate the generator.
On a website, a password reset token was created as follows (server code):
import random
t = int(time.time()) # so'rov kelgan sekund (Unix vaqt)
random.seed(t)
token = random.getrandbits(32) # foydalanuvchiga koʻrsatiladi
kalit = bytes(random.getrandbits(8) for _ in range(38))
ct = bytes(a ^ b for a, b in zip(bayroq, kalit))
From the server log, it is known that the request came within the first one hour starting from January 1, 2025, 00:00:00 UTC, i.e. 1735689600 <= t < 1735693200 (3600 variants in total).
Token shown to the user (in base 16):
ebcc3923
Encrypted flag (hex):
8b7ff5723190825f2d165db011940eec33b6eb6daff6421d82293a1a66f77c0f
cafad28f11de
Test the 3600 seeds: whichever one matches the token, the key can also be regenerated from that seed.