Skip to main content

Chương 22: Clickjacking

Khái niệm

Clickjacking (UI Redressing — Tái trang trí giao diện) là tấn công khiến người dùng click vào thứ họ không thấy hoặc không nghĩ họ đang click.

Mức độ nguy hiểm: Trung bình — Phụ thuộc vào action bị khai thác.

Cơ chế: Nhúng trang web mục tiêu vào iframe vô hình, overlay trên trang decoy.


Cách hoạt động

<!-- Trang của hacker -->
<style>
iframe {
position: absolute;
width: 500px;
height: 700px;
opacity: 0.0001; /* Vô hình nhưng vẫn clickable */
z-index: 2;
top: 0; left: 0;
}
.decoy {
position: absolute;
z-index: 1;
top: 300px; /* Overlap với iframe's button */
left: 200px;
}
</style>

<iframe src="https://bank.com/transfer?to=hacker&amount=1000"></iframe>
<div class="decoy">
<button>Click here to claim your prize!</button>
</div>

<!-- User click "claim prize" → actually click bank.com "Confirm Transfer" -->

Phòng chống

X-Frame-Options

X-Frame-Options: DENY → không ai được embed
X-Frame-Options: SAMEORIGIN → chỉ same origin được embed
X-Frame-Options: ALLOW-FROM https://partner.com → deprecated

Content-Security-Policy frame-ancestors

Content-Security-Policy: frame-ancestors 'none'
Content-Security-Policy: frame-ancestors 'self'
Content-Security-Policy: frame-ancestors https://partner.com

CSP frame-ancestors thay thế X-Frame-Options — linh hoạt hơn.

# Nginx
add_header X-Frame-Options "DENY" always;
add_header Content-Security-Policy "frame-ancestors 'none'" always;

Frame-busting JavaScript (Không đáng tin)

// Yếu: có thể bypass bằng sandbox iframe
if (window !== window.top) {
window.top.location = window.location;
}

// Bypass:
<iframe sandbox="allow-forms allow-scripts" src="...">

Tóm tắt

  • Clickjacking: invisible iframe overlay → user click phần tử hidden.
  • Phòng chống: X-Frame-Options: DENY + CSP: frame-ancestors 'none'.
  • Frame-busting JS có thể bị bypass với sandbox iframe.