Exploiting Content Providers
Intro
A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolver class. A content provider can use different ways to store its data and the data can be stored in a database, in files, or even over a network.
It has to be declared inside the Manifest.xml file. Example:
<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>In this case, it's necessary the permission READ_KEYS to access content://com.mwr.example.sieve.DBContentProvider/Keys
(Also, notice that in the next section we are going to access /Keys/ which isn't protected, that's because the developer got confused and protected /Keys but declared /Keys/)
Maybe you can access private data or exploit some vulnerability (SQL Injection or Path Traversal).
Get info from exposed content providers
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: FalseWe can reconstruct part of the content URIs to access the DBContentProvider, because we know that they must begin with “content://” and the information obtained by Drozer inside Path: /Keys.
Drozer can guess and try several URIs:
You should also check the ContentProvider code to search for queries:

Also, if you can't find full queries you could check which names are declared by the ContentProvider on the onCreate method:

The query will be like: content://name.of.package.class/declared_name
Database-backed Content Providers
Probably most of the Content Providers are used as interface for a database. Therefore, if you can access it you could be able to extract, update, insert and delete information. Check if you can access sensitive information or try to change it to bypass authorisation mechanisms.
When checking the code of the Content Provider look also for functions named like: query, insert, update and delete:


Because you will be able to call them
Query content
Insert content
Quering the database you will learn the name of the columns, then, you could be able to insert data in the DB:

Note that in insert and update you can use --string to indicate string, --double to indicate a double, --float, --integer, --long, --short, --boolean
Update content
Knowing the name of the columns you could also modify the entries:

Delete content

SQL Injection
It is simple to test for SQL injection (SQLite) by manipulating the projection and selection fields that are passed to the content provider. When quering the Content Provider there are 2 interesting arguments to search for information: --selection and --projection:

You can try to abuse this parameters to test for SQL injections:
Automatic SQLInjection discovery by Drozer
File System-backed Content Providers
Content providers could be also used to access files:

Read file
You can read files from the Content Provider
Path Traversal
If you can access files, you can try to abuse a Path Traversal (in this case this isn't necessary but you can try to use "../" and similar tricks).
Automatic Path Traversal discovery by Drozer
References
Last updated