日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Busting Frame Busting: a Study of Clickjacking Vulnerabilities on Popular Sites

發布時間:2023/12/16 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Busting Frame Busting: a Study of Clickjacking Vulnerabilities on Popular Sites 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Busting Frame Busting
Reference From: http://seclab.stanford.edu/websec/framebusting/framebust.pdf
Translated By: LittleHann

?

?

1. 摘要

基于Web Frame的攻擊例如: ClickJacking,一般使用iframes去劫持用戶的web session。目前最普遍的防御手段被稱之為frame busting,即阻止當頁面加載一個frame的時候對當前頁面產生影響。

?

2. 介紹

Frame busting依靠防御代碼來防止頁面加載一個嵌套的frame,它是防御ClickJacking的主要手段。Frame busting同時還被用在保護login登錄頁面上,如果沒有frame busting,那個這個login登錄頁面能夠在任何的嵌套的子frame中打開。一些新型的高級ClickJacking技術使用Drag-and-Drop去提取敏感隱私數據并且注入到另一個frame中,完成數據竊取。

上圖演示了一個ClickJacking。原始的頁面被一個透明的的frame(內容是在的,只是視覺上是透明的)覆蓋在了原本的頁面圖層的上面。當用戶和原始的頁面進行交互的時候(例如點擊),他們在不知情的情況下和惡意的frame頁面進行了交互,達到了欺騙劫持的目的。

為了對抗這種ClickJacking攻擊,業界普通采用這種做法: frame busting bode

if(top.location != location)

{

  top.location = self.location;

}

frame busting code一般由一個條件表達式和糾正動作(即跳轉)組成。即將頂層頁面導航值當前頁面。

我們的調查顯示:

大多數的網站還僅僅是做了簡單的代碼防御,即把top.location(覆蓋在原始頁面上的"惡意"frame重定向回sefl.location("正確"的frame))。針對ClickJacking的防御并沒有得到重視。

?

?

?

3. ClickJacking的常規防御方法

frame busting 的條件判斷語句:

if (top != self) if (top.location != self.location) if (top.location != location) if (parent.frames.length > 0) if (window != top) if (window.top !== window.self) if (window.self != window.top) if (parent && parent != window) if (parent && parent.frames && parent.frames.length>0) if((self.parent&&!(self.parent===self))&&(self.parent.frames.length!=0))

frame busting 的糾正動作代碼:

?

top.location = self.location top.location.href = document.location.href top.location.href = self.location.href top.location.replace(self.location) top.location.href = window.location.href top.location.replace(document.location) top.location.href = window.location.href top.location.href = "URL" document.write('') top.location = location top.location.replace(document.location) top.location.replace('URL') top.location.href = document.location top.location.replace(window.location.href) top.location.href = location.href self.parent.location = document.location parent.location.href = self.document.location top.location.href = self.location top.location = window.location top.location.replace(window.location.pathname) window.top.location = window.self.location setTimeout(function(){document.body.innerHTML='';},1); window.self.onload = function(evt){document.body.innerHTML='';} var url = window.location.href; top.location.replace(url)


對于這種防御方法,我的理解是這樣的:
這是一個對于frame覆蓋的poc演示:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
?? ?<title>Click Jack!</title> ?
?? ?<style type="text/css"> ?
?? ??? ?iframe
?? ??? ?{
?? ??? ??? ?width: 900px;
?? ??? ??? ?height: 250px;

?? ??? ??? ?/* Use absolute positioning to line up update button with fake button */
?? ??? ??? ?position: absolute;
?? ??? ??? ?top: -195px;
?? ??? ??? ?left: -740px;
?? ??? ??? ?z-index: 2;

?? ??? ??? ?/* Hide from view */
?? ??? ??? ?-moz-opacity: 0.5;
?? ??? ??? ?opacity: 0.5;
?? ??? ??? ?filter: alpha(opacity=0.5);
?? ??? ?}

?? ??? ?button
?? ??? ?{
?? ??? ??? ?position: absolute;
?? ??? ??? ?top: 10px;
?? ??? ??? ?left: 10px;
?? ??? ??? ?z-index: 1;
?? ??? ??? ?width: 120px;
?? ??? ?}
?? ?</style>??? ?
</head>
<body>
?? ? <iframe src="http://www.baidu.com" scrolling="no"></iframe>
?? ? <button>Click Here!</button>
</body>
</html>

注意這個<iframe src="http://www.baidu.com" scrolling="no"></iframe>其實是在當前BOM(http://www.dreamdu.com/javascript/what_is_bom/)中插入了一個新的窗體window,而在一個
BOM中,各個window之間的地位是平級的,區分它們的視覺參數只有z-index。當兩個window產生覆蓋時,這兩個window之間就有了top和parent的父子關系,即frame覆蓋的問題。

攻擊者通過控制iframe的長、寬以及調整top、left的位置,可以把iframe頁面內的任意部分覆蓋到任何地方。
同時設置iframe的position為absolute,并將z-index的值設置為最大,以達到讓iframe處于頁面的最上層。最后,通過設置opacity來控制iframe頁面的透明度,值0是完全不可見。
這樣,就完成了一次點擊劫持攻擊。



3. ClickJacking的繞過方法

3.1 Double Frame 雙框架嵌套繞過法
之前介紹的普通的ClickJacking防御代碼中只是簡單的對parent.location進行賦值來進行frame覆蓋的糾正。
這在當前頁面只被攻擊者覆蓋了一個frame的情況能起到很好的防御作用。然后,如果攻擊者在當前頁面上覆蓋了兩個的frame(Double Frame),情況就不一樣了。

建立兩個頁面:

1.html代碼為:

<iframe src="2.html">

2.html代碼為:

<iframe src="http://www.victim.com">

訪問1.html之后可以看到頁面并無跳轉等動作。

?

?

?

3.2 onBeforeUnload函數的利用

我對這個函數的理解是,我們可以把它看成是一個DOM的生命周期函數,它在一個頁面將要被關閉時調用。而這個所謂的頁面"關閉"包括刷新和URL的跳轉。這個“生命周期”函數可以為我們用來對抗frame busting的防御代碼。即傳統的frame busting的原理就是檢測當前的top.location是否和self.location是否一致,如果不一致就進行URL的跳轉,而這個跳轉可以被攻擊者通過onBeforeUnload注冊的回調函數攔截下來,進行相應的處理。

如下的防御代碼:

if(top != self) top.location.replace(location);

新建立頁面,代碼如下:

<script> var framekiller = true; window.onbeforeunload = function()
{
  if(framekiller)
  {
    return "Write something here to keep people stay!";
  }
}; </script> <iframe src="http://www.victim.com/">

打開頁面顯示如下:

欺騙用戶點擊留在此頁后顯示:

?

?

?

?

3.3 針對XSS Filter的攻擊和利用

IE8和Google Chrome引入了一個XSS Filter機制來防止頁面中出現典型的XSS 攻擊。但是,反過來,XSS Filter也可能被用來對抗frame busting的代碼。

防御代碼如下:

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

新建立頁面,代碼如下:

<iframe src="http://www.victim.com/?<script>">

訪問后頁面顯示:

?

?

IE的xss篩選器自動攔截了跳轉。可以看到,原本的frame busting防御代碼的跳轉被IE XSS Filter當成了惡意跳轉給攔了下來。這突然讓我想到了一個原則:

"所有的安全漏洞都來自于原本正常的功能。關鍵是我們對這個功能的理解深刻程度以及利用方式"

?

?

?

?

3.4 Referer檢查的問題

有一些站點允許自己的域名嵌套自己,禁止外站對自己的嵌套。

通常是用document.referer來檢測來源是否為自己的域名。

if(top.location!=location){if(document.referrer && document.referrer.indexOf("aaa.com")==1){top.location.replace(document.location.href);} }

判斷字符串中是否含有本域名是常見的錯誤用法,利用二級域名的方式便可繞過,如:

http://aaa.com.bbb.com

注:從https域下post數據到http域的時候,瀏覽器不帶Referer。

?

?

?

3.5 location劫持

在IE瀏覽器中,如果能夠在防御代碼的前面可以插入form表單的話,可以利用form表單對location進行劫持。

<form name=self location="javascript:alert(1)"></form> <script> if(top!=self)
{top.location=self.location } </script>

用iframe嵌套此代碼,可以看到沒有跳轉,執行了alert(1)。

?

?

?

4. 推薦防御的方法

4.1 X-FRAME-OPTIONS

X-FRAME-OPTIONS是微軟提出的一個http頭,專門用來防御利用iframe嵌套的點擊劫持攻擊。

并且在IE8、Firefox3.6、Chrome4以上的版本均能很好的支持。

這個頭有三個值:

DENY // 拒絕任何域加載SAMEORIGIN // 允許同源域下加載ALLOW-FROM // 可以定義允許frame加載的頁面地址

?

php中設置示例:

header ( "X-FRAME-OPTIONS:DENY");




4.2 目前最好的js的防御方案為 <head> <style> body { display : none;} </style> </head> <body> <script> if (self == top)
{var theBody = document.getElementsByTagName('body')[0];theBody.style.display = "block"; }
else
{top.location = self.location; } </script>

轉載于:https://www.cnblogs.com/LittleHann/p/3386055.html

總結

以上是生活随笔為你收集整理的Busting Frame Busting: a Study of Clickjacking Vulnerabilities on Popular Sites的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。