2021-03-14-Numbers

Posted on March 14, 2021

Numbers

Solution

When we connect to address from task description, we need to guess some numbers. It seems like the numbers are 32-bit. I’ve done similar challenge before and I assumed that the goal of this challenge is to rebuild Mersenne Twister’s matrix state. I utilized RandCrack Python library to do that.

import socket

from randcrack import RandCrack
rc = RandCrack()

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print("connecting")
s.connect(("challs.dvc.tf", 3096))
print("connected")

print(s.recv(256))
for _ in range(624):
    s.send(b'1\n')
    n = int(s.recv(4096).decode().replace("Nice try! I was thinking of ", "").split("\n")[0])
    print(n)
    rc.submit(n)

guessed_number = rc.predict_getrandbits(32)
print(guessed_number)
s.send(("%i\n" % guessed_number).encode("ASCII"))
while True:
    print(s.recv(4096))

Flag

dvCTF{tw1st3d_numb3rs}

Credits

License

CC BY 4.0 WaletSec + everl0stz