Android安全之Intent Scheme Url攻击

KayleeHiggs 7年前
   <h3><strong>0X01 前言</strong></h3>    <p>Intent scheme url是一种用于在web页面中启动终端app activity的特殊URL,在针对intent scheme URL攻击大爆发之前,很多android的浏览器都支持intent scheme url。</p>    <p>Intent scheme url的引入虽然带来了一定的便捷性,但从另外一方面看,给恶意攻击页面通过intent-based攻击终端上已安装应用提供了便利,尽管浏览器app已经采取了一定的安全策略来减少这一类风险,但显然是不够的。</p>    <p>2014年3月,一篇关于intent scheme url攻击的文章:</p>    <p>Whitepaper – Attacking Android browsers via intent scheme URLs</p>    <p>详细介绍了相关的攻击手法,之后国内的漏洞收集平台上开始被这一类型漏洞刷屏。</p>    <h3><strong>0X02 Intent scheme url解析</strong></h3>    <p>一个intent scheme url的使用示例:</p>    <p><img src="https://simg.open-open.com/show/4e1be6b54795fded92918ed652a22236.png"></p>    <p>如果浏览器支持intent scheme url,在加载了改web页面后,将根据url生成一个intent,并尝试通过intent打来指定的activity。此过程中浏览器的需要完成的工作可以拆分为3步:</p>    <p><strong>Step1:</strong></p>    <p>根据url生成对应的intent object,此过程通过以下代码完成:</p>    <p>Intent intent = Intent.parseUri(url);</p>    <p>intent scheme url的内容可以根据一下语法规则设置的比较完善:</p>    <p>intent:</p>    <pre>  <code class="language-java">HOST/URI-path // Optional host     #Intent;        package=[string];        action=[string];        category=[string];        component=[string];        scheme=[string];     end;    </code></pre>    <p><strong>Step2:</strong></p>    <p>intent过滤,安全起见,很多浏览器对step1中的intent object进行过滤,以抵御intent-based攻击,不用的浏览器,过滤规则各不相同。</p>    <p><strong>Step3:</strong></p>    <p>组件调用,最后一步就是使用step2过滤后的intent调用指定的组件,浏览器中一般使用Context#startActivityIfNeeded() 或者 Context#startActivity()方法实现。</p>    <p>下面是各大浏览器对Intent scheme URL的支持情况 :</p>    <p style="text-align:center"><img src="https://simg.open-open.com/show/d2006c803fd3f1e8e4666d248771775a.png"></p>    <h3><strong>0X03攻击场景</strong></h3>    <p>主要由两种攻击场景。</p>    <p><strong>类型1:浏览器攻击</strong></p>    <p>因为intent是浏览器依据url生成并以浏览器自己的身份发送的,因此攻击者恶意页面中的intent scheme url不仅可以调起导出组件,还可以调起私有组<strong>件。</strong></p>    <p><strong>类型2:终端上安装的任意APP</strong></p>    <p>intent-based攻击一般是通过终端上安装的恶意app来实现的,但通过浏览器加载包含特定intent scheme url的恶意页面,可以实现对终端上安装的任意app远程intent-based攻击的效果。在2013年东京的Pwn2Own上比赛上,次攻击方式被应用于攻陷三星Samsung Galaxy S4。</p>    <h3><strong>0X04 攻击案例</strong></h3>    <p>以下介绍三个浏览器的intent scheme url攻击案例,攻击主要源于这些浏览器在step2(也就是intent过滤过程)中存在缺陷。</p>    <p>Opera mobile for Android cookie theft</p>    <p>Opera浏览器中缺少intent过滤步骤,一次可以通过恶意页面中的intent scheme url调起浏览器的任意activity,包括私有的activity,通过如下攻击代码可以获取到Opera浏览器的cookie:</p>    <p style="text-align:center"><img src="https://simg.open-open.com/show/148223da83eeb551e55e6afdbc6268e7.jpg"></p>    <p>"com.admarvel.android.ads.AdMarvelActivity"是Opera浏览器的私有组件,"url=file:///data/data/com.opera.browser/app_opera/cookies"是Opera浏览器cookie文件的存放位置。</p>    <p>Chrome for Android UXSS (Universal XSS)</p>    <p>Chrome的UXSS漏洞利用相对复杂,这里先介绍一下Intent Selector。Intent Selector机制提供一种main intent不匹配的情况下可以设置替补的方案。如下的intent scheme url:</p>    <p style="text-align:center"><img src="https://simg.open-open.com/show/1180c811a3547957c4aafe16aa15f291.jpg"></p>    <p>其中“SEL”是selector intent的标识。</p>    <p>在chrome中包含以下代码:</p>    <p>1:Intent intent = Intent.parseUri(uri);</p>    <p>2:intent.addCategory("android.intent.category.BROWSABLE");</p>    <p>3:intent.setComponent(null);</p>    <p>4:context.startActivityIfNeeded(intent, -1);</p>    <p>第二行添加了BROWSABLE category(目标Activity允许本身通过 Web 浏览器启动,以显示链接引用的数据,以此过滤/防止一些不该被调起的组件被调起),第三行将组建设置为null,用以抵御intent-based攻击,但如果使用selector intent可以完美的bypass以上限制。</p>    <p>以下是android chrome上的一个UXSS攻击的POC:</p>    <p style="text-align:center"><img src="https://simg.open-open.com/show/40fbdfbd55d2fea27e3cc4510f82a4a1.jpg"></p>    <p><strong>Old stock browser cookie theft</strong></p>    <p>Android stock browser (com.android.browser)的问题类似于android chrome,同样是在step2中对intent的过滤问题,最终攻击者可以盗取浏览器的cookie。此漏洞可能只存在于Android 4.3以下的设备,之后的版本中不一定预装stock browser。</p>    <h3><strong>0X05 总结</strong></h3>    <p>有效抵御intent scheme url攻击的方法主要是在step2中对intent做严格的安全限制:</p>    <pre>  <code class="language-java">// convert intent scheme URL to intent object   Intent intent = Intent.parseUri(uri);   // forbid launching activities without BROWSABLE category   intent.addCategory("android.intent.category.BROWSABLE");   // forbid explicit call   intent.setComponent(null);   // forbid intent with selector intent   intent.setSelector(null);    // start the activity by the intent   context.startActivityIfNeeded(intent, -1);    </code></pre>    <h3><strong>0X06 参考</strong></h3>    <p>腾讯御安全为开发者推出了安全保护服务,其中包括漏洞扫描、应用加固、SO加固等,能够帮助企业软件发现潜在漏洞风险、防逆向、防篡改、防二次打包。有需求的团队可以登录御安全官网试用。</p>    <p> </p>    <p>来自:http://mobile.51cto.com/android-524918.htm</p>    <p> </p>