# 1.35 cors漏洞

CORS漏洞其中已经存在很久了，但是国内了解的人不是很多，文章更是少只有少，漏洞平台也没有此分类。

在DefConChina中，陈建军分享的议题中解释的更清楚，有意向的可以找PPT或者视频

owasp内的详细介绍

<http://blog.securelayer7.net/owasp-top-10-security-misconfiguration-5-cors-vulnerability-patch/>

## 漏洞描述

CORS，Cross-Origin Resource Sharing，跨源资源共享。

CORS是W3C出的一个标准，其思想是使用自定义的HTTP头部让浏览器与服务器进行沟通。因为开发者需要进行跨域进行获取资源，应用场景，在a.com，想获取b.com中的数据，常用的2种方法进行跨域 一种为JSONP,一种为CORS.还有html标签也能跨域，有以下几种 img, iframe,ink, script

cors跨域访问资源示意图：

![](https://i.screenshot.net/v25i287)

假设用户登陆一个含有CORS配置网站vuln.com，同时又访问了攻击者提供的一个链接evil.com。 evil.com的网站向vuln.com这个网站发起请求获取敏感数据，浏览器能否接收信息取决于vuln.com的配置。

如果vuln.com配置了Access-Control-Allow-Origin头且为预期，那么允许接收，否则浏览器会因为同源策略而不接收。

常见测试点：

1.互联网厂商的api接口

2.聊天的程序的api接口

3.app的api（不过有一些请求需要带有一些额外的请求头，利用起来比较困难）

4.区块链厂商

## 漏洞等级

低危

## 漏洞危害

造成跨域问题，可能造成信息泄露等危害。

## 漏洞检测方法

第一种：

> curl <https://test.net> -H “Origin: <https://evil.com”> -I

当你看到的返回结果包括

> Access-Control-Allow-Credentials: true Access-Control-Allow-Origin: <https://evil.com>

第二种：

github上提供了一个关于扫描CORS配置漏洞的脚本，[CORScanner](https://github.com/chenjj/CORScanner)。

参数如下：

```

root@kali:~/Desktop/CORScanner# python cors_scan.py -h
usage: cors_scan.py [-h] [-u URL] [-i INPUT] [-t THREADS] [-o OUTPUT]
                    [-v [VERBOSE]] [-d [HEADERS [HEADERS ...]]]

OPTIONS:
  -h, --help            show this help message and exit
  -u URL, --url URL     URL/domain to check it's CORS policy
  -i INPUT, --input INPUT
                        URL/domain list file to check their CORS policy
  -t THREADS, --threads THREADS
                        Number of threads to use for CORS scan
  -o OUTPUT, --output OUTPUT
                        Save the results to text file
  -v [VERBOSE], --verbose [VERBOSE]
                        Enable Verbosity and display results in realtime
  -d [HEADERS [HEADERS ...]], --headers [HEADERS [HEADERS ...]]
                        Add headers to the request.

Example: python cors_scan.py -u google.com
```

第三种：

使用burp进行自动化检测

在burp下做如下设置

![](https://i.screenshot.net/ry5bm0m)

![](https://i.screenshot.net/vxozi33)

即可自动检测cors漏洞

![](https://i.screenshot.net/np19fp4)

## 漏洞利用方法

详见下文

## 漏洞修复方案

（1）如果没有必要就不要开启CORS

（2）严格限制域白名单，而不是使用\*

（3）尽量避免使用Access-Control-Allow-Credentials

（4）对于orgin域名进行严格限制，可信域名限制，详细限制，如信任子域名 \*.test.com 如果检查域名后缀方式请采用 .test.com

（5）配置“VARY”头部

（6）如果可能的话避免使用“CREDENTIALS”

（7）限制缓存的时间

（8）限制使用的方法

## 漏洞案例

hackerone上一个500dollar的漏洞

<https://bugbountypoc.com/exploiting-cross-origin-resource-sharing/>


---

# Agent Instructions: 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:

```
GET https://ninjia.gitbook.io/secskill/web/cors.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
