mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['src/mobile-pentesting/android-app-pentesting/drozer-tutoria
This commit is contained in:
parent
9698207396
commit
8a268aa6f4
@ -4,7 +4,7 @@
|
||||
|
||||
## Intro
|
||||
|
||||
数据是通过一个称为 **content provider** 的组件在一个应用程序与其他应用程序之间 **按请求提供** 的。这些请求通过 **ContentResolver class** 方法进行管理。内容提供者可以将其数据存储在各种位置,例如 **数据库**、**文件** 或通过 **网络**。
|
||||
数据是通过一个称为 **content provider** 的组件在应用程序之间 **按请求提供** 的。这些请求通过 **ContentResolver class** 方法进行管理。内容提供者可以将其数据存储在各种位置,例如 **数据库**、**文件** 或通过 **网络**。
|
||||
|
||||
在 _Manifest.xml_ 文件中,内容提供者的声明是必需的。例如:
|
||||
```xml
|
||||
@ -62,12 +62,12 @@ content://com.mwr.example.sieve.DBContentProvider/Passwords/
|
||||
|
||||
查询将类似于: `content://name.of.package.class/declared_name`
|
||||
|
||||
## **数据库支持的 Content Providers**
|
||||
## **数据库支持的内容提供者**
|
||||
|
||||
大多数 Content Providers 可能用作 **数据库** 的 **接口**。因此,如果您可以访问它,您可能能够 **提取、更新、插入和删除** 信息。\
|
||||
大多数内容提供者可能作为 **数据库** 的 **接口** 使用。因此,如果您可以访问它,您将能够 **提取、更新、插入和删除** 信息。\
|
||||
检查您是否可以 **访问敏感信息** 或尝试更改它以 **绕过授权** 机制。
|
||||
|
||||
检查 Content Provider 代码时 **还要查看** 名称类似于:_query, insert, update 和 delete_ 的 **函数**:
|
||||
检查 Content Provider 代码时,**还要查看** 名称类似于:_query、insert、update 和 delete_ 的 **函数**:
|
||||
|
||||
.png>)
|
||||
|
||||
@ -91,7 +91,7 @@ email: incognitoguy50@gmail.com
|
||||
|
||||
.png>)
|
||||
|
||||
.png>)
|
||||
.png>)
|
||||
|
||||
_请注意,在插入和更新中,您可以使用 --string 来表示字符串,--double 来表示双精度,--float,--integer,--long,--short,--boolean_
|
||||
|
||||
@ -107,7 +107,7 @@ _请注意,在插入和更新中,您可以使用 --string 来表示字符串
|
||||
|
||||
### **SQL Injection**
|
||||
|
||||
通过操纵传递给内容提供者的**投影**和**选择字段**,测试 SQL 注入**(SQLite)**是简单的。\
|
||||
通过操纵传递给内容提供者的**投影**和**选择字段**,测试 SQL 注入 **(SQLite)** 是很简单的。\
|
||||
查询内容提供者时,有两个有趣的参数可以搜索信息:_--selection_ 和 _--projection_:
|
||||
|
||||
.png>)
|
||||
@ -160,7 +160,7 @@ dz> run app.provider.read content://com.mwr.example.sieve.FileBackupProvider/etc
|
||||
```
|
||||
### **路径遍历**
|
||||
|
||||
如果您可以访问文件,您可以尝试利用路径遍历(在这种情况下这不是必要的,但您可以尝试使用“_../_”和类似的技巧)。
|
||||
如果您可以访问文件,您可以尝试利用路径遍历(在这种情况下,这不是必需的,但您可以尝试使用“_../_”和类似的技巧)。
|
||||
```
|
||||
dz> run app.provider.read content://com.mwr.example.sieve.FileBackupProvider/etc/hosts
|
||||
127.0.0.1 localhost
|
||||
@ -173,10 +173,61 @@ Vulnerable Providers:
|
||||
content://com.mwr.example.sieve.FileBackupProvider/
|
||||
content://com.mwr.example.sieve.FileBackupProvider
|
||||
```
|
||||
## 参考
|
||||
## 2023-2025 更新与现代技巧
|
||||
|
||||
### Drozer 3.x (Python 3) 已发布
|
||||
|
||||
WithSecure 在 2022 年恢复了对 drozer 的维护,并将框架移植到 **Python 3**(最新 **3.1.0 – 2024 年 4 月**)。除了兼容性修复外,特别在处理内容提供者时有用的新模块包括:
|
||||
|
||||
* `scanner.provider.exported` – 仅列出 `android:exported="true"` 的提供者。
|
||||
* `app.provider.grant` – 自动调用 `grantUriPermission()`,以便您可以与在 Android 12+ 上期望 `FLAG_GRANT_READ_URI_PERMISSION` / `FLAG_GRANT_WRITE_URI_PERMISSION` 的提供者进行通信。
|
||||
* 更好地处理 **Scoped Storage**,以便 Android 11+ 上的基于文件的提供者仍然可以访问。
|
||||
|
||||
升级(主机和代理):
|
||||
```bash
|
||||
pipx install --force "git+https://github.com/WithSecureLabs/drozer@v3.1.0"
|
||||
adb install drozer-agent-3.1.0.apk
|
||||
```
|
||||
### 使用内置的 `cmd content` 助手 (ADB ≥ 8.0)
|
||||
|
||||
所有现代 Android 设备都配备了一个 CLI,可以查询/更新提供者 **而无需安装任何代理**:
|
||||
```bash
|
||||
adb shell cmd content query --uri content://com.test.provider/items/
|
||||
adb shell cmd content update --uri content://com.test.provider/items/1 \
|
||||
--bind price:d:1337
|
||||
adb shell cmd content call --uri content://com.test.provider \
|
||||
--method evilMethod --arg 'foo'
|
||||
```
|
||||
将其与 `run-as <pkg>` 或已获取root权限的shell结合使用,以测试仅限内部的提供者。
|
||||
|
||||
### 最近滥用内容提供者的真实世界CVE
|
||||
|
||||
| CVE | 年份 | 组件 | 漏洞类别 | 影响 |
|
||||
|-----|------|-----------|-----------|--------|
|
||||
| CVE-2024-43089 | 2024 | MediaProvider | `openFile()`中的路径遍历 | 从任何应用的私有存储中任意读取文件 |
|
||||
| CVE-2023-35670 | 2023 | MediaProvider | 路径遍历 | 信息泄露 |
|
||||
|
||||
在易受攻击的构建上重新创建CVE-2024-43089:
|
||||
```bash
|
||||
adb shell cmd content read \
|
||||
--uri content://media/external_primary/file/../../data/data/com.target/shared_prefs/foo.xml
|
||||
```
|
||||
### API 30+ 的加固检查清单
|
||||
|
||||
* 声明 `android:exported="false"`,除非提供者 **必须** 是公共的 – 从 API 31 开始,该属性是强制性的。
|
||||
* 强制 **权限** 和/或 `android:grantUriPermissions="true"`,而不是导出整个提供者。
|
||||
* 白名单允许的 `projection`、`selection` 和 `sortOrder` 参数(例如,使用 `SQLiteQueryBuilder.setProjectionMap` 构建查询)。
|
||||
* 在 `openFile()` 中规范请求的路径(`FileUtils`),并拒绝 `..` 序列以防止遍历。
|
||||
* 当暴露文件时,优先使用 **Storage Access Framework** 或 `FileProvider`。
|
||||
|
||||
这些在最近的 Android 版本中的更改意味着许多遗留的利用原语仍然有效,但需要更新的 drozer 模块或 `cmd content` 助手可以自动应用的额外标志/权限。
|
||||
|
||||
## 参考文献
|
||||
|
||||
- [https://www.tutorialspoint.com/android/android_content_providers.htm](https://www.tutorialspoint.com/android/android_content_providers.htm)
|
||||
- [https://manifestsecurity.com/android-application-security-part-15/](https://manifestsecurity.com/android-application-security-part-15/)
|
||||
- [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)
|
||||
- [https://github.com/WithSecureLabs/drozer/releases/tag/3.1.0](https://github.com/WithSecureLabs/drozer/releases/tag/3.1.0)
|
||||
- [https://source.android.com/security/bulletin/2024-07-01](https://source.android.com/security/bulletin/2024-07-01)
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
44
theme/ai.js
44
theme/ai.js
@ -4,9 +4,10 @@
|
||||
|
||||
|
||||
(() => {
|
||||
const KEY = 'htSummerDiscountDismissed';
|
||||
const KEY = 'htSummerDiscountsDismissed';
|
||||
const IMG = '/images/discount.jpeg';
|
||||
const TXT = 'HT Summer Discount, Last Days!';
|
||||
const TXT = 'Click here for HT Summer Discounts, Last Days!';
|
||||
const URL = 'https://training.hacktricks.xyz';
|
||||
|
||||
/* Stop if user already dismissed */
|
||||
if (localStorage.getItem(KEY) === 'true') return;
|
||||
@ -32,13 +33,37 @@
|
||||
display: flex; flex-direction: column; align-items: stretch;
|
||||
`);
|
||||
|
||||
/* --- Title bar (separate, over image) --- */
|
||||
/* --- Title bar (link + close) --- */
|
||||
const titleBar = $('div', `
|
||||
padding: 1rem; text-align: center;
|
||||
position: relative;
|
||||
padding: 1rem 2.5rem 1rem 1rem; /* room for the close button */
|
||||
text-align: center;
|
||||
background: #222; color: #fff;
|
||||
font-size: 1.3rem; font-weight: 700;
|
||||
`);
|
||||
titleBar.textContent = TXT;
|
||||
|
||||
const link = $('a', `
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
display: block;
|
||||
`);
|
||||
link.href = URL;
|
||||
link.target = '_blank';
|
||||
link.rel = 'noopener noreferrer';
|
||||
link.textContent = TXT;
|
||||
titleBar.appendChild(link);
|
||||
|
||||
/* Close "X" (no persistence) */
|
||||
const closeBtn = $('button', `
|
||||
position: absolute; top: .25rem; right: .5rem;
|
||||
background: transparent; border: none;
|
||||
color: #fff; font-size: 1.4rem; line-height: 1;
|
||||
cursor: pointer; padding: 0; margin: 0;
|
||||
`);
|
||||
closeBtn.setAttribute('aria-label', 'Close');
|
||||
closeBtn.textContent = '✕';
|
||||
closeBtn.onclick = () => overlay.remove();
|
||||
titleBar.appendChild(closeBtn);
|
||||
|
||||
/* --- Image --- */
|
||||
const img = $('img');
|
||||
@ -62,14 +87,15 @@
|
||||
modal.append(titleBar, img, label);
|
||||
overlay.appendChild(modal);
|
||||
|
||||
(document.readyState === 'loading'
|
||||
? () => document.addEventListener('DOMContentLoaded', () => document.body.appendChild(overlay), { once: true })
|
||||
: () => document.body.appendChild(overlay))();
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', () => document.body.appendChild(overlay), { once: true });
|
||||
} else {
|
||||
document.body.appendChild(overlay);
|
||||
}
|
||||
})();
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* HackTricks AI Chat Widget v1.16 – resizable sidebar
|
||||
* ---------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user