通过 iframe 实现 xss(Enabling cross-site scripting XSS via an iframe)

这篇文章虽然是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大小的方法。

<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 οnlοad="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/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值