Author: Balajinaidu V
Flag: CTF{a13a806d175841731b24a01e9af240bc81750967542550a4b3bb77a29a9d291b}
Do you really think random numbers generated by computers are random?
Random numbers generated by random
package in python is not really random, if we know the seed then we can get the next sequence of numbers again. So here it is seeded with time.time()
which returns the number of seconds passed since epoch. The program is executed earlier to generate the flag, so if we try to seed the random number with current time and decrease the seed by one every time, we will reach to the time when the program was executed. Through which we can get the seed. Once we have the seed we can get the same sequence of numbers again, which will provide us the flag.
The following python program finds the seed and flag.
import random
import time
import hashlib
t = round(time.time())
for i in reversed(range(t)):
random.seed(i)
x = random.random()
if (x == 0.33567959567961436):
print("**************** seed is "+ str(i)+ " ****************")
random.seed(i , version=2)
while True:
rand = random.random()
has = hashlib.sha256(str(rand).encode()).hexdigest()
flag = f"CTF{{{has}}}"
if "7a2" in has:
with open("./flag", "w") as f:
f.write(flag)
print("Flag written to file")
exit(0)