# Drozer Tutorial

<details>

<summary><strong>从零开始学习 AWS 黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS 红队专家）</strong></a><strong>！</strong></summary>

支持 HackTricks 的其他方式：

* 如果您想看到您的**公司在 HackTricks 中做广告**或**下载 PDF 版本的 HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
* 探索[**PEASS 家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)
* **加入** 💬 [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**电报群组**](https://t.me/peass) 或在 **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live) 上 **关注**我们。
* 通过向 [**HackTricks**](https://github.com/carlospolop/hacktricks) 和 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github 仓库提交 PR 来分享您的黑客技巧。

</details>

<img src="/files/wQPam8C1YmPwZ2KLeMOE" alt="" data-size="original">

**漏洞赏金提示**：**注册** Intigriti，这是一家由黑客创建的高级**漏洞赏金平台**！立即加入我们，访问 [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks)，开始赚取高达\*\*$100,000\*\*的赏金！

{% embed url="<https://go.intigriti.com/hacktricks>" %}

## 要测试的 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
```

下载并安装 drozer APK 文件从[最新发布版本](https://github.com/mwrlabs/drozer/releases)。此刻它是[这个](https://github.com/mwrlabs/drozer/releases/download/2.3.4/drozer-agent-2.3.4.apk)。

```bash
adb install drozer.apk
```

### 启动服务器

代理正在端口31415上运行，我们需要进行[端口转发](https://en.wikipedia.org/wiki/Port_forwarding)以建立Drozer客户端和代理之间的通信，以下是执行此操作的命令：

```bash
adb forward tcp:31415 tcp:31415
```

最后，**启动**该**应用程序**并按下底部的 "**ON**"

![](/files/fKXbbNgyTd1fe1gXsKkT)

然后连接到它：

```bash
drozer console connect
```

## 有趣的命令

| **命令**          | **描述**                                           |
| --------------- | ------------------------------------------------ |
| **Help MODULE** | 显示所选模块的帮助信息                                      |
| **list**        | 显示当前会话中可以执行的所有drozer模块的列表。这会隐藏您没有适当权限运行的模块。      |
| **shell**       | 在设备上以代理的上下文启动一个交互式Linux shell。                   |
| **clean**       | 删除Android设备上drozer存储的临时文件。                       |
| **load**        | 加载包含drozer命令并按顺序执行它们的文件。                         |
| **module**      | 从互联网查找并安装额外的drozer模块。                            |
| **unset**       | 删除drozer传递给任何Linux shell的命名变量。                   |
| **set**         | 将一个值存储在一个变量中，该值将作为环境变量传递给drozer生成的任何Linux shell。 |
| **shell**       | 在设备上以代理的上下文启动一个交互式Linux shell。                   |
| **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
```

阅读 **Manifest**：

```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
```

* **Activities**: 也许您可以启动一个活动并绕过某种应该阻止您启动它的授权。
* **Content providers**: 也许您可以访问私人数据或利用一些漏洞（SQL注入或路径遍历）。
* **Services**:
* **is debuggable**: [了解更多](#is-debuggeable)

### 活动

在AndroidManifest.xml文件中，导出的活动组件的“android:exported”值设置为\*\*“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
* 导出的 ActivityName 为 com.example.test.MainActivity

```bash
adb shell am start -n com.example.demo/com.example.test.MainActivity
```

### 内容提供者

这篇文章内容太多了，**你可以**[**在这里访问它的独立页面**](/mobile-pentesting/android-app-pentesting/drozer-tutorial/exploiting-content-providers.md)。

### 服务

一个导出的服务在 Manifest.xml 中声明：

```markup
<service android:name=".AuthService" android:exported="true" android:process=":remote"/>
```

在代码中**检查**`handleMessage`函数，该函数将**接收**消息：

![](/files/Jggj2c5Zn4YxonODizz4)

#### 列出服务

```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**帮助：

![](/files/xES9zmnQujeAzNlarwCU)

请注意，您将首先发送数据内部的"*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
```

![](/files/pCFo9GI10Hn3XEbO5B0H)

### 广播接收器

**在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)的内容提供程序，您可以向任何非高级目的地**发送任意短信**，而无需**请求**用户的权限。

![](/files/hju4hfCJeywCLmtYmvLy)

![](/files/3OWeKjKbHYmWaxVh1iY7)

如果您阅读代码，必须将参数"*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!"
```

### 是否可调试

生产 APK 不应该是可调试的。\
这意味着你可以**连接 Java 调试器**到运行中的应用程序，实时检查它，设置断点，逐步执行，收集变量值甚至修改它们。[InfoSec 研究所有一篇出色的文章](/mobile-pentesting/android-app-pentesting/exploiting-a-debuggeable-applciation.md)关于当你的应用程序是可调试的时候如何深入挖掘并注入运行时代码。

当一个应用程序是可调试的时候，它会出现在清单文件中：

```xml
<application theme="@2131296387" debuggable="true"
```

您可以使用**Drozer**找到所有可调试的应用程序：

```bash
run app.package.debuggable
```

## 教程

* <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://www.hackingarticles.in/android-penetration-testing-drozer/>
* <https://medium.com/@ashrafrizvi3006/how-to-test-android-application-security-using-drozer-edc002c5dcac>

## 更多信息

* <https://blog.dixitaditya.com/android-pentesting-cheatsheet/>

<img src="/files/wQPam8C1YmPwZ2KLeMOE" alt="" data-size="original">

**漏洞赏金提示**：**注册** Intigriti，一个由黑客创建的高级**漏洞赏金平台**！立即加入我们，访问 [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks)，开始赚取高达\*\*$100,000\*\*的赏金！

{% embed url="<https://go.intigriti.com/hacktricks>" %}

<details>

<summary><strong>从零开始学习AWS黑客技术，成为专家</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE（HackTricks AWS Red Team Expert）</strong></a><strong>！</strong></summary>

支持HackTricks的其他方式：

* 如果您想在HackTricks中看到您的**公司广告**或**下载PDF版本的HackTricks**，请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 探索[**PEASS家族**](https://opensea.io/collection/the-peass-family)，我们的独家[**NFT**](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord群**](https://discord.gg/hRep4RUj7f) 或 [**电报群**](https://t.me/peass) 或在**Twitter**上关注我们 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hacktricks.xsx.tw/mobile-pentesting/android-app-pentesting/drozer-tutorial.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
