0409-Clickjacking简单介绍

# Clickjacking简单介绍

0x00 相关背景介绍
———–

Clickjacking(点击劫持)是由互联网安全专家罗伯特·汉森和耶利米·格劳斯曼在2008年首创的。

是一种视觉欺骗手段,在web端就是iframe嵌套一个透明不可见的页面,让用户在不知情的情况下,点击攻击者想要欺骗用户点击的位置。

由于点击劫持的出现,便出现了反frame嵌套的方式,因为点击劫持需要iframe嵌套页面来攻击。

下面代码是最常见的防止frame嵌套的例子:

“`
if(top.location!=location)
top.location=self.location;

“`

事实上,这种代码很容易被绕过,在后文中讨论。

0x01 防御的几种方式
————

防止frame嵌套的js使用代码由高到低比例:

“`
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))

“`

检测到后的处理方案:

“`
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)

“`

0x02 绕过的几种方式
————

对于使用parent.location来防御的可以使用多层嵌套的方式绕过。

### 一、例如防御代码为:

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

“`

建立两个页面:

1.html代码为:

“`

“`

重点是手机站点,很多主站做的很不错,但是手机站点没有做任何防护,很容易造成点击劫持。

### 五、location劫持

在IE浏览器中,如果能够在防御代码的前面可以插入form表单的话,可以利用form表单对location进行劫持。

“`

“`

用iframe嵌套此代码,可以看到没有跳转,执行了alert(1)。

相关案例:[WooYun: 腾讯微博clickhijacking(不要被你的双眼欺骗)](http://www.wooyun.org/bugs/wooyun-2013-019683)[WooYun: 新浪微博遭受clickhijacking攻击(已经有大量案例)](http://www.wooyun.org/bugs/wooyun-2012-09973)

0x03 推荐防御的方法:
————-

### 一、X-FRAME-OPTIONS

X-FRAME-OPTIONS是微软提出的一个http头,专门用来防御利用iframe嵌套的点击劫持攻击。

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

这个头有三个值:

“`
DENY // 拒绝任何域加载

SAMEORIGIN // 允许同源域下加载

ALLOW-FROM // 可以定义允许frame加载的页面地址

“`

php中设置示例:

“`
header ( “X-FRAME-OPTIONS:DENY”);

“`

### 二、目前最好的js的防御方案为:

“`




“`

© 版权声明
THE END
喜欢就支持一下吧
点赞0赞赏 分享
评论 抢沙发

请登录后发表评论

    请登录后查看评论内容