钓鱼攻击之Reverse Tabnabbing
字数 1033 2025-08-25 22:58:20
Reverse Tabnabbing 钓鱼攻击技术详解
1. 漏洞概述
Reverse Tabnabbing(反向标签页劫持攻击)是一种利用浏览器特性实施的钓鱼攻击技术。攻击者通过在A页面中打开一个新的页面B(而非替换原始页面),然后利用B页面对A页面进行操作,将A页面修改为钓鱼页面C。
2. 攻击原理
2.1 核心机制
攻击依赖于浏览器的 window.opener API:
- 当页面A打开页面B时,B页面可以通过
window.opener获取对A页面的引用 - 通过这个引用,B页面可以修改A页面的URL和其他属性
2.2 触发条件
以下两种情况会触发此漏洞:
- 使用
<a>标签且具有target="_blank"属性,但没有rel="noopener"属性 - 使用
window.open()方法打开新页面
3. 攻击演示
3.1 示例代码
a.html (正常网站)
<html>
<title>legit website</title>
<body>
<li><a href="http://localhost/b.html" target="_blank">Vulnerable target using html link to open the new page</a></li>
<button onclick="window.open('http://localhost/b.html')">Vulnerable target using javascript to open the new page</button>
</body>
</html>
b.html (恶意网站)
<html>
<title>malicious website</title>
<body>
<script>
if (window.opener) {
window.opener.location = "http://localhost/c.html";
} else {
alert("no vulnerability");
}
</script>
</body>
</html>
c.html (钓鱼网站)
<!DOCTYPE html>
<html>
<head>
<title>phish website</title>
</head>
<body>
<li><a href="http://localhost/b.html" target="_blank">Vulnerable target using html link to open the new page</a></li>
<button onclick="window.open('http://localhost/b.html')">Vulnerable target using javascript to open the new page</button>
</body>
</html>
3.2 攻击流程
- 用户访问正常网站a.html
- 用户点击链接或按钮,打开b.html
- b.html检测到window.opener存在
- b.html将a.html的location修改为c.html
- 用户返回原标签页时,看到的是伪装成原网站的钓鱼页面
4. 漏洞危害
- 用户信任的原始页面被静默替换为钓鱼页面
- 攻击者可获取用户登录凭证等敏感信息
- 钓鱼页面可以高度模仿原始网站,增加欺骗性
- 攻击可跨域实施
5. 防御措施
5.1 针对标签的防御
添加 rel="noopener" 属性:
<a href="http://localhost/b.html" target="_blank" rel="noopener">Safe link</a>
对于旧版浏览器,可使用 rel="noreferrer":
<a href="http://localhost/b.html" target="_blank" rel="noreferrer">Safe link</a>
5.2 针对window.open的防御
手动设置opener为null:
var otherWindow = window.open();
otherWindow.opener = null;
otherWindow.location = url;
5.3 完整防御示例
<html>
<title>legit website</title>
<body>
<script type="text/javascript">
function safeOpen(url) {
var otherWindow = window.open();
otherWindow.opener = null;
otherWindow.location = url;
}
</script>
<li><a href="http://localhost/b.html" target="_blank" rel="noopener">Safe target using html link</a></li>
<button onclick="safeOpen('http://localhost/b.html')">Safe target using javascript</button>
</body>
</html>
6. 浏览器兼容性说明
- 现代浏览器普遍支持
rel="noopener" - 旧版浏览器可能需要使用
rel="noreferrer"作为替代方案 - 部分浏览器已默认在新标签页中设置
opener=null,但仍建议显式防御
7. 实际应用建议
- 对所有外部链接进行审查,确保添加防护属性
- 在代码审查中检查所有使用
window.open的地方 - 考虑使用CSP(内容安全策略)作为额外防护层
- 对用户生成内容中的链接进行特殊处理
通过实施这些防御措施,可以有效防止Reverse Tabnabbing攻击,保护用户免受钓鱼攻击的威胁。