點擊劫持 Framekiller--惡意frame導致CSRF攻擊

 

頁面被惡意iframe後,將可能導致csrf攻擊。而且頁面上的元素能夠被DIV覆蓋,將可能加重這種攻擊。iframe被DIV覆蓋可以參考下面的鏈接:http://www.hiermenuscentral.com/issues/safiframe/iframeover.html

 

一般的解決方法如下:

<script type="text/javascript"> if(top != self) top.location.replace(location); </script>

但其實,這種方式能夠被繞過。比如在父頁面中,加入如下代碼(限於某些對204處理時不會跳轉的瀏覽器):

var prevent_bust = 0; // Event handler to catch execution of the busting

script. window.onbeforeunload = function() { prevent_bust++ }; // Continuously monitor whether busting script has fired.

setInterval(function() { if (prevent_bust > 0) { // Yes: it has fired.

prevent_bust -= 2; // Avoid further action. // Get a 'No Content' status which keeps us on the same page. window.top.location = 'http://server-which-responds-with-204.com'; } }, 1);

或者:

var framekiller = true; window.onbeforeunload = function() { if(framekiller) { return "..."; // any message that helps user to make decision } };

2010年,有人提出這樣的解決方法:

<style> html{display : none ; } </style> <script> if( self == top ) { document.documentElement.style.display = 'block' ; } else { top.location = self.location ; } </script>

當然,這些解決方法可能是有缺陷的,比如瀏覽器沒有開啓執行JS,或者有缺陷等。

IE 8可以通過設置下面的HTTP Header:

點擊劫持 (Clickjacking) 防禦: 某些黑客會嘗試誘騙用戶去單擊一些看起來像是執行安全或無害功能的按鈕,但執行的卻是不相關的任務。 點擊劫持者 (Clickjacker) 通過使用透明框架,將特定的 UI 元素用令人誤解的文本和圖像加以覆蓋,從而將惡意代碼或僞裝代碼 (Redress) 嵌入到用戶界面中。 爲了幫助防止點擊劫持攻擊,網站所有者可以隨 HTML 頁面發送名爲 X-Frame-Options 的 HTTP 響應標頭,以限制設置頁面框架的方式。
X-Frame-Options: Deny如果 X-Frame-Options 值包含 Deny 標記,則 Internet Explorer 8 將阻止呈現包含在某個框架中的頁面。 如果該值包含 SameOrigin 標記,並且頂級瀏覽上下文不同於包含該指令的頁面的源,則 Internet Explorer 將不呈現該頁面。 所阻止的頁將被替換爲“此內容無法在框架中顯示”錯誤頁。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章