Chinaunix首页 | 论坛 | 博客
  • 博客访问: 289199
  • 博文数量: 57
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1474
  • 用 户 组: 普通用户
  • 注册时间: 2013-07-25 10:56
文章分类
文章存档

2014年(25)

2013年(32)

分类: 网络与安全

2013-07-31 10:03:19

0x00 相关背景介绍

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

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

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

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

if(top.location!=location)
    top.location=self.location;
事实上,这种代码很容易被绕过,在后文中讨论。

0x01 防御的几种方式

 

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

?
1
2
3
4
5
6
7
8
9
10
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))
检测到后的处理方案:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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)。

相关案例: 腾讯微博clickhijacking(不要被你的双眼欺骗)

 

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的防御方案为:
?
1
2
3
4
5
6
7
8
9
10
11
12




阅读(1440) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~