All About Timing

Description

I'm always late for class but my prof told me that time is relative Comment Suggest edit

Author: jloh02

nc challs.nusgreyhats.org 31111

https://storage.googleapis.com/greyctf-challs/dist-All-About-Timing.zip


Code Analysis

import time
import random

random.seed(int(time.time()))

print("Guess the number I'm thinking of? It's all about the timing")
x = input("Your guess:")

n = random.randint(1000000000000000, 10000000000000000-1)

if int(x) == n:
    with open("flag.txt") as f:
        print(f.readline())
else: 
    print(f"Wrong answer! The number I was thinking of was {n}\nRemember it's all about the timing!")

The code generated a random integer, using the time as seed


Exploit

As python random is pseudo random, with the same seed, we are able to generate the same number each time.

I wrote a simple solve script using pwntools.

import time
import random
from pwn import *


host = "challs2.nusgreyhats.org" 
port = 31111

conn = remote(host,port)

random.seed(int(time.time()))
n = random.randint(1000000000000000, 10000000000000000-1)
q = conn.recvuntil(b'Your guess:')
conn.sendline(str(n).encode())
flag = conn.recvuntil(b"}\n")
print(flag)
conn.close()

Flag: grey{t1m3_i5_a_s0c1al_coNstRucT}

Last updated