Blogger Information
Blog 33
fans 0
comment 0
visits 25864
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实例讲解 target=’_blank’ 安全漏洞
非常缪
Original
688 people have browsed it

如果你在页面上的超链接a标记上添加了target="_blank"属性,一个非常简单的钓鱼攻击的漏洞很可能就这样打开了。攻击者只需要在他的页面上放置简单的JavaScript代码,就能轻松的控制你的页面的显示。if(window.opener){  window.opener.location ="https://www.webhek.com";}

 

通常我们知道使用 window.open();语句时,我们可以获得opener句柄,但也许没注意到,通过target="_blank"点开的窗口、标签页,子窗口也能捕获opener句柄,通过这个句柄,子窗口可以修改父窗口的页面地址,让父窗口显示指定的页面。

如果你的页面上有个链接,链接到别处的网址,并且链接上使用了target="_blank"属性,那么,当用户浏览你的网页,并点击了这个链接,这个链接的页面除了能正常的弹出外,还可以修改你的页面窗口的地址,通常用户不会想到是后开启的窗口控制了前一个窗口,因为后开启的窗口和原始窗口不是同一个网站的页面。

下面是一个实际例子,CSDN的极客头条是一个很容易实现这个攻击的地方。(如果它修复了这个漏洞,那么这个演示将会失效。)

http://geek.csdn.net/news/detail/99960

进入上面提供的极客头条的一个文章链接页面,点击里面的页面链接地址,会弹出本页面,同时,极客头条的页面也会转向到另外一个受控制的页面。这个页面和极客头条没有关系,但后弹出的页面很轻松的替换了它的地址。

为了限制子页面通过

window.opener控制父页面,我们需要在页面上所有使用了target="_blank"的链接上添加rel="noopener"属性,但是,火狐浏览器并不支持这个有特殊意义的属性,火狐浏览器里需要写成rel="noreferrer",我们可以把它们的写法合并,写成rel="noopener noreferrer"。这样,子页面就获取不到父页面的句柄了。

 

我们还可以使用JavaScript来实现这个目的。

var otherWindow = window.open();otherWindow.opener =null;otherWindow.location = url;

但在Safari浏览器这种方法似乎不起作用。


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!