通过 iframe 实现 xss(Enabling cross-site scripting XSS via an iframe)
2013-07-25 15:02
169 查看
这篇文章虽然是2008年写的,比较旧,但是问题讲的通俗易懂,一看就明白那种,感觉不错,就翻译出来了。
有这样的一个想当普遍的场景就是:你有一个包含iframe的页面,而这个iframe的src是指向和当前页面不同的域名。这样做是没错的,记住iframe就是这样设计的!
接下来的示例图展示我们要讨论的一种方案:
现在你想单击iframe里的一个链接,在父页面里来触发一个动作(可能是在父页面里提交一个表单,可能是在父页面里调整iframe的高度)。这时你遇到了困难,因为浏览器不让你访问不用域名下的javascript脚本里的方法或者属性。
如果一个iframe的src指向的域名与包含他的父页面的域名不一样,这时父页面和iframe通信就会遇到同源的限制,因为浏览器基于内建的安全策略会阻止这种行为。一个相对不那么痛苦的解决方案是需要一个额外的iframe(请看下图)。
现实中的例子:
你可以在 sky movies上看到一个正在运行的例子,在这个网站上iframe随着它包含的iframe改变而改变大小。这是在iframe内部控制的。
首先,为什么我们需要实现像这样的解决方案?
因为,movies.sky.com的首页能够设置iframe的高度,但不能获得iframe的内容高度,而iframe 的document能够获得高度但是不能设置包围他的iframe的高度。
关于解决方案每个组件块的解释:
使用下面的例子页面,我们能够创建一个关于这种技术的演示。
下面是主页面的源码(上边草图中标的[1]),它包含一个iframe和一个将被用来设置iframe大小的方法。
下面是iframe页面的源码(上边草图中标的[2]),它包含一个额外的iframe和一些实习技术的脚本。
原文:
http://www.codecouch.com/2008/10/cross-site-scripting-xss-using-iframes/
有这样的一个想当普遍的场景就是:你有一个包含iframe的页面,而这个iframe的src是指向和当前页面不同的域名。这样做是没错的,记住iframe就是这样设计的!
接下来的示例图展示我们要讨论的一种方案:
现在你想单击iframe里的一个链接,在父页面里来触发一个动作(可能是在父页面里提交一个表单,可能是在父页面里调整iframe的高度)。这时你遇到了困难,因为浏览器不让你访问不用域名下的javascript脚本里的方法或者属性。
如果一个iframe的src指向的域名与包含他的父页面的域名不一样,这时父页面和iframe通信就会遇到同源的限制,因为浏览器基于内建的安全策略会阻止这种行为。一个相对不那么痛苦的解决方案是需要一个额外的iframe(请看下图)。
现实中的例子:
你可以在 sky movies上看到一个正在运行的例子,在这个网站上iframe随着它包含的iframe改变而改变大小。这是在iframe内部控制的。
首先,为什么我们需要实现像这样的解决方案?
因为,movies.sky.com的首页能够设置iframe的高度,但不能获得iframe的内容高度,而iframe 的document能够获得高度但是不能设置包围他的iframe的高度。
关于解决方案每个组件块的解释:
使用下面的例子页面,我们能够创建一个关于这种技术的演示。
下面是主页面的源码(上边草图中标的[1]),它包含一个iframe和一个将被用来设置iframe大小的方法。
<html> <head> <title>Page hosted on example.com</title> <script type="text/javascript"> function resizeIframeHeight(nHeight) { var iframe = document.getElementById('mainIframe'); iframe.setAttribute('height', nHeight); } </script> </head> <body> <h1>This page is hosted on the example.com domain</h1> <p>The iframe below is hosted on the example.org domain</p> <iframe id="mainIframe" width="400" height="200" src="http://example.org/iframedDocument.html">Iframes not supported.</iframe> </body> </html>
下面是iframe页面的源码(上边草图中标的[2]),它包含一个额外的iframe和一些实习技术的脚本。
<html> <head> <title>Page hosted on example.org</title> <script type="text/javascript"> function updateIframeHeight() { var iframe = document.getElementById('hiddenIframe'); var newHeight = parseInt(document.body.offsetHeight,10) + 10; iframe.src = 'http://example.com/xssEnabler.html?height=' + newHeight; } </script> </head> <body onload="updateIframeHeight()"> <h1>This page is hosted on the example.org domain</h1> <p>The iframe below is hosted on the example.com domain (and be styled to be hidden)</p> <iframe id="hiddenIframe" width="100" height="100" src="http://example.com/xssEnabler.html">Iframes not supported.</iframe> </body> </html>最后一个源文件驻留在同一个域中(上边草图中标的[3]),它包含一些脚本来截取高度参数,然后把它传给主要页面中用来设置iframe大小的函数。在上面的代码中,它指的是“http://example.org/xssEnabler.html”的内容,被保存成一个静态文件,实现的代码就是下面你看到的。
<script type="text/javascript"> function getFirstParamFromLocation() { var pair = window.location.search.substring(1); var parts = pair.split('='); return parts[1]; } var nHeight = getFirstParamFromLocation(); try { window.top.resizeIframeHeight(height); } catch(e) {}; </script>很明显你不能使用“example.com”和“ example.org”在你的方案中,它们仅仅是用来给你使用的每个文件标识不同域名的。
原文:
http://www.codecouch.com/2008/10/cross-site-scripting-xss-using-iframes/
相关文章推荐
- 如何通过单页实现类似iframe左右侧结构
- Cross Site Scripting Attacks: Xss Exploits and Defense
- js通过iframe加载外部网页的实现代码
- 跨站脚本攻击(Cross‐Site Scripting (XSS))
- 通过jsonObject toBean方法,实现对象的实例化
- You may receive an "Access Denied" or a "Permission Denied" scripting error message when you browse a secure Web site that contains multiple frames
- XSS Cross Site Scripting
- js自定义方法通过隐藏iframe实现文件下载
- 文件上传 通过隐藏iframe的方式来实现ajax上传文件并返回处理结果 ie乱码问题解决
- XSS(Cross-Site-Scripting)跨站攻击方式以及防御[待续]
- 收藏《CnForums和已有系统的整合方案》《通过IViewObject接口,取浏览器的图象,实现SNAP 》《SNAP的另类实现,采用iFRAME,内嵌框架的形式.》等
- Cross-Site Scripting XSS 跨站攻击全攻略 分类: 系统架构 2015-07-08 12:25 21人阅读 评论(2) 收藏
- WebGoat学习——跨站脚本攻击(Cross‐Site Scripting (XSS))
- Implementing a Neural Network from Scratch in Python – An Introduction(通过python中的Scratch来实现神经网络--简介)
- Cross-Site Scripting XSS 跨站攻击全攻略
- Web安全之XSS(Cross Site Scripting)深入理解
- CS131-PA2 通过聚类实现前/背景分离 Foreground-Background Segmentation via Clustering
- QQ可以通过 连接 http://wpa.qq.com/msgrd?V=1&Uin=13284200&Site='在线咨询'&Menu=yes 实现会话
- 如何通过单页实现类似iframe左右侧结构
- 通过P3P协议,实现跨域set cookie,解决同域IFRAME中SESSION传递失效问题