> For the complete documentation index, see [llms.txt](https://alham-rizvi.gitbook.io/alhamrizvi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/reverse-engineering/chronohack.md).

# chronohack

We are given the following source code:

```python
import random
import time

def get_random(length):
    alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    random.seed(int(time.time() * 1000))  # seeding with current time 
    s = ""
    for i in range(length):
        s += random.choice(alphabet)
    return s
```

#### Vulnerability

The token is generated using:

```python
random.seed(int(time.time() * 1000))
```

This means the PRNG depends entirely on the current timestamp (in milliseconds), making it predictable.

#### Approach

* Recreated the token generator locally
* Connected to the remote service using pwntools
* Took local time before sending guesses
* Brute-forced nearby timestamps (to handle latency)
* Tried 50 guesses per connection (server limit)
* Reconnected and repeated with adjusted offsets

#### Solution Script

```python
from pwn import *
import random
import time

def get_random(length, seed):
    alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    random.seed(seed)
    return ''.join(random.choice(alphabet) for _ in range(length))

HOST = "verbal-sleep.picoctf.net"
PORT = 64493

found_flag = False

for adjust in range(-50, 1000, 40):
    print(f"[+] Adjustment: {adjust}")

    start_time = time.time()
    r = remote(HOST, PORT)

    for i in range(50):
        seed = int(start_time * 1000) + i + adjust
        token = get_random(20, seed)

        try:
            r.recvuntil(b"(or exit):")
        except:
            break

        print(f"Trying: {token}")
        r.sendline(token.encode())

        res = r.recvline()

        if b"Sorry" not in res:
            print("\n" + "="*100)
            print("[+] Token Found:", token)
            print(res.decode())
            print(r.recvline().decode())
            found_flag = True
            break

    r.close()

    if found_flag:
        break
```

#### Result

The correct token was found by matching the seed, and the flag was returned:

```
picoCTF{...}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://alham-rizvi.gitbook.io/alhamrizvi/picoctf-writeups/picoctf/reverse-engineering/chronohack.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
