Android 应用 Pentesting
Tip
学习和实践 AWS 黑客技术:
HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE)
学习和实践 Azure 黑客技术:
HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。
Android 应用 基础
强烈建议先阅读此页面,以了解与 Android 安全相关的最重要部分以及 Android 应用中最危险的组件:
ADB (Android Debug Bridge)
这是连接 Android 设备(模拟或物理设备)所需的主要工具。
ADB 允许从计算机通过 USB 或 网络 控制设备。该工具支持双向文件的复制、应用的安装与卸载、执行 shell 命令、备份数据、读取日志等功能。
查看以下 ADB Commands 列表以了解如何使用 adb。
Smali
有时对应用代码进行修改以访问隐藏信息(例如被良好混淆的密码或 flags)是很有意义的。此时,可以反编译 APK,修改代码并重新编译。
In this tutorial you can learn how to decompile and APK, modify Smali code and recompile the APK with the new functionality。这在作为进行动态分析时若干测试的替代方法会非常有用。请始终记住这种可能性。
Other interesting tricks
- Spoofing your location in Play Store
- Play Integrity attestation spoofing (SafetyNet replacement)
- Android app-level virtualization / app cloning abuse & detection
- Shizuku Privileged API (ADB-based non-root privileged access)
- Exploiting Insecure In-App Update Mechanisms
- Abusing Accessibility Services (Android RAT)
- Android IME / InputMethodService Abuse (Malicious Keyboards)
- NFC/EMV Relay via HCE (Android Tap-to-Pay abuse)
- 下载 APKs: https://apps.evozi.com/apk-downloader/, https://apkpure.com/es/, https://www.apkmirror.com/, https://apkcombo.com/es-es/apk-downloader/, https://github.com/kiber-io/apkd
自动化的多来源 APK 获取 (justapk)
pip install justapk (Python 3.11+)。CLI 将 JSON 输出到 stdout,并将进度输出到 stderr(便于管道处理)。它会按确定性的回退链尝试以下来源:APK20 → F-Droid → APKPure (mobile API) → APKMirror (HTML scrape) → Uptodown (mobile API) → APKCombo (HTML scrape)。对受 Cloudflare 保护的来源使用 curl_cffi 结合 TLS 指纹模拟以模仿真实客户端,减少被 bot 检测拦截。
justapk download <package> # auto fallback
justapk download <package> -s apkpure # pin a source / version / output dir
justapk search telegram
justapk info org.telegram.messenger
justapk convert app.xapk -o output/ # merges splits, re-signs with debug key
convert 将 XAPK/split APKs 合并并使用 debug key 签名,因此生成的 APK 的签名/来源会与原始不同(仅用于测试/分析,不用于生产安装)。
- 从设备提取 APK:
adb shell pm list packages
com.android.insecurebankv2
adb shell pm path com.android.insecurebankv2
package:/data/app/com.android.insecurebankv2-Jnf8pNgwy3QA_U5f-n_4jQ==/base.apk
adb pull /data/app/com.android.insecurebankv2-Jnf8pNgwy3QA_U5f-n_4jQ==/base.apk
- 使用 APKEditor 合并所有 splits 和 base apks:
mkdir splits
adb shell pm path com.android.insecurebankv2 | cut -d ':' -f 2 | xargs -n1 -i adb pull {} splits
java -jar ../APKEditor.jar m -i splits/ -o merged.apk
# after merging, you will need to align and sign the apk, personally, I like to use the uberapksigner
java -jar uber-apk-signer.jar -a merged.apk --allowResign -o merged_signed
Android malware 实战技巧 (loaders, fileless DEX, persistence)
Native staging + fileless DEX loaders
一些 Android droppers 会嵌入一个 native 库 (lib*.so),该库会 解密并写入第二个 ELF(例如 l.so)到临时路径,通过 JNI 加载它,然后使用 dalvik.system.InMemoryDexClassLoader 将真实逻辑以 DEX 仅在内存中加载。这样可以降低 payload 的静态可见性并避免将 classes*.dex 写入磁盘。
Practical triage points:
- 查找那些非常早就调用
dlopen或System.loadLibrary的 native libs,然后通过混淆的栈字符串(例如在栈上 XOR 解码)来解析 Java 方法。 - 监视日志/字符串或 hooks 中的
InMemoryDexClassLoader,这通常表明 fileless DEX 的执行。
快速 Frida hook 用于转储内存中的 DEX 缓冲区:
Java.perform(() => {
const IM = Java.use('dalvik.system.InMemoryDexClassLoader');
IM.$init.overload('java.nio.ByteBuffer','java.lang.ClassLoader').implementation = function(buf, parent){
const arr = Java.array('byte', buf.array());
const fos = Java.use('java.io.FileOutputStream').$new("/sdcard/memdex.dex");
fos.write(arr); fos.close();
return this.$init(buf, parent);
};
});
Anti-analysis kill-switch
Packed loaders 经常在模拟器或分析检查失败时通过调用来自我终止(例如,CPU_ABI 验证):
android.os.Process.killProcess(android.os.Process.myPid());
通过 foreground service + MediaPlayer 循环实现持久化
一种轻量级的持久化模式是通过保持一个 foreground service 存活并显示 pinned notification,并使用 MediaPlayer 持续播放几乎不可听到的音频循环。这样可以使进程保持“活动”状态,减少操作系统因不活动而终止进程。查找使用 ForegroundService + MediaPlayer 循环播放小型资源(通常几秒钟)的情况。
Accessibility overlay + ACTION_SET_TEXT 劫持
用户授予 Accessibility 后,banking trojans 可以监控 foreground app,渲染一个逼真的 overlay(通常是以 Base64 存储的 WebView HTML),并使用 AccessibilityNodeInfo.ACTION_SET_TEXT 替换交易字段。这样在受害者看到合理的 UI 时,可以静默地替换收款地址。
最小文本替换示例:
Bundle args = new Bundle();
args.putCharSequence(AccessibilityNodeInfo.ACTION_ARGUMENT_SET_TEXT_CHARSEQUENCE,
"ATTACKER_USDT_ADDRESS");
node.performAction(AccessibilityNodeInfo.ACTION_SET_TEXT, args);
将合法推送基础设施作为 C2 门控
Instead of custom sockets, some malware uses Firebase Cloud Messaging (FCM) as the C2 channel. FCM messages can trigger telemetry checks (charging state, battery %, temperature, user inactivity) and gate actions like mining or fraud for stealth.
使用基于文件名派生密钥的加密 native payload 暂存
Native payloads can be delivered as encrypted ELF blobs and decrypted with CipherInputStream(), using a key derived from SHA‑1 of the downloaded filename. Each filename/version yields a distinct key, hindering static IOC reuse.
Jezail rooted Android pentesting toolkit (REST API + web UI)
- Runs on a rooted device (Magisk/rootAVD) and starts an HTTP server on tcp/8080 with a Flutter web UI and REST API.
- Install the release APK with perms:
adb install -g -r jezail.apk, then launch the app (server auto-starts). - Endpoints:
http://<device-ip>:8080/(UI),http://<device-ip>:8080/api/json(API listing),http://<device-ip>:8080/api/swagger(Swagger). - Emulator port-forward to reach UI/API from the host:
adb forward tcp:8080 tcp:8080then browsehttp://localhost:8080.
Android Enterprise & Work Profile Attacks
Android Enterprise Work Profile Bypass
Case Studies & Vulnerabilities
Air Keyboard Remote Input Injection
Android Rooting Frameworks Manager Auth Bypass Syscall Hook
Abusing Android Media Pipelines Image Parsers
Firmware Level Zygote Backdoor Libandroid Runtime
静态分析
First of all, for analysing an APK you should take a look to the to the Java code using a decompiler.
Please, read here to find information about different available decompilers.
查找有价值的信息
Just taking a look to the strings of the APK you can search for passwords, URLs (https://github.com/ndelphit/apkurlgrep), api keys, encryption, bluetooth uuids, tokens and anything interesting… look even for code execution backdoors or authentication backdoors (hardcoded admin credentials to the app).
Firebase
Pay special attention to firebase URLs and check if it is bad configured. More information about whats is FIrebase and how to exploit it here.
对应用的基本理解 - Manifest.xml, strings.xml
The examination of an application’s Manifest.xml and strings.xml files can reveal potential security vulnerabilities. These files can be accessed using decompilers or by renaming the APK file extension to .zip and then unzipping it.
Vulnerabilities identified from the Manifest.xml include:
- Debuggable Applications: Applications set as debuggable (
debuggable="true") in the Manifest.xml file pose a risk as they allow connections that can lead to exploitation. For further understanding on how to exploit debuggable applications, refer to a tutorial on finding and exploiting debuggable applications on a device. - Backup Settings: The
android:allowBackup="false"attribute should be explicitly set for applications dealing with sensitive information to prevent unauthorized data backups via adb, especially when usb debugging is enabled. - Network Security: Custom network security configurations (
android:networkSecurityConfig="@xml/network_security_config") in res/xml/ can specify security details like certificate pins and HTTP traffic settings. An example is allowing HTTP traffic for specific domains. - Exported Activities and Services: Identifying exported activities and services in the manifest can highlight components that might be misused. Further analysis during dynamic testing can reveal how to exploit these components.
- Content Providers and FileProviders: Exposed content providers could allow unauthorized access or modification of data. The configuration of FileProviders should also be scrutinized.
- Broadcast Receivers and URL Schemes: These components could be leveraged for exploitation, with particular attention to how URL schemes are managed for input vulnerabilities.
- SDK Versions: The
minSdkVersion,targetSDKVersion, andmaxSdkVersionattributes indicate the supported Android versions, highlighting the importance of not supporting outdated, vulnerable Android versions for security reasons.
From the strings.xml file, sensitive information such as API keys, custom schemas, and other developer notes can be discovered, underscoring the need for careful review of these resources.
Tapjacking
Tapjacking is an attack where a malicious application is launched and positions itself on top of a victim application. Once it visibly obscures the victim app, its user interface is designed in such a way as to trick the user to interact with it, while it is passing the interaction along to the victim app.
In effect, it is blinding the user from knowing they are actually performing actions on the victim app.
Find more information in:
Task Hijacking
An activity with the launchMode set to singleTask without any taskAffinity defined is vulnerable to task Hijacking. This means, that an application can be installed and if launched before the real application it could hijack the task of the real application (so the user will be interacting with the malicious application thinking he is using the real one).
More info in:
不安全的数据存储
Internal Storage
In Android, files stored in internal storage are designed to be accessible exclusively by the app that created them. This security measure is enforced by the Android operating system and is generally adequate for the security needs of most applications. However, developers sometimes utilize modes such as MODE_WORLD_READABLE and MODE_WORLD_WRITABLE to allow files to be shared between different applications. Yet, these modes do not restrict access to these files by other applications, including potentially malicious ones.
- Static Analysis:
- Ensure that the use of
MODE_WORLD_READABLEandMODE_WORLD_WRITABLEis carefully scrutinized. These modes can potentially expose files to unintended or unauthorized access.
- Dynamic Analysis:
- Verify the permissions set on files created by the app. Specifically, check if any files are set to be readable or writable worldwide. This can pose a significant security risk, as it would allow any application installed on the device, regardless of its origin or intent, to read or modify these files.
External Storage
When dealing with files on external storage, such as SD Cards, certain precautions should be taken:
- Accessibility:
- Files on external storage are globally readable and writable. This means any application or user can access these files.
- Security Concerns:
- Given the ease of access, it’s advised not to store sensitive information on external storage.
- External storage can be removed or accessed by any application, making it less secure.
- Handling Data from External Storage:
- Always perform input validation on data retrieved from external storage. This is crucial because the data is from an untrusted source.
- Storing executables or class files on external storage for dynamic loading is strongly discouraged.
- If your application must retrieve executable files from external storage, ensure these files are signed and cryptographically verified before they are dynamically loaded. This step is vital for maintaining the security integrity of your application.
External storage can be accessed in /storage/emulated/0 , /sdcard , /mnt/sdcard
Tip
Starting with Android 4.4 (API 17), the SD card has a directory structure which limits access from an app to the directory which is specifically for that app. This prevents malicious application from gaining read or write access to another app’s files.
Sensitive data stored in clear-text
- Shared preferences: Android allow to each application to easily save xml files in the path
/data/data/<packagename>/shared_prefs/and sometimes it’s possible to find sensitive information in clear-text in that folder. - Databases: Android allow to each application to easily save sqlite databases in the path
/data/data/<packagename>/databases/and sometimes it’s possible to find sensitive information in clear-text in that folder.
Broken TLS
Accept All Certificates
For some reason sometimes developers accept all the certificates even if for example the hostname does not match with lines of code like the following one:
SSLSocketFactory sf = new cc(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
A good way to test this is to try to capture the traffic using some proxy like Burp without authorising Burp CA inside the device. Also, you can generate with Burp a certificate for a different hostname and use it.
Broken Cryptography
Poor Key Management Processes
一些开发者将敏感数据保存在本地存储并使用硬编码/可预测的密钥进行加密。这样做是不安全的,因为反向工程可能允许攻击者提取机密信息。
Use of Insecure and/or Deprecated Algorithms
开发者不应使用已弃用的算法来执行授权检查、存储或发送数据。其中一些算法包括:RC4、MD4、MD5、SHA1……例如,如果使用hashes来存储密码,应使用对暴力破解有抵抗力的哈希算法并加入 salt。
Other checks
- 建议对 APK 进行混淆,以增加攻击者逆向工程的难度。
- 如果应用是敏感类(例如银行应用),应自行检查手机是否已 root并据此采取相应措施。
- 如果应用是敏感类(例如银行应用),应检查是否在模拟器中运行。
- 如果应用是敏感类(例如银行应用),应在执行前校验自身完整性,以检测是否被篡改。
- 使用 APKiD 检查用于构建 APK 的编译器/packer/obfuscator
React Native Application
阅读下面的页面,了解如何轻松访问 React 应用的 javascript 代码:
Xamarin Applications
阅读下面的页面,了解如何轻松访问 xamarin 应用的 C# 代码:
Superpacked Applications
根据这篇 blog post,superpacked 是 Meta 的一种算法,它将应用的内容压缩到单个文件中。博客讨论了创建一个可以解压此类应用的 app 的可能性……以及一种更快的方法,涉及到执行应用并从文件系统收集已解压的文件。
Automated Static Code Analysis
工具 mariana-trench 能够通过扫描应用的代码来发现漏洞。该工具包含一系列的已知 sources(指示工具输入由用户控制的位置)、sinks(指示工具危险的位置,恶意用户输入可能造成损害)和规则。这些规则说明了指示漏洞的sources-sinks 组合。
基于这些信息,mariana-trench 会审查代码并查找可能的漏洞。
Secrets leaked
应用内部可能包含机密(API keys、密码、隐藏的 urls、子域名……)你可能能够发现这些信息。可以使用诸如 https://github.com/dwisiswant0/apkleaks 的工具进行检测。
Bypass Biometric Authentication
Bypass Biometric Authentication (Android)
Other interesting functions
- Code execution:
Runtime.exec(), ProcessBuilder(), native code:system() - Send SMSs:
sendTextMessage, sendMultipartTestMessage - Native functions declared as
native:public native, System.loadLibrary, System.load - Read this to learn how to reverse native functions
- In-memory native code execution via JNI (downloaded shellcode → mmap/mprotect → call):
In Memory Jni Shellcode Execution
Other tricks
Dynamic Analysis
First of all, you need an environment where you can install the application and all the environment (Burp CA cert, Drozer and Frida mainly). Therefore, a rooted device (emulated or not) is extremely recommended.
Online Dynamic analysis
你可以在以下网站创建一个免费账号: https://appetize.io/。该平台允许你上传并执行 APK,因此有助于观察 apk 的运行行为。
你甚至可以在网页中查看应用日志并通过 adb 连接。
.png)
借助 ADB 连接,你可以在模拟器内使用 Drozer 和 Frida。
Local Dynamic Analysis
Using an emulator
- Android Studio(你可以创建 x86 和 arm 设备,根据 this 最新 x86 版本 支持 ARM 库,无需使用慢速的 arm 模拟器)。
- 在此页面学习如何进行设置:
- Genymotion (免费版:Personal Edition,需要创建账户。建议下载带有 VirtualBox 的版本以避免潜在错误。)
- Nox(免费,但不支持 Frida 或 Drozer)。
Tip
在任何平台创建新模拟器时请记住,屏幕越大,模拟器运行越慢。因此如可能请选择小屏幕。
要在 Genymotion 中安装 google services(如 AppStore),需要点击下图中用红色标出的按钮:
.png)
另外,请注意在 Genymotion 的 Android VM 配置 中可以选择 Bridge Network 模式(如果你要从另一个带有工具的 VM 连接到 Android VM,这将很有用)。
Use a physical device
你需要激活调试选项,如果可以的话最好能将设备root:
- Settings.
- (FromAndroid 8.0) Select System.
- Select About phone.
- Press Build number 7 times.
- Go back and you will find the Developer options.
一旦安装了应用,首先应该运行并观察它做什么、如何工作,并熟悉其行为。
建议使用 MobSF dynamic analysis + pidcat 执行初步动态分析,这样在 MobSF 捕获大量可供后续审查的有价值数据的同时,我们也能学习应用的运行机制。
Magisk/Zygisk quick notes (recommended on Pixel devices)
- 使用 Magisk 应用对 boot.img 打补丁并通过 fastboot 刷入以获得无系统 root
- 启用 Zygisk + DenyList 以隐藏 root;当需要更强的隐藏时考虑使用 LSPosed/Shamiko
- 保留原始 boot.img 以便从 OTA 更新中恢复;每次 OTA 后重新打补丁
- 对于屏幕镜像,在主机上使用 scrcpy
Unintended Data Leakage
Logging
开发者应谨慎避免公开暴露调试信息,因为这可能导致敏感数据泄露。推荐使用工具 pidcat 和 adb logcat 来监控应用日志,以识别并保护敏感信息。Pidcat 因其易用性和可读性而更受青睐。
Warning
请注意,从 Android 4.0 之后的新版 开始,应用只能访问其自身的日志。因此应用无法访问其他应用的日志。
无论如何,仍建议不要记录敏感信息。
Copy/Paste Buffer Caching
Android 的剪贴板框架支持复制粘贴功能,但存在风险:其他应用可以访问剪贴板,可能导致敏感数据泄露。对于信用卡等敏感字段,应禁用复制/粘贴功能以防止数据泄露。
Crash Logs
如果应用崩溃并保存日志,这些日志可能帮助攻击者,尤其是在应用无法反向工程时。为降低风险,尽量避免在崩溃时记录日志;若必须通过网络传输日志,请确保通过 SSL 通道发送以保证安全。
作为 pentester,尝试查看这些日志。
Analytics Data Sent To 3rd Parties
应用通常会集成类似 Google Adsense 的服务,开发者实现不当可能会leak sensitive data。为识别潜在的数据泄露,建议拦截应用流量并检查是否有敏感信息发送到第三方服务。
SQLite DBs
大多数应用会使用内部 SQLite 数据库保存信息。在测试时查看创建的数据库、表名和列名以及所有保存的数据,因为你可能会发现敏感信息(这将构成漏洞)。
数据库应位于 /data/data/the.package.name/databases,例如 /data/data/com.mwr.example.sieve/databases
如果数据库保存了机密信息且已加密,但你能在应用中找到加密密码,这仍然构成漏洞。
使用 .tables 列举表,使用 .schema <table_name> 列举表的列信息。
Drozer (Exploit Activities, Content Providers and Services)
From Drozer Docs: Drozer 允许你模拟 Android 应用的角色并与其他应用交互。它可以执行已安装应用可以做的任何事情,例如利用 Android 的进程间通信(IPC)机制并与底层操作系统交互。
Drozer 是一个有用的工具,可用于利用 exported activities、exported services 和 Content Providers,你将在以下部分学习到这些内容。
Exploiting exported Activities
Read this if you want to refresh what is an Android Activity.
还要记住,activity 的代码从 onCreate 方法开始执行。
Authorisation bypass
当 Activity 被 exported 时,你可以从外部应用调用它的界面。因此,如果包含敏感信息的 activity 被exported,你可能能够绕过****认证机制来访问它。
Learn how to exploit exported activities with Drozer.
你也可以通过 adb 启动一个 exported activity:
- PackageName is com.example.demo
- Exported ActivityName is com.example.test.MainActivity
adb shell am start -n com.example.demo/com.example.test.MainActivity
NOTE: MobSF will detect as malicious the use of singleTask/singleInstance as android:launchMode in an activity, but due to this, apparently this is only dangerous on old versions (API versions < 21).
Tip
注意,authorisation bypass 并不总是一个 vulnerability,这取决于 bypass 的工作方式以及暴露了哪些信息。
敏感信息泄露
Activities can also return results。如果你设法找到一个 exported 且未受保护的 activity 调用 setResult 方法并返回敏感信息,就会发生敏感信息泄露。
Tapjacking
如果未防护 Tapjacking,你可能滥用已导出的 activity 使 用户执行意外操作。更多关于 what is Tapjacking follow the link 的信息请参考链接。
Exploiting Content Providers - 访问和操作敏感信息
Read this if you want to refresh what is a Content Provider.
Content providers 基本上用于 share data。如果一个应用有可用的 content providers,你可能能够从中extract sensitive 数据。也应测试可能存在的 SQL injections 和 Path Traversals,因为它们可能存在漏洞。
Learn how to exploit Content Providers with Drozer.
Exploiting Services
Read this if you want to refresh what is a Service.
请记住,Service 的行为通常从方法 onStartCommand 开始。
Service 基本上是可以 接收数据、处理 它并(或不)返回 响应的东西。因此,如果一个应用在导出某些 services,你应该检查其code以了解其行为,并动态测试以提取机密信息、绕过认证措施等。
Learn how to exploit Services with Drozer.
Exploiting Broadcast Receivers
Read this if you want to refresh what is a Broadcast Receiver.
请记住,Broadcast Receiver 的行为通常从方法 onReceive 开始。
Broadcast receiver 会等待某种类型的消息。取决于接收器如何处理该消息,它可能存在漏洞。
Learn how to exploit Broadcast Receivers with Drozer.
Exploiting Schemes / Deep links
你可以手动查找 deep links,使用像 MobSF 这样的工具或像 this one 这样的脚本。
你可以使用 adb 或 browser open 已声明的 scheme:
adb shell am start -a android.intent.action.VIEW -d "scheme://hostname/path?param=value" [your.package.name]
请注意你可以省略包名,移动设备会自动调用应该打开该链接的应用。
<!-- Browser regular link -->
<a href="scheme://hostname/path?param=value">Click me</a>
<!-- fallback in your url you could try the intent url -->
<a href="intent://hostname#Intent;scheme=scheme;package=your.package.name;S.browser_fallback_url=http%3A%2F%2Fwww.example.com;end">with alternative</a>
执行的代码
为了找到 在 App 中将被执行的代码,前往由 deeplink 调用的 activity 并搜索函数 onNewIntent。
 (1) (1) (1).png)
敏感信息
每次发现 deep link 时,请检查 i**t’s 不会通过 URL 参数接收敏感数据(例如密码),因为任何其他应用都可能 冒充该 deep link 并窃取这些数据!
路径中的参数
你 还必须检查是否有任何 deep link 在 URL 的路径中使用参数,例如: https://api.example.com/v1/users/{username},在这种情况下你可以通过访问类似 example://app/users?username=../../unwanted-endpoint%3fparam=value 来强制进行路径遍历。
注意如果你在应用内部找到了正确的 endpoints,你可能能够导致 Open Redirect(如果路径的一部分被用作域名)、account takeover(如果你能在没有 CSRF token 的情况下修改用户详情并且易受影响的 endpoint 使用了正确的方法)以及任何其他漏洞。关于此的更多信息请参见 这里。
更多示例:
一个关于 links(/.well-known/assetlinks.json)的有趣的 bug bounty 报告。
Transport Layer Inspection and Verification Failures
- Certificates are not always inspected properly by Android applications. 很多此类应用会忽略警告并接受 self-signed certificates,或者在某些情况下回退到使用 HTTP 连接。
- Negotiations during the SSL/TLS handshake are sometimes weak, 使用不安全的 cipher suites。这种弱点会使连接容易受到 MITM 攻击,允许攻击者解密数据。
- Leakage of private information 是一个风险:应用在某些事务中使用 secure channels 进行身份验证,但在其他事务上又使用 non-secure channels 通信。这种做法无法保护敏感数据(例如 session cookies 或用户详情)免于被恶意方拦截。
Certificate Verification
我们将着重于 证书验证(certificate verification)。必须验证服务器证书的完整性以增强安全性。这一点至关重要,因为不安全的 TLS 配置和通过未加密通道传输敏感数据会带来重大风险。有关验证服务器证书和修补漏洞的详细步骤,this resource 提供了全面的指南。
SSL Pinning
SSL Pinning 是一种安全措施,应用会将服务器证书与存储在应用内的已知副本进行校验。该方法对于防止 MITM 攻击至关重要。对于处理敏感信息的应用,强烈建议实现 SSL Pinning。
Traffic Inspection
要检查 HTTP 流量,需要 安装代理工具的证书(例如 Burp)。如果不安装该证书,加密流量可能无法通过代理可见。关于安装自定义 CA certificate 的指南,请参考 click here。
面向 API Level 24 及以上 的应用需要修改 Network Security Config 才能接受代理的 CA certificate。这一步对于检查加密流量至关重要。有关修改 Network Security Config 的说明,请参阅 refer to this tutorial。
如果应用使用 Flutter,你需要按照 this page 中的说明进行操作。这是因为仅将证书添加到系统存储通常不起作用,Flutter 有其自己的有效 CA 列表。
Static detection of SSL/TLS pinning
在尝试运行时绕过之前,先快速映射 APK 中 pinning 强制生效的位置。静态发现有助于你规划 hook/patch,并将精力集中在正确的代码路径上。
Tool: SSLPinDetect
- 开源的静态分析工具,会将 APK 反编译为 Smali(通过 apktool),并扫描为 SSL/TLS pinning 实现策划的正则模式。
- 为每个匹配项报告精确的文件路径、行号和代码片段。
- 覆盖常见框架和自定义代码路径:OkHttp CertificatePinner、自定义的 javax.net.ssl.X509TrustManager.checkServerTrusted、使用自定义 TrustManagers/KeyManagers 的 SSLContext.init,以及 Network Security Config XML pins。
Install
- Prereqs: Python >= 3.8, Java on PATH, apktool
git clone https://github.com/aancw/SSLPinDetect
cd SSLPinDetect
pip install -r requirements.txt
用法
# Basic
python sslpindetect.py -f app.apk -a apktool.jar
# Verbose (timings + per-match path:line + snippet)
python sslpindetect.py -a apktool_2.11.0.jar -f sample/app-release.apk -v
示例模式规则 (JSON) 使用或扩展 signatures 来检测专有/自定义的 pinning 样式。你可以加载自己的 JSON 并在大规模上进行 scan。
{
"OkHttp Certificate Pinning": [
"Lcom/squareup/okhttp/CertificatePinner;",
"Lokhttp3/CertificatePinner;",
"setCertificatePinner"
],
"TrustManager Override": [
"Ljavax/net/ssl/X509TrustManager;",
"checkServerTrusted"
]
}
Notes and tips
- 对大型应用使用多线程和内存映射 I/O 进行快速扫描;预编译的 regex 可减少开销/误报。
- Pattern collection: https://github.com/aancw/smali-sslpin-patterns
- 接下来用于优先筛查的典型检测目标:
- OkHttp: CertificatePinner 的使用、setCertificatePinner、okhttp3/okhttp 包引用
- 自定义 TrustManagers:javax.net.ssl.X509TrustManager、checkServerTrusted 的重写
- 自定义 SSL contexts:SSLContext.getInstance + SSLContext.init 与自定义管理器
- 声明式 pins 位于 res/xml network security config 和 manifest 的引用中
- 使用匹配到的位置来规划 Frida hooks、静态补丁或配置审查,然后再进行动态测试。
Bypassing SSL Pinning
当实现了 SSL Pinning 时,必须绕过它以便检查 HTTPS 流量。可用的方法有多种:
- 自动使用 apk-mitm 修改 apk 以 绕过 SSLPinning。此方法的最大优点是无需 root 即可绕过 SSL Pinning,但你需要删除应用并重新安装新版本,而且并非在所有情况下都有效。
- 你可以使用 Frida(下面有讨论)来绕过该保护。这里有一份使用 Burp+Frida+Genymotion 的指南: https://spenkk.github.io/bugbounty/Configuring-Frida-with-Burp-and-GenyMotion-to-bypass-SSL-Pinning/
- 你也可以尝试使用 objection 自动绕过 SSL Pinning:
objection --gadget com.package.app explore --startup-command "android sslpinning disable" - 你还可以尝试使用 MobSF dynamic analysis(下文解释)来自动绕过 SSL Pinning
- 如果你仍然认为有部分流量未被捕获,可以尝试使用 iptables 将流量转发到 burp。阅读这篇博客: https://infosecwriteups.com/bypass-ssl-pinning-with-ip-forwarding-iptables-568171b52b62
Looking for Common Web Vulnerabilities
同样重要的是在应用内搜索常见的 Web 漏洞。关于识别和缓解这些漏洞的详细信息超出本摘要范围,但在其他资料中有详尽说明。
Frida
Frida 是一个面向开发者、逆向工程师和安全研究人员的动态插装工具包。
你可以访问正在运行的应用并在运行时 hook 方法以改变行为、修改值、提取值、执行不同代码等…
如果你想 pentest Android 应用,你需要会使用 Frida。
- 学习如何使用 Frida: Frida tutorial
- 一些与 Frida 配合使用的 “GUI”: https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security
- Ojection 很适合自动化 Frida 的使用: https://github.com/sensepost/objection , https://github.com/dpnishant/appmon
- 你可以在这里找到一些优秀的 Frida 脚本: https://codeshare.frida.re/
- 尝试通过如下方式加载 Frida 来绕过 anti-debugging / anti-frida 机制,详见 https://erfur.github.io/blog/dev/code-injection-without-ptrace(工具 linjector)
Anti-instrumentation & SSL pinning bypass workflow
Android Anti Instrumentation And Ssl Pinning Bypass
Dump Memory - Fridump
检查应用是否在内存中存储了不应存储的敏感信息,例如密码或助记词。
使用 Fridump3 可以导出应用的内存,命令如下:
# With PID
python3 fridump3.py -u <PID>
# With name
frida-ps -Uai
python3 fridump3.py -u "<Name>"
这会将内存转储到 ./dump 文件夹,您可以在其中使用类似下面的 grep 命令:
strings * | grep -E "^[a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+ [a-z]+$"
Keystore 中的敏感数据
在 Android 中,Keystore 是存储敏感数据的最佳位置,但拥有足够权限时仍然 可能被访问。由于应用程序倾向于在这里存储 明文敏感数据,pentests 应以 root 用户或具有设备物理访问权限的人的身份检查这些数据,因为他们可能能够窃取这些数据。
即使应用将数据存储在 Keystore 中,数据也应被加密。
要访问 keystore 内的数据,可以使用这个 Frida 脚本: https://github.com/WithSecureLabs/android-keystore-audit/blob/master/frida-scripts/tracer-cipher.js
frida -U -f com.example.app -l frida-scripts/tracer-cipher.js
Fingerprint/Biometrics Bypass
使用下面的 Frida 脚本,可能可以 bypass fingerprint authentication,该认证是 Android 应用用来 保护某些敏感区域:
frida --codeshare krapgras/android-biometric-bypass-update-android-11 -U -f <app.package>
后台图片
当你将应用置于后台时,Android 会存储该应用的 快照,这样当它恢复到前台时,会先加载这张图片,从而看起来应用启动得更快。
然而,如果该快照包含 敏感信息,有权限访问该快照的人可能会 窃取这些信息(注意,你需要 root 才能访问它)。
这些快照通常存储在: /data/system_ce/0/snapshots
Android 提供了一种通过设置 FLAG_SECURE 布局参数来防止截屏的方法。使用此标志后,窗口内容被视为安全,阻止其出现在截图中或在不安全的显示设备上被查看。
getWindow().setFlags(LayoutParams.FLAG_SECURE, LayoutParams.FLAG_SECURE);
Android 应用分析器
这个工具可以在动态分析时帮助你管理不同的工具: https://github.com/NotSoSecure/android_application_analyzer
Intent Injection
开发者常常创建代理组件(例如 activities、services 和 broadcast receivers)来处理这些 Intents,并将它们传递给诸如 startActivity(...) 或 sendBroadcast(...) 之类的方法,这可能是有风险的。
危险在于允许攻击者通过误导这些 Intents 来触发未导出的应用组件或访问敏感的 content providers。一个显著的例子是 WebView 组件通过 Intent.parseUri(...) 将 URL 转换为 Intent 对象并执行它们,可能导致恶意的 Intent injections。
重要要点
- Intent Injection 类似于 web 的 Open Redirect 问题。
- 利用方式包括将
Intent对象作为 extras 传递,这些对象可以被重定向以执行不安全的操作。 - 它可能会将未导出的组件和 content providers 暴露给攻击者。
WebView将 URL 转换为Intent的行为可能会导致非预期的操作。
Android Client Side Injections and others
你可能从 Web 安全中已经熟悉这类漏洞。在 Android 应用中需要特别注意以下这些漏洞:
- SQL Injection: 在处理动态查询或 Content-Providers 时,确保使用参数化查询。
- JavaScript Injection (XSS): 确认对任何 WebViews 禁用 JavaScript 和 Plugin 支持(默认是禁用的)。 More info here.
- Local File Inclusion: 应禁用 WebViews 访问文件系统的权限(默认启用) -
(webview.getSettings().setAllowFileAccess(false);). More info here. - Eternal cookies: 在很多情况下,当 android 应用结束会话时,cookie 未被撤销,或甚至被保存到磁盘。
- Secure Flag in cookies
自动化分析
MobSF
Static analysis
.png)
Vulnerability assessment of the application 使用一个友好的 web 前端界面。你也可以执行 dynamic analysis(但需要准备环境)。
docker pull opensecurity/mobile-security-framework-mobsf
docker run -it -p 8000:8000 opensecurity/mobile-security-framework-mobsf:latest
Notice that MobSF can analyse Android(apk), IOS(ipa) and Windows(apx) applications (Windows applications must be analyzed from a MobSF installed in a Windows host).
Also, if you create a ZIP file with the source code if an Android or an IOS app (go to the root folder of the application, select everything and create a ZIPfile), it will be able to analyse it also.
MobSF also allows you to diff/Compare analysis and to integrate VirusTotal (you will need to set your API key in MobSF/settings.py and enable it: VT_ENABLED = TRUE VT_API_KEY = <Your API key> VT_UPLOAD = TRUE). You can also set VT_UPLOAD to False, then the hash will be upload instead of the file.
Assisted Dynamic analysis with MobSF
MobSF can also be very helpful for dynamic analysis in Android, but in that case you will need to install MobSF and genymotion in your host (a VM or Docker won’t work). Note: You need to start first a VM in genymotion and then MobSF.
The MobSF dynamic analyser can:
- Dump application data (URLs, logs, clipboard, screenshots made by you, screenshots made by “Exported Activity Tester”, emails, SQLite databases, XML files, and other created files). All of this is done automatically except for the screenshots, you need to press when you want a screenshot or you need to press “Exported Activity Tester” to obtain screenshots of all the exported activities.
- Capture HTTPS traffic
- Use Frida to obtain runtime information
From android versions > 5, it will automatically start Frida and will set global proxy settings to capture traffic. It will only capture traffic from the tested application.
Frida
By default, it will also use some Frida Scripts to bypass SSL pinning, root detection and debugger detection and to monitor interesting APIs.
MobSF can also invoke exported activities, grab screenshots of them and save them for the report.
To start the dynamic testing press the green bottom: “Start Instrumentation”. Press the “Frida Live Logs” to see the logs generated by the Frida scripts and “Live API Monitor” to see all the invocation to hooked methods, arguments passed and returned values (this will appear after pressing “Start Instrumentation”).
MobSF also allows you to load your own Frida scripts (to send the results of your Friday scripts to MobSF use the function send()). It also has several pre-written scripts you can load (you can add more in MobSF/DynamicAnalyzer/tools/frida_scripts/others/), just select them, press “Load” and press “Start Instrumentation” (you will be able to see the logs of that scripts inside “Frida Live Logs”).
.png)
Moreover, you have some Auxiliary Frida functionalities:
- Enumerate Loaded Classes: It will print all the loaded classes
- Capture Strings: It will print all the capture strings while using the application (super noisy)
- Capture String Comparisons: Could be very useful. It will show the 2 strings being compared and if the result was True or False.
- Enumerate Class Methods: Put the class name (like “java.io.File”) and it will print all the methods of the class.
- Search Class Pattern: Search classes by pattern
- Trace Class Methods: Trace a whole class (see inputs and outputs of all methods of th class). Remember that by default MobSF traces several interesting Android Api methods.
Once you have selected the auxiliary module you want to use you need to press “Start Intrumentation” and you will see all the outputs in “Frida Live Logs”.
Shell
Mobsf also brings you a shell with some adb commands, MobSF commands, and common shell commands at the bottom of the dynamic analysis page. Some interesting commands:
help
shell ls
activities
exported_activities
services
receivers
HTTP tools
When http traffic is capture you can see an ugly view of the captured traffic on “HTTP(S) Traffic” bottom or a nicer view in “Start HTTPTools” green bottom. From the second option, you can send the captured requests to proxies like Burp or Owasp ZAP.
To do so, power on Burp –> turn off Intercept –> in MobSB HTTPTools select the request –> press “Send to Fuzzer” –> select the proxy address (http://127.0.0.1:8080\).
Once you finish the dynamic analysis with MobSF you can press on “Start Web API Fuzzer” to fuzz http requests an look for vulnerabilities.
Tip
After performing a dynamic analysis with MobSF the proxy settings me be misconfigured and you won’t be able to fix them from the GUI. You can fix the proxy settings by doing:
adb shell settings put global http_proxy :0
Assisted Dynamic Analysis with Inspeckage
You can get the tool from Inspeckage.
This tool with use some Hooks to let you know what is happening in the application while you perform a dynamic analysis.
Yaazhini
This is a great tool to perform static analysis with a GUI
.png)
Qark
This tool is designed to look for several security related Android application vulnerabilities, either in source code or packaged APKs. The tool is also capable of creating a “Proof-of-Concept” deployable APK and ADB commands, to exploit some of the found vulnerabilities (Exposed activities, intents, tapjacking…). As with Drozer, there is no need to root the test device.
pip3 install --user qark # --user is only needed if not using a virtualenv
qark --apk path/to/my.apk
qark --java path/to/parent/java/folder
qark --java path/to/specific/java/file.java
ReverseAPK
- 显示所有提取的文件,便于参考
- 自动将 APK 文件反编译为 Java 和 Smali 格式
- 分析 AndroidManifest.xml 以查找常见漏洞和行为
- 对源代码进行静态分析以查找常见漏洞和行为
- 设备信息
- 以及更多
reverse-apk relative/path/to/APP.apk
SUPER Android Analyzer
SUPER 是一个命令行应用程序,可在 Windows、MacOS X 和 Linux 上使用,用于分析 .apk 文件以查找漏洞。它通过解压 APK 并应用一系列规则来检测这些漏洞。
所有规则集中在 rules.json 文件中,每个公司或测试人员都可以创建自己的规则来分析他们需要的内容。
从 download page 下载最新的二进制文件。
super-analyzer {apk_file}
StaCoAn
.png)
StaCoAn 是一个 跨平台 工具,帮助开发者、bugbounty hunters 和 ethical hackers 对移动应用执行 static code analysis。
该工具的使用方式是将你的移动应用文件(.apk 或 .ipa 文件)拖放到 StaCoAn 应用上,它会为你生成一个可视化且可移植的报告。你可以调整设置和 wordlists 以获得定制化体验。
下载 latest release:
./stacoan
AndroBugs
AndroBugs Framework 是一个 Android 漏洞分析系统,帮助 developers 或 hackers 发现 Android 应用中的潜在安全漏洞。
Windows releases
python androbugs.py -f [APK file]
androbugs.exe -f [APK file]
Androwarn
Androwarn 是一个工具,主要用于检测并提醒用户 Android 应用可能存在的潜在恶意行为。
检测通过使用 androguard 库对应用的 Dalvik bytecode(以 Smali 表示)进行 static analysis 来完成。
该工具会查找 “恶意”应用的常见行为,例如:Telephony identifiers exfiltration, Audio/video flow interception, PIM data modification, Arbitrary code execution…
python androwarn.py -i my_application_to_be_analyzed.apk -r html -v 3
MARA Framework
.png)
MARA 是一个 Mobile Application Reverse engineering and Analysis Framework。它将常用的 mobile application reverse engineering 和 analysis 工具整合在一起,帮助针对 OWASP mobile security threats 对移动应用进行测试。其目标是让移动应用开发者和安全专家更容易、更友好地完成这项工作。
它可以:
- 使用不同的工具提取 Java 和 Smali 代码
- Analyze APKs using: smalisca, ClassyShark, androbugs, androwarn, APKiD
- 使用 regexps 从 APK 中提取私有信息。
- Analyze the Manifest.
- Analyze found domains using: pyssltest, testssl and whatweb
- 通过 apk-deguard.com 进行 APK deobfuscate
Koodous
Useful to detect malware: https://koodous.com/
Obfuscating/Deobfuscating code
注意,根据你用来混淆代码的服务和配置不同,Secrets 可能会被混淆,也可能不会。
ProGuard
From Wikipedia: ProGuard 是一个开源的命令行工具,用于缩小、优化和混淆 Java 代码。它能够优化字节码并检测和移除未使用的指令。ProGuard 是自由软件,在 GNU General Public License 第 2 版下发布。
ProGuard 随 Android SDK 一起分发,并在以 release 模式构建应用时运行。
DexGuard
Find a step-by-step guide to deobfuscate the apk in https://blog.lexfo.fr/dexguard.html
(From that guide) Last time we checked, the Dexguard mode of operation was:
- load a resource as an InputStream;
- feed the result to a class inheriting from FilterInputStream to decrypt it;
- do some useless obfuscation to waste a few minutes of time from a reverser;
- feed the decrypted result to a ZipInputStream to get a DEX file;
- finally load the resulting DEX as a Resource using the
loadDexmethod.
DeGuard
DeGuard 逆转了 Android 混淆工具所执行的混淆过程。这样可以进行多种安全分析,包括代码检查和库识别。
你可以将被混淆的 APK 上传到他们的平台。
[Deobfuscate android App]https://github.com/In3tinct/deobfuscate-android-app
This is a LLM tool to find any potential security vulnerabilities in android apps and deobfuscate android app code. Uses Google’s Gemini public API.
Simplify
It is a generic android deobfuscator. Simplify virtually executes an app to understand its behavior and then tries to optimize the code so it behaves identically but is easier for a human to understand. Each optimization type is simple and generic, so it doesn’t matter what the specific type of obfuscation is used.
APKiD
APKiD gives you information about how an APK was made. It identifies many compilers, packers, obfuscators, and other weird stuff. It’s PEiD for Android.
Manual
Read this tutorial to learn some tricks on how to reverse custom obfuscation
Labs
Androl4b
AndroL4b 是一个基于 ubuntu-mate 的 Android 安全虚拟机,包含来自不同安全研究者的最新框架、教程和实验室资源,用于 reverse engineering 和 malware analysis。
References
- Play Integrity API: How It Works & How to Bypass It
- https://owasp.org/www-project-mobile-app-security/
- https://appsecwiki.com/#/ 这是一个很棒的资源列表
- https://maddiestone.github.io/AndroidAppRE/ Android 快速课程
- https://manifestsecurity.com/android-application-security/
- https://github.com/Ralireza/Android-Security-Teryaagh
- https://www.youtube.com/watch?v=PMKnPaGWxtg&feature=youtu.be&ab_channel=B3nacSec
- SSLPinDetect: Advanced SSL Pinning Detection for Android Security Analysis
- SSLPinDetect GitHub
- smali-sslpin-patterns
- Build a Repeatable Android Bug Bounty Lab: Emulator vs Magisk, Burp, Frida, and Medusa
- CoRPhone — Android in-memory JNI execution and packaging pipeline
- justapk — multi-source APK downloader with Cloudflare bypass
- Jezail rooted Android pentesting toolkit (REST API + Flutter UI)
- BeatBanker: A dual‑mode Android Trojan
Tip
学习和实践 AWS 黑客技术:
HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE)
学习和实践 Azure 黑客技术:
HackTricks Training Azure Red Team Expert (AzRTE)
支持 HackTricks
- 查看 订阅计划!
- 加入 💬 Discord 群组 或 Telegram 群组 或 在 Twitter 🐦 上关注我们 @hacktricks_live.
- 通过向 HackTricks 和 HackTricks Cloud GitHub 仓库提交 PR 来分享黑客技巧。


