--- title: "Drozer Tutorial" section: "Mobile" sectionSlug: "mobile-pentesting" sourcePath: "src/mobile-pentesting/android-app-pentesting/drozer-tutorial/README.md" sourceUrl: "https://github.com/HackTricks-wiki/hacktricks/blob/188de82beb54e70956b2952367a0af91d26758b8/src/mobile-pentesting/android-app-pentesting/drozer-tutorial/README.md" sha: "188de82beb54e70956b2952367a0af91d26758b8" isIndex: true modified: true license: "CC-BY-NC-4.0" --- # Drozer Tutorial ## APKs to test - [Sieve](https://github.com/mwrlabs/drozer/releases/download/2.3.4/sieve.apk) (from mrwlabs) - [DIVA](https://payatu.com/wp-content/uploads/2016/01/diva-beta.tar.gz) **Parts of this tutorial were extracted from the** [**Drozer documentation pdf**](https://labs.withsecure.com/content/dam/labs/docs/mwri-drozer-user-guide-2015-03-23.pdf)**.**[[1]](#references) ## Installation Install Drozer Client inside your host. Download it from the [latest releases](https://github.com/mwrlabs/drozer/releases). ```bash pip install drozer-2.4.4-py2-none-any.whl pip install twisted pip install service_identity ``` Download and install drozer APK from the [latest releases](https://github.com/mwrlabs/drozer/releases). At this moment it is [this](https://github.com/mwrlabs/drozer/releases/download/2.3.4/drozer-agent-2.3.4.apk). ```bash adb install drozer.apk ``` ### Starting the Server Agent is running on port 31415, we need to [port forward](https://en.wikipedia.org/wiki/Port_forwarding) to establish the communication between the Drozer Client and Agent, here is the command to do so:[[4]](#references) ```bash adb forward tcp:31415 tcp:31415 ``` Finally, **launch** the **application** and press the bottom "**ON**" ![Installation - Starting the Server: Finally, launch the application and press the bottom " ON "](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28459%29.png) And connect to it: ```bash drozer console connect ``` ## Interesting Commands | **Commands** | **Description** | | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | | **Help MODULE** | Shows help of the selected module | | **list** | Shows a list of all drozer modules that can be executed in the current session. This hides modules that you don’t have appropriate permissions to run. | | **shell** | Start an interactive Linux shell on the device, in the context of the Agent. | | **clean** | Remove temporary files stored by drozer on the Android device. | | **load** | Load a file containing drozer commands and execute them in sequence. | | **module** | Find and install additional drozer modules from the Internet. | | **unset** | Remove a named variable that drozer passes to any Linux shells that it spawns. | | **set** | Stores a value in a variable that will be passed as an environmental variable to any Linux shells spawned by drozer. | | **shell** | Start an interactive Linux shell on the device, in the context of the Agent | | **run MODULE** | Execute a drozer module | | **exploit** | Drozer can create exploits to execute in the decide. `drozer exploit list` | | **payload** | The exploits need a payload. `drozer payload list` | ### Package Find the **name** of the package filtering by part of the name:[[6]](#references) ```bash dz> run app.package.list -f sieve com.mwr.example.sieve ``` **Basic Information** of the package: ```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 ``` Read **Manifest**: ```bash run app.package.manifest jakhar.aseem.diva ``` **Attack surface** of the package: ```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 ``` - **Activities**: You may be able to start an activity and bypass authorization that should prevent untrusted callers from launching it. - **Content providers**: Maybe you can access private data or exploit some vulnerability (SQL Injection or Path Traversal).[[3]](#references) - **Services**: - **is debuggable**: [Learn more](#is-debuggable) ### Activities An exported activity component’s “android:exported” value is set to **“true”** in the AndroidManifest.xml file: ```html ``` **List exported activities**: ```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 ``` **Start activity**: You may be able to start an activity and bypass authorization that should prevent untrusted callers from launching it.[[5]](#references) ```bash dz> run app.activity.start --component com.mwr.example.sieve com.mwr.example.sieve.PWList ``` You can also start an exported activity from **adb**: - PackageName is com.example.demo - Exported ActivityName is com.example.test.MainActivity ```bash adb shell am start -n com.example.demo/com.example.test.MainActivity ``` ### Content Providers This post was so big to be here so **you can** [**access it in its own page here**](/hacktricks/mobile-pentesting/android-app-pentesting/drozer-tutorial/exploiting-content-providers). ### Services A exported service is declared inside the Manifest.xml: ```html ``` Inside the code **check** for the **`handleMessage`**function which will **receive** the **message**: ![Content Providers - Services: Inside the code check for the handleMessage function which will receive the message](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%2882%29.png) #### List service ```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 ``` #### **Interact** with a service ```bash app.service.send Send a Message to a service, and display the reply app.service.start Start Service app.service.stop Stop Service ``` #### Example Check the **drozer** help for `app.service.send`: ![Interact with a service - Example: Take a look to the drozer help for app.service.send](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%281079%29.png) Note that you will be sending first the data inside "_msg.what_", then "_msg.arg1_" and "_msg.arg2_", you should check inside the code **which information is being used** and where.\ Using the `--extra` option you can send something interpreted by "_msg.replyTo"_, and using `--bundle-as-obj` you create and object with the provided details. In the following example: - `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 ``` ![Interact with a service - Example: 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...](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28647%29.png) ### Broadcast Receivers **In the Android basic info section you can see what is a Broadcast Receiver**. After discovering this Broadcast Receivers you should **check the code** of them. Pay special attention to the **`onReceive`** function as it will be handling the messages received. #### **Detect all** broadcast receivers ```bash run app.broadcast.info #Detects all ``` #### Check broadcast receivers of an app ```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 ``` #### Broadcast **Interactions** ```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 ``` #### Send a message In this example abusing the [FourGoats apk](https://github.com/linkedin/qark/blob/master/tests/goatdroid.apk) Content Provider you can **send an arbitrary SMS** any non-premium destination **without asking** the user for permission. ![Broadcast Interactions - Send a message: In this example abusing the FourGoats apk Content Provider you can send an arbitrary SMS any non-premium destination without asking the user for...](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28415%29.png) ![Broadcast Interactions - Send a message: In this example abusing the FourGoats apk Content Provider you can send an arbitrary SMS any non-premium destination without asking the user for...](https://raw.githubusercontent.com/HackTricks-wiki/hacktricks/188de82beb54e70956b2952367a0af91d26758b8/src/images/image%20%28573%29.png) If you read the code, the parameters "_phoneNumber_" and "_message_" must be sent to the Content Provider. ```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 debuggable A production APK should never be debuggable.\ If it is, you can **attach a Java debugger** to the running application, inspect it at runtime, set breakpoints, step through execution, read variable values, and even change them. [InfoSec Institute provides a detailed walkthrough](/hacktricks/mobile-pentesting/android-app-pentesting/exploiting-a-debuggeable-applciation) on analyzing debuggable applications and injecting runtime code.[[2]](#references) When an application is debuggable, it will appear in the Manifest: ```xml