# CVE-2016-1779技术分析及其背后的故事 **Author:xisigr@腾讯玄武实验室** 0x00 前言 ======= * * * Geolocation API被用来获取用户主机设备的地理位置,并且它有一套完整的保护用户隐私的机制。但CVE-2016-1776这个漏洞,绕过了Geolocation认证源的安全机制,并有可能导致用户隐私泄漏。本文在分析CVE-2016-1779漏洞成因的基础上探讨了Geolocation隐私机制,其中穿插的获取苹果公司的地理位置的“故事”,对用户隐私更是一个警醒。 0x01 CVE-2016-1776 ================== * * * 在IOS中Geolocation认证是由UIWebView来做处理,攻击者可以绕过同源策略使认证框在任意域弹出,并且当用户点击允许后可获取到用户的地理位置。在IOS平台中,Safari和Chrome都受到这个漏洞的影响。 受影响产品:WebKit in Apple iOS < 9.3 and Safari < 9.1,Chrome 漏洞修复日期:2016/3/21 漏洞公告: * [https://support.apple.com/HT206166](https://support.apple.com/HT206166) * [https://support.apple.com/HT206171](https://support.apple.com/HT206171) * [http://lists.apple.com/archives/security-announce/2016/Mar/msg00000.html](http://lists.apple.com/archives/security-announce/2016/Mar/msg00000.html) * [http://lists.apple.com/archives/security-announce/2016/Mar/msg00005.html](http://lists.apple.com/archives/security-announce/2016/Mar/msg00005.html) 0x02 漏洞分析 ========= * * * ### 2.1 Geolocation API的安全隐私策略 在W3C官方文档描述中,可以清晰的了解到Geolocation API的安全隐私策略。其中下面这条和我们今天分析的CVE-2016-1776相关 > 4.1 Privacy considerations for implementers of the Geolocation API > > User agents must not send location information to Web sites without the express permission of the user. User agents must acquire permission through a user interface, unless they have prearranged trust relationships with users, as described below. The user interface must include the host component of the document's URI [URI]. Those permissions that are acquired through the user interface and that are preserved beyond the current browsing session (i.e. beyond the time when the browsing context[BROWSINGCONTEXT] is navigated to another URL) must be revocable and user agents must respect revoked permissions. > > [https://www.w3.org/TR/geolocation-API/](https://www.w3.org/TR/geolocation-API/) 这条安全策略明确指出:“Geolocation必须经过用户的许可才可以使用,除非已经预先确认了信任关系。浏览器在使用Geolocation时会弹出一个认证框来通知用户,并且在这个认证框的UI上必须包含此页面的URI。”对于这条策略,当下主流浏览器都已经实现。 ### 2.2 认证框的源 触发Geolocation的认证框很简单,我们只要运行下面的代码即可,前提是之前没有允许当前域获取Geolocation。 ``` ``` 例如:http://www.test.com/geo.html。运行后,浏览器会在当前页面上弹出认证对话框,对话框的UI上会显示来源:www.test.com。 ### 2.3 PoC Exploit Code of CVE-2016-1779 在2.2中是触发Geolocation认证源的一个简单流程。从这个过程中,我有了以下的想法。 * 可否改变认证源。 * 如果可以改变,是否可以为空。 于是,按照这个思路,开始了我的测试之旅。在这个过程中,发现IOS下Safari和Chrome在使用`data:`来解析这段代码时,认证源头将为“`://`” ``` data:text/html;base64,PHNjcmlwdD4KZnVuY3Rpb24gc3VjY2Vzcyhwb3NpdGlvbikge30KbmF2aWdhdG9yLmdlb2xvY2F0aW9uLmdldEN1cnJlbnRQb3NpdGlvbihzdWNjZXNzKTsKPC9zY3JpcHQ+Cg== ``` safari:  chrome:  接下来,我进一步优化了POC,如下 ```