- 注册时间
- 2012-11-28
- 最后登录
- 2021-2-12
- 阅读权限
- 200
- 积分
- 3774
- 精华
- 0
- 帖子
- 116
  
ta_mind | mb_qb7 2013-3-19 01:56 |
---|
classn_01: 366 classn_02 [LV.9]以坛为家II
|
点击劫持漏洞 X-Frame-Options HTTP 响应头, 可以指示浏览器是否应该加载一个 iframe 中的页面。 网站可以通过设置 X-Frame-Options 阻止站点内的页面被其他页面嵌入从而防止点击劫持
方法一:常见的比如使用js,判断顶层窗口跳转:
1
2
3
4
5
6
| js 代码:
(function () {
if (window != window.top) {
window.top.location.replace(window.location); //或者干别的事情
}
})();
|
一般这样够用了,但是有一次发现失效了,看了一下人家网站就是顶层窗口中的代码,发现这段代码:
1
2
3
| js 代码:
var location = document.location;
// 或者 var location = "";
|
轻轻松松被破解了,悲剧。
注:此方式破解对IE6,IE7,IE9+、Chrome、firefox无效
方法二:meta 标签:基本没什么效果,所以也放弃了:
1
2
| html 代码:
<meta http-equiv="Windows-Target" contect="_top">
|
方法三:使用HTTP 响应头信息中的 X-Frame-Options属性
使用 X-Frame-Options 有三个可选的值:
- DENY:浏览器拒绝当前页面加载任何Frame页面
- SAMEORIGIN:frame页面的地址只能为同源域名下的页面
- ALLOW-FROM:origin为允许frame加载的页面地址
换一句话说,如果设置为 DENY,不光在别人的网站 frame 嵌入时会无法加载,在同域名页面中同样会无法加载。另一方面,如果设置为 SAMEORIGIN,那么页面就可以在同域名页面的 frame 中嵌套
绝大部分浏览器支持:
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari | Basic support | 4.1.249.1042 | 3.6.9 (1.9.2.9) | 8.0 | 10.5 | 4.0 |
配置 Apache 配置 Apache 在所有页面上发送 X-Frame-Options 响应头,需要把下面这行添加到 'site' 的配置中:
1
| Header always append X-Frame-Options SAMEORIGIN
|
配置 nginx 配置 nginx 发送 X-Frame-Options 响应头,把下面这行添加到 'http', 'server' 或者 'location' 的配置中:
1
| add_header X-Frame-Options SAMEORIGIN;
|
配置 IIS 配置 IIS 发送 X-Frame-Options 响应头,添加下面的配置到 Web.config 文件中:
1
2
3
4
5
6
7
8
9
10
11
| <system.webServer>
...
<httpProtocol>
<customHeaders>
<add name="X-Frame-Options" value="SAMEORIGIN" />
</customHeaders>
</httpProtocol>
...
</system.webServer>
|
结果 在 Firefox 尝试加载 frame 的内容时,如果 X-Frame-Options 响应头设置为禁止访问了,那么 Firefox 会用 about:blank 展现到 frame 中。也许从某种方面来讲的话,展示为错误消息会更好一点。
|
|