灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:1830回复:0

Chrome浏览器iframe跨域访问安全漏洞

楼主#
更多 发布于:2012-08-23 23:16

Chrome 浏览器的iframe跨域访问处理存在安全问题,可导致那些使用iframe进行跨域数据传送的网站受到攻击,跨域传送的数据可被恶意网站获取。
详细说明:测试用的Chrome 浏览器版本:18.0

iframe.contentWindow.name在iframe里的页面切换之后,仍然可以保留以前的内容,此种方法常被用来作JS的跨域数据获取。

正常通过iframe.contentWindow.name跨域数据获取的方法为:
1. www.jamcode.org上的页面中的JS创建一个iframe,src为google.com/test.html
2. google.com/test.html中的JS设置了window.name="数据内容"
3. 然后需要google.com/test.html中的JS*主动*location.replace跳转到jamcode.org/blank.html
这样跳转之后,iframe.contentWindow.name的内容不会丢失,并且,由于跳转完成之后,iframe与宿主页面已同域,www.jamcode.org中的JS就可以获取到iframe.contentWindow.name的内容,完成跨域数据的获取。


Chrome的安全漏洞

通过iframe.name跨域获取数据的一个必要信任步骤是,必须是iframe中的页面主动跳转到一个和宿主页面同域的页面。但在Chrome中,可以通过宿主页面的JS去设置iframe.src为自己域的一个页面,iframe.contentWindow.name仍然会保留着,导致任意恶意页面可以获取iframe.contentWindow.name上的数据。
利用漏洞的步骤:
1. www.jamcode.org上的页面中的JS创建一个iframe,src为google.com/test.html
2. google.com/test.html中的JS设置了window.name="数据内容"
3. www.jamcode.org在监听到iframe.onload事件之后,JS直接将iframe.src设置成www.jamcode.org/blank.html不必等待iframe中主动跳转,即可将iframe设置成同域的一个页面,并且window.name的数据不会丢失。
漏洞证明:google.com/test.html页面的代码:

<script>
window.name="uid=xxx; friends=1,23,44;...";
location.replace("plus.google.com/blank.html");
</script>

/evil.html的代码:

<script>
var iframe=document.createElement("iframe");
iframe.onload=function () {
  iframe.src="/blank.html";
  alert(iframe.contentWindow.name);
};
iframe.src="google.com/test.html";
</script>


修复方案:


限制为必须iframe中的页面主动中转才保留window.name的内容

iframe页面变化后即不再保留iframe.contentWindow.name的内容

作者Jam

喜欢0 评分0
游客

返回顶部