AirJD 焦点
AirJD

没有录音文件
00:00/00:00
加收藏

谈谈安卓的 Intent注入 by 汪涛@百度

发布者 airjd   简介 Ruby技术大会相关演讲
发布于 1441068144596  浏览 6982 关键词 Hybrid混合开发, 网络安全, Android 
分享到

第1页

2015-­‐8 汪涛



第2页

¡ 汪涛 of Baidu X-­‐Team,ID neobyte

¡ 多年安全评估经验,涉及⽅方向较杂,web安全、java安全、android安 全、前端安全…



第3页

Intent注⼊入的概念 Intent转换与复制 Action/Component/Data注入 PendingIntent误用 parseUri注入



第4页

¡ Android提供的⼀一种java环境下IPC的形式。Intent是⼀一种 IPC消息对象,用于向APP的组件请求⼀一次操作

§ 发送与接收组件可能运⾏行在同⼀一个APP或不同的APP(进程)中

§ 请求的操作可以是启动⼀一个Activity,Service或处理Broadcast

§ Intent中通常有Action(⾏行动)或Component(目标组件名),系 统据此决定接收Intent的目标组件

§ Intent中还通常包含额外的数据(Extras,Data),供目标组件处 理



Action



Compo



Intent



Data







Extras



第5页

¡ Intent是安卓app的重要本地攻击界面:APP公开 组件接收外部Intent数据处理时可能存在安全漏洞

¡ 实例:

§ Webview JsInterface

§ SQL injection

§ Path Traversal

§ 权限泄漏,⽹网络权限,读写短信的权限



Action



Compo



Intent



Data







Extras



目标 数据



第6页

¡ http://oasam.org/en/oasam/oasam-­‐dv-­‐data-­‐validation/oasam-­‐dv-­‐007-­‐ intent-­‐injection

¡ If user’s  input is loaded in a dynamic manner in the Intent data, a  malicious user could manipulate such data in order to execute code  through it. In particular, the existence of dynamic data must be checked  while including such data in an Intent, especially through the following  Intent methods: addCategory(), setAction(), setClass(), setClassName(),  setComponent(), setData() and setDataAndType().



外部输⼊入



App

Intent



startService



Activity Service



Receiver



第7页

¡ 本地Intent注⼊入的风险

§ 本地权限提升

§ 访问私有组件等

¡ 场景

§ 某APP存在本地Intent注⼊入漏洞,因此注⼊入的 Intent可以攻击其敏感的私有组件

§ System权限的APP若存在Intent注⼊入漏洞,可以 绕过IPC权限,启动⼀一些敏感的组件,例如 launchAnyWhere, BroadcastAnyWhere



第8页

¡ 远程Intent注⼊入的风险

§ 等同于有限的远程命令执⾏行 § 本地暴露组件的漏洞可从远程攻击

¡ 场景

§ 来自⽹网页中的JS,可以发起intent,播打电话 § 来自通信⽹网络中的短信,可以发起intent



第9页

Intent转换与复制

n
完整接收intent后转发 n
Intent代理 n
getParcelable() n
new Intent(intent)

PendingIntent误用

n
泄漏pendingintent可能使其 他进程修改intent并以APP的 身份发出



Action/Compo/Data注⼊入

n
构造intent的元素来自外部 n
Action注⼊入 n
Component注⼊入 n
Data注⼊入

parseUri注⼊入

n
 Intent.parseUri可解析String 为Intent,如果未进⾏行校验, 可能被攻击者篡改Intent



第10页

• ⼀一个开源的java bytecode 缺陷分析⼯工具

• 分析⼀一个目录下的所有class⽂文件

• 编译安卓4.4.4,得到所有中间过程的class⽂文件 (这样就⽆无需dex2jar),共约3万个class



第11页

Intent注入的概念 Intent转换与复制 Action/Component/Data注入 PendingIntent误用 parseUri注入



第12页

¡ 最早由申迪分析,AccountManager存在缺陷,恶意APP可 以发出任意intent来启动activity(绕过IPC权限限制)

( http://blogs.360.cn/360mobile/2014/08/19/launchanywhere-­‐google-­‐bug-­‐ 7699048/  )

¡ 本质上就是⼀一个intent注⼊入

android.accounts.AccountManager$AmsTask$Response.onResult(Bundle)



第13页

¡ Intent本身可以传递数据。如果在intent中传递⼀一个intent, 往往代表需要用这个intent发起⼀一个新的IPCàintent注⼊入

¡ 为了寻找这种Intent转换的特征,可以看看Bytecode

android.accounts.AccountManager$AmsTask$Response.onResult(Bundle)



第14页

¡ 在findbugs中扫描所有Bytecode指令,如果是checkcast, 进⼀一步检查是否是cast为intent类型



第15页

¡ 对Android 4.4全系统扫描后发现106例Intent的checkcast, 根据是否在同⽅方法中发送了该intent调整优先级,结果第 ⼀一个就是launchAnywhere漏洞,另外还发现⼀一个0day…



第16页

¡ ChooserActivity存在Intent注⼊入漏洞,恶意⽆无权限APP可以System权限 启动任意Activity(类似launchAnywhere)

¡ 安卓Framework层有⼀一个导出的Activity组件: ChooserActivity com.android.internal.app.ChooserActivity (4.4.4版截图)



第17页

¡ 启动该activity会从输⼊入intent中读取EXTRA_INTENT与 EXTRA_INITIAL_INTENTS,分别是⼀一个intent以及⼀一个intent数组,然 后传递给super.onCreate



第18页

¡ super类为com.android.internal.app.ResolverActivity,将启动用户选择 的intent



第19页

¡ 2012年(4.1)的⼀一个补丁中增加了对是否有权限启动 EXTRA_INTENT的检查,但依然遗漏了对EXTRA_INITIAL_INTENTS的 检查,所以可以利用EXTRA_INITIAL_INTENTS来launchAnywhere

¡ https://android.googlesource.com/platform/frameworks/base/+/5320eb8

938098c9824093f7f842a0a97bbc190a4%5E%21/#F4



第20页

¡ 但当我们去launch时,发现权限错误…

¡ http://developer.android.com/guide/topics/manifest/activity-­‐ element.html#multi

Whether an instance  of the activity can be launched into the process of the  component that started it -­‐ "true" if it can be, and "false" if not. The default value  is "false“. Normally, a new instance  of an activity is launched into the process of  the application that defined it



第21页

¡ com.android.server.am.ActivityRecord ¡ com.android.server.am.PendingIntentRecord



第22页

¡ com.android.server.am.ActivityManagerService ¡ com.android.server.am.ActivityStackSupervisor



第23页

¡ com.android.server.am.ActivityStackSupervisor



第24页

¡ 通过pendingintent,ChooserActivity将在 system进程启动并launch我们的intent



第25页

¡ 因为是system进程,可以 启动需要权限的Activity, 或者是私有的Activity

¡ Demo演示弹出两个图标

让用户选择,如果选择了 ⼿手机,将开始拨打电话



第26页

¡ 2014-­‐09-­‐15报告给Android,但是…

Thanks for the report. This issue  was previously reported to us by another  researcher. We're testing  a fix for the next release of Android. We ask that you keep this issue confidential until  our fix is released.

¡ 补丁 com.android.internal.app.ResolverActivity,startActivityAsCaller

¡ Fix issue #14617210: Apps can gain access to any ContentProvider with  grantUriPermissions (no user interaction required)   https://android.googlesource.com/platform/frameworks/base/+/028ceeb 472801bcfa5844fc89ed0da8463098824



第27页

¡ https://android.googlesource.com/platform/frameworks/base/+/android-­‐ 5.1.1_r8/packages/Shell/src/com/android/shell/BugreportWarningActivity.java



第28页

¡ https://android.googlesource.com/platform/packages/apps/Camera2/+/android-­‐ 5.1.1_r8/src/com/android/camera/ProxyLauncher.java



第29页

¡ https://android.googlesource.com/platform/packages/apps/Settings/+/android-­‐ 5.1.1_r8/src/com/android/settings/users/AppRestrictionsFragment.java



第30页

¡ https://android.googlesource.com/platform/packages/apps/Browser/+/android-­‐ 5.1.1_r8/src/com/android/browser/widget/BookmarkWidgetProxy.java



第31页

Intent注入的概念 Intent转换与复制 Action/Component/Data注⼊入 PendingIntent误用 parseUri注入



第32页

¡ Action/Component/Data仅仅是狭义的举例, 实际范畴是所有构成Intent的元素均可被注 ⼊入

¡ 攻击者可以控制发送intent的目标或数据, 或者是全部



Action



Compo



Intent



Data







Extras



第33页

¡ curesec发现的安卓拨打电话权限绕过漏洞CVE-­‐2013-­‐6272 

(<4.4.2,http://blog.curesec.com/article/blog/35.html)

com.android.phone.PhoneGlobals$NotificationBroadcastReceiver



第34页

¡ 用数据流分析⽅方法,分析java对象的数据污染扩散 ¡ source:binder接⼝口为数据⼊入⼝口 ¡ sink: setAction(), setClass(), setClassName(), setComponent(), setData() 

setDataAndType()这些为目标 ¡ 跨过程的数据流分析

¡ 缺陷:误报率较⾼高(>1k),但依然发现了⼀一个0dayJ



第35页

¡ WapPushManager中存在的SQL注⼊入,也是Intent注⼊入,攻 击者可以远程发送恶意wappush指令,让⼿手机启动组件

¡ 我们在2014-­‐10-­‐11报告安卓,2014-­‐11-­‐8确认

com.android.smspush.WapPushManager



第36页

¡ 通过模拟端⼝口发送wappush sms ¡ ⼿手机收到后,触发SQL注⼊入,查询出settings的component

并启动 ¡ 4.4.4的POC如下

0891683108200105f04408a00156 08860104216092902512237B0605 040b8423f00A065603B081EAAF2 720756e696f6e2073656c65637420 302c27636f6d2e616e64726f6964 2e73657474696e6773272c27636f6 d2e616e64726f69642e736574746 96e67732e53657474696e6773272c 302c302c302d2d200002066A008 509036D6F62696C65746964696E 67732E636F6D2F0001



第37页

Intent注入的概念 Intent转换与复制 Action/Component/Data注入 PendingIntent误用 parseUri注入



第38页

¡ PendingIntent,经常用于通知

§ Pending:延时的 § 包裹着真实的intent § 创建者的context

¡ A把将来要发送的intent打包, 然后交给B,让B在将来代表A 发出这个intent

¡ 即使A已经不存在,B也能以A 的context来发出这个intent

B篡改这个intent = intent注⼊入



第39页

¡ 安卓也意识到PendingIntent的风险,设置了限制,详见 android.content.Intent.fillin()

¡ 默认情况下(除非开发者设置特殊标记)



§ B⽆无法修改Component



§ 仅当A的原始Intent中action为空,B才可以修改action



¡ 但是,如果A的原始Intent中component与action都为空,B



就可以控制Intent的目标,B填⼊入Extras部分的数据直接合并



覆盖A的-­‐>目标与数据均被B控制-­‐>Intent注⼊入(注:这里描述的是⼤大部



分情况,忽视了pkg, data, type, category这些数据在intent解析中的影响)



Action



Intent



Extras



Compo



Data







目标 数据



第40页

¡ http://developer.android.com/reference/android/app/PendingIntent.html

By giving a PendingIntent to another application, you are granting it the right to  perform  the operation you have specified as if the other application was  yourself  (with the same permissions and identity). As such, you should be careful  about how you build the PendingIntent:  almost always, for example, the base  Intent  you supply should have the component name explicitly set to one of your  own components, to ensure  it is ultimately sent  there and nowhere else.



第41页

¡ 扫描每个method,根据情况调整告警级别

§ 发现有构造PendingIntent的⽅方法,例如getActivity,getBroadcast,getService, createPendingResult,getActivities,若有报告并设定告警级别为低

§ 在同⼀一个method中,扫描是否调用Intent的设置Component⽅方法,例如特定intent构 造函数,setClass,setClassName,setComponent等,若没有,调⾼高告警级别为中

§ 在同⼀一个method中,扫描是否调用Intent的设置action⽅方法,例如特定intent构造函 数, setAction等,若没有,调⾼高告警级别为⾼高

§ 其他⼀一些细节调整:例如开发⼈人员主动设置了相关的特殊标记,同⼀一个method中 用putExtra将PendingIntent打包到intent中



第42页

¡ 对Android 4.4全系统扫描后发现152例告警,其中⾼高优先级35例,发 现⼀一个0day…



第43页

¡ 安卓Settings中存在PendingIntent权限泄漏漏洞,恶意⽆无 权限app可以system权限发送⼀一个含action与数据的⼴广播

¡ 我们在2014-­‐9-­‐2报告安卓,2014-­‐9-­‐10确认

com.android.settings.accounts.AddAccountSettings.addAccount(String)



第44页

¡ 安装时提示⽆无需任何 权限

¡ 启动后自动伪造来自 任意⼿手机号的⼀一条短 信

¡ 另外⼀一个严重的 Demo中,启动后自 动重启用户⼿手机并清

除包括短信,通信录 等数据



第45页

¡ https://android.googlesource.com/platform/frameworks/base/+/android-­‐ 5.1.1_r8/keystore/java/android/security/KeyChain.java



第46页

¡ https://android.googlesource.com/platform/frameworks/opt/telephony/+/android-­‐ 5.1.1_r8/src/java/com/android/internal/telephony/gsm/GsmServiceStateTracker.java



第47页

Intent注入的概念 Intent转换与复制 Action/Component/Data注入 PendingIntent误用 parseUri注⼊入



第48页

¡ https://developer.chrome.com/multidevice/android/intents

A little  known feature in Android lets you  launch apps directly from  a web page  via an Android Intent. Only activities  that have the category filter,  android.intent.category.BROWSABLE are able to be invoked using this method  as it indicates that the application is safe to open from the Browser.

基于intent的URI语法如下:  (可参考安卓源码android.content.Intent.parseUri() intent:

HOST/URI-­‐path // Optional host  #Intent; 

package=[string];  action=[string];  category=[string];  component=[string];  scheme=[string];  end;

参考: [1]  http://www.mbsd.jp/Whitepaper/IntentScheme.pdf [2]  http://drops.wooyun.org/papers/2893



第49页

¡ com.android.webview.chromium.WebViewContentsClientAdapter.java



第50页

¡ 直接查找intent.parseUri⽅方法的调用即可 ¡ 对Android 4.4全系统扫描后发现9例告警,并未发现明显的安全问题 ¡ 于是我们去看Chrome,于是发现⼀一个0day…



第51页

¡ 检查Intent的action是否等于某个常量字符串,符合条件的intent被启 动activity。

¡ 但可以直接在uri中指定component,⽆无视action,启动任意activity, 即使未声明BROWSABLE

¡ 我们在2014-­‐10-­‐9报告Chrome,2014-­‐10-­‐9确认



第52页

¡ 访问页面自动触发(Chrome  Android <=37.0.2062.117)

<script> var url =  "intent:#Intent;action=com.google.android.apps.auth enticator.AUTHENTICATE;S.url=javascript:eval(decode URIComponent('location%3D%22http%3A%2F%2Fww w.baidu.com%2F%22%3Bwindow.onload%3Dfunction() %20%7Balert(document.cookie)%7D%3B'));SEL;compo nent=com.android.chrome/com.google.android.apps.c hrome.help.HelpActivity;end"; location.href = url; </script>



第53页

¡ 访问⽹网页自动触发,详见 https://code.google.com/p/chromiu m/issues/detail?id=421817

¡ 演示视频是基于小米语音助⼿手,与 上述链接中的POC略有修改



第54页

¡ Intent注⼊入漏洞,并非⼀一个新的概念,它早就存在。它比 较稀少,因此容易被忽视

¡ 归纳了Intent注⼊入的4种形式:Intent转换与复制、 Action/Component/Data注⼊入、PendingIntent误用与 parseUri注⼊入

¡ 归纳了利用自动化的⼯工具发现这4类形式的⽅方法,通过批 量的扫描,可以轻易发现这些漏洞

¡ 在每种都找到了⼀一个安卓OS或Chrome安卓版的0day,达 到本地提权或远程命令执⾏行的效果,分别得到了Android 与Chrome的官⽅方致谢

¡ Android官⽅方致谢:http://source.android.com/devices/tech/security/overview/acknowledgements.html ¡ Chrome官⽅方致谢:http://googlechromereleases.blogspot.com/2014/11/stable-­‐channel-­‐update_18.html



第55页

¡ 谢谢!



支持文件格式:*.pdf
上传最后阶段需要进行在线转换,可能需要1~2分钟,请耐心等待。