> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/web/race-conditions/exploitation-of-time-sensitive-vulnerabilities.md).

# Exploitation of Time-sensitive Vulnerabilities

Exploitation of Time-sensitive Vulnerabilities notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### Exploiting Time-sensitive Vulnerabilities

### Lab Context

The site offers a feature of **Password reset** via a link sent by email. / There is no real race condition on the logical application side, but the generation of **tokens** is **cased**: it depends on a **predictable value** (time), which allows to forge a valid token for another user by sending requests \*\* at the same time\*\*.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c58a84bf71f02dd10b85375f3d415c416bce37ea%2F%7BDF7E5660-9207-4CDB-B974-C67123A4191D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Observations Initiales

1. We use **Forgot password** with user `wiener`.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-626227ff5ce7b6028baaf462af347a06ca8fd1cf%2F%7BB837963E-072E-48E3-B684-700364BE996A%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* An e-mail containing a link of the type:
* `/forgot-password?user=wiener&token=<token>`

{% code overflow="wrap" %}

```bash
Hello!

Please follow the link below to reset your password.

https://0a1300c9040343bf810b7f2a00e60085.web-security-academy.net/forgot-password?user=wiener&token=3930dc6d3d076151204ad4147326f81a5e1609a8
```

{% endcode %}

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a26e0e7d9ed5174051929e952e4701fbf0c31666%2F%7B113509E4-671D-401B-8EA0-F6AE9725AB1E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Token looks like a **SHA1** (40 hexadecimal characters).

`forgot-password?user=wiener&token=3930dc6d3d076151204ad4147326f81a5e1609a8`

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-930b5c1465387f7d158ca316aa89aa6512b44d48%2F%7BB66B464D-4E68-4DAB-BEEC-0A8D7F05E9A5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Token looks like a **SHA1** (40 hexadecimal characters).

```bash
hashid '3930dc6d3d076151204ad4147326f81a5e1609a8'
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b340c74876dd768b3c7c3d51ff402645274e0abb%2F%7B4BC8DA5A-DA34-4C1C-9B18-9B2014CD516F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

1. By generating several tokens

Assumption: Token is derived mainly from a **timestamp** (or a time-based value), rather than a robust secret.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5c3e7d33579f6ed4584f7ebc7de1cde1e72139d4%2F%7B178FE46D-40F0-4953-A695-CB87823E2810%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

### Key Idea: Force Two Requests at the Same Millisecond

If we can trigger **two resets** at the same time, and the token depends only on the timing, then **the two tokens will be identical**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bec565b7f22d7983fb35e5825b4630f0ab626d2a%2F%7B12B696E9-90B1-4254-9667-9BE6B0B5A8A1%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Problem: The server (PHP) sometimes avoids collisions with the same session / CSRF. / Solution: get **two separate sessions**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2ee71deeee62f0504694e71a121ce2e6c5d653b1%2F%7BFEB5680C-2F57-42E6-B7C8-FF2B83D48C79%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Preparation: Get Two Session + CSRF Couples

Two separate requests are made to:

* `GET /forgot-password`

```http
GET /forgot-password HTTP/2
Host: 0a1300c9040343bf810b7f2a00e60085.web-security-academy.net
Cookie:
```

Each answer gives a new couple:

* `PHPSESSID=<...>`
* a new token CSRF (value hidden in the form)

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b60d532445a46566acaa6178aab35384c8538fa7%2F%7B98B7B0DE-2B48-4BED-8144-C012C86D110E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

There are **two ready requests**, each with:

* its `PHPSESSID` cookie
* its associated CSRF field

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f3e9ec62d0b0ff2b38e6b310296c91946facabb9%2F%7BE079B013-0BBB-45D5-82A6-61EA24021EB4%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Trigger: Sending in Parallel

Then we send **in parallel** two POST of reset (even endpoint), in Burp (group + send parallel), so that they arrive **in the same time window**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1639be135577b23a01cc8c769db888ffb9427bd9%2F%7B73C6239F-A361-47DD-9C21-B14A292C373F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Result observed: The two emails received contain \*\* exactly the same token\*\*:

```bash
933ccbd314dc37df95887cd914b07e330517f7bb
933ccbd314dc37df95887cd914b07e330517f7bb
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-6e01ba6eb1ee900953b12829b07e9dce10948360%2F%7BB899DE0C-EB53-4923-BF3D-9D085BD0D5C9%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Conclusion: Token depends essentially on **timestamp**, not on a single secret per user.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a02641ffd57f018d7f18479178fe15dcb54edee5%2F%7B792B8500-D851-4581-94E5-A377EB809957%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Operation: Carlos Reset with Wiener's Token

Objective: Token valid for `carlos`.

Method:

1. Launch in parallel two resets:

* one for `wiener`
* one for `carlos`

```bash
forgot-password?user=wiener&token=da1d6e3ed67bef3efa9fe74fcfbf7603120ea744
forgot-password?user=carlos&token=da1d6e3ed67bef3efa9fe74fcfbf7603120ea744
```

Since the tokens are identical, the received token (e.g. via `wiener` email) will also be valid for `carlos`.

If the site accepts this URL, you can **set a new password** for `carlos`.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f516708a8f594fc919108cb151310a273c478af2%2F%7BDCB16AF0-DCAB-499F-A6BF-EF1784E72D57%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Lab Completion

1. Log in as `carlos` with the new password.
2. Access the \*\* admin sign\*\*.
3. Remove the `carlos` user to validate the lab.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3b7b12ddd7f01c59ee5b83b2f2b93214ec5bbd08%2F%7B686872ED-506C-438E-94DB-7ED0530354C1%7D.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/web/race-conditions/exploitation-of-time-sensitive-vulnerabilities.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
