Tags: random python misc python3 

Rating: 0

# Random memory
![](https://i.imgur.com/LYaopt0.png)

## Challange
We are presented with the remote server connection details.

The connection output:
```
[+] Initializing Python Virtual Machine.
[+] System booted (1567949125.7451274), memory check is required, pushing random values to all 31337 cells...
.....................................................
0x0: 0x7952
0x1: 0x4d7
0x2: 0x5101
0x3: 0x51b
0x4: 0x4ca4
0x5: 0x6376
0x6: 0x6344
0x7: 0x3fbd
0x8: 0x3e51
0x9: 0x2c4e
0xa: 0x4eab
0xb: 0x364d
0xc: 0x29b1
0xd: 0x4dda
0xe: 0x4d89
0xf: 0x3480
0x10: 0xfd9
0x11: 0xba7
...
# Redacted long data
...
0x205b: 0xe90
0x205c: 0x4913
0x205d: 0xf9e
0x205e: 0x41da
0x205f: NULL
[+] Uncorrectable error found in Random Memory Generator. Manual action required.
[+] Set value:

```

The first two lines provide us with the system **timestamp** and the **cell count**.
We also know that we are dealing with **python random generator**.

Using timestamp from the output I attempted to replicate the results locally using the same timestamp as a **seed**.

```
#!/usr/bin/python3
import random

timestamp = float('1567949125.7451274')
random.seed(31338)
for i in range(iterations):
print(f'{hex(i)} :{hex(random.randint(0, 31337))}')

```

The results matched the remote output so the rest was a matter of putting the script together.

Note: Results only matched on Python3

## Solver

```
#!/usr/bin/python3
from pwn import *
import random

def main():
r = remote('165.22.22.11', 5566)
data = r.recvuntil('..').decode('utf-8')

timestamp = float(data.split('(')[1].split(')')[0])
print(f"[+] Timestamp: {timestamp}")

random.seed(timestamp)
numbers = {}

for i in range(31338):
numbers[hex(i)] = hex(random.randint(0, 31337))

data = r.recvuntil('NULL').decode('utf-8')
data = data.split('\n')[-1].split(':')[0]

key = numbers.get(data)

print(f'[+] Address: {data}\n[+] Key: {key}')

r.recvuntil('value:')
r.sendline(numbers.get(data))

print(r.recvline_endswith('}').decode('utf-8'))

if __name__ == '__main__':
main()
```

### Solution

```
[+] Opening connection to 165.22.22.11 on port 5566: Done
[+] Timestamp: 1567983214.83652
[+] Address: 0x691c
[+] Key: 0x2f8e
[+] AFFCTF{d0n7_l0s3_y0ur_m3m0ry}
[*] Closed connection to 165.22.22.11 port 5566
```