fkie-cad/Sandroid_Dexray-Intercept

GitHub: fkie-cad/Sandroid_Dexray-Intercept

基于 Frida 的 Android 应用运行时行为追踪与恶意软件分析工具,支持多维度 Hook 捕获和 DEX 脱壳。

Stars: 3 | Forks: 2

Dexray Intercept Logo

Android Binary API Tracer
# Sandroid - Dexray Intercept ![version](https://img.shields.io/badge/version-1.0.1.4-blue) [![PyPI version](https://badge.fury.io/py/dexray-intercept.svg)](https://badge.fury.io/py/dexray-intercept) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/7f9d915c5c231710.svg)](https://github.com/fkie-cad/Sandroid_Dexray-Intercept/actions/workflows/ci.yml) [![Ruff](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/7584e43ec3231711.svg)](https://github.com/fkie-cad/Sandroid_Dexray-Intercept/actions/workflows/lint.yml) [![Publish status](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/0d542dcdc3231711.svg)](https://github.com/fkie-cad/Sandroid_Dexray-Intercept/actions/workflows/publish.yml) [![Documentation](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/c290f7c268231712.svg)](https://github.com/fkie-cad/Sandroid_Dexray-Intercept/actions/workflows/docs.yml) Dexray Intercept 是动态沙箱 [Sandroid](https://github.com/fkie-cad/Sandroid_core) 的一部分。其目的是创建运行时配置文件以跟踪 Android 应用程序的行为。这是通过利用 frida 来实现的。 ## 安装 只需使用 pip 安装: ``` python3 -m pip install dexray-intercept ``` 这会将 Dexray Intercept 安装为命令行工具 `ammm` 或 `dexray-intercept`。 此外,它还将提供一个包 `dexray_intercept`。关于如何使用该包的更多信息见下文。 ## 运行 请确保您的 Android 设备已获得 root 权限。`frida-server` 将自动安装到最新版本。然后,您只需调用以下命令即可使用 Dexray Intercept: ``` dexray-intercept # 或使用其旧名称: ammm ``` ### Hook 选择(新功能) 所有 hook 默认**已禁用**以获得最佳性能。根据您的分析需求启用 hook: ``` # 启用特定 hooks dexray-intercept --enable-aes # Enable AES crypto hooks dexray-intercept --enable-web # Enable web/HTTP hooks dexray-intercept --enable-aes --enable-web # Enable multiple hooks # 启用 hook 组 dexray-intercept --hooks-crypto # Enable all crypto hooks dexray-intercept --hooks-network # Enable all network hooks dexray-intercept --hooks-filesystem # Enable all file system hooks # 启用所有 hooks (性能影响) dexray-intercept --hooks-all # Enable all available hooks # 使用 package identifier 代替应用名称 dexray-intercept -s com.example.package --hooks-crypto ``` ### 可用的 Hook 类别 - **Crypto**: `--hooks-crypto` (AES, encodings, keystore, certificates) - **Network**: `--hooks-network` (HTTP, sockets, SSL/TLS) - **File System**: `--hooks-filesystem` (file operations, databases, shared preferences) - **IPC**: `--hooks-ipc` (intents, broadcasts, binder, shared preferences) - **Process**: `--hooks-process` (DEX unpacking, native libraries, runtime) - **Services**: `--hooks-services` (camera, location, telephony, bluetooth) 以下是在我们的 AVD 上监控 chrome 应用程序的示例: ``` dexray-intercept Chrome Dexray Intercept ⠀⠀⠀⠀⢀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠙⢷⣤⣤⣴⣶⣶⣦⣤⣤⡾⠋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⠾⠛⢉⣉⣉⣉⡉⠛⠷⣦⣄⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⠋⣠⣴⣿⣿⣿⣿⣿⡿⣿⣶⣌⠹⣷⡀⠀⠀ ⠀⠀⠀⠀⣼⣿⣿⣉⣹⣿⣿⣿⣿⣏⣉⣿⣿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣼⠁⣴⣿⣿⣿⣿⣿⣿⣿⣿⣆⠉⠻⣧⠘⣷⠀⠀ ⠀⠀⠀⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⡇⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠀⠀⠈⠀⢹⡇⠀ ⣠⣄⠀⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠀⣠⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡇⢸⣿⠛⣿⣿⣿⣿⣿⣿⡿⠃⠀⠀⠀⠀⢸⡇⠀ ⣿⣿⡇⢸⣿⣿⣿Sandroid⣿⣿⣿⡇⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣷⠀⢿⡆⠈⠛⠻⠟⠛⠉⠀⠀⠀⠀⠀⠀⣾⠃⠀ ⣿⣿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⣧⡀⠻⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⠃⠀⠀ ⣿⣿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢼⠿⣦⣄⠀⠀⠀⠀⠀⠀⠀⣀⣴⠟⠁⠀⠀⠀ ⣿⣿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⣦⠀⠀⠈⠉⠛⠓⠲⠶⠖⠚⠋⠉⠀⠀⠀⠀⠀⠀ ⠻⠟⠁⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠈⠻⠟⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠉⠉⣿⣿⣿⡏⠉⠉⢹⣿⣿⣿⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⣾⣿⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⣿⣿⣿⡇⠀⠀⢸⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀⢀⣄⠈⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ ⠀⠀⠀⠀⠀⠀⠈⠉⠉⠀⠀⠀⠀⠉⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ [*] starting app profiling [*] press Ctrl+C to stop the profiling ... [*] Filesystem profiling informations: [*] [Libc::read] Read FD (anon_inode:[eventfd],0x7ac6b67540,8) [*] Filesystem profiling informations: [*] [Libc::read] Read FD (anon_inode:[eventfd],0x7fcb41c990,8 ``` ## 作为包运行 ### 新 API(推荐) 将 Dexray Intercept 作为包安装,并使用新的模块化架构: ``` from dexray_intercept import AppProfiler, setup_frida_device from dexray_intercept.services.hook_manager import HookManager # 连接设备并获取进程 device = setup_frida_device() process = device.attach("com.example.app") # 配置 hooks (默认全部禁用以保证性能) hook_config = { 'aes_hooks': True, 'web_hooks': True, 'file_system_hooks': True, 'keystore_hooks': True } # 使用新架构创建 profiler profiler = AppProfiler( process, verbose_mode=True, output_format="JSON", hook_config=hook_config, enable_stacktrace=True ) # 开始分析 script = profiler.start_profiling() # ... 让应用运行并收集数据 ... # 获取结果 profile_data = profiler.get_profile_data() json_output = profiler.get_profiling_log_as_json() # 运行时 hook 管理 profiler.enable_hook('socket_hooks', True) # Enable more hooks at runtime enabled_hooks = profiler.get_enabled_hooks() # Check what's enabled # 停止分析 profiler.stop_profiling() ``` ### Hook 类别 根据您的分析需求启用特定的 hook 组: ``` # Crypto hooks hook_config = { 'aes_hooks': True, 'encodings_hooks': True, 'keystore_hooks': True } # Network hooks hook_config = { 'web_hooks': True, 'socket_hooks': True } # File system hooks hook_config = { 'file_system_hooks': True, 'database_hooks': True } # 启用所有 hooks (性能影响) profiler.enable_all_hooks() # 启用 hook 组 profiler.enable_hook_group('crypto') # Enable all crypto-related hooks ``` ### 旧版 API(向后兼容) 旧版 API 仍然可用,以保持向后兼容性: ``` from dexray_intercept import AppProfilerLegacy # 或使用环境变量:DEXRAY_FORCE_OLD_ARCH=true profiler = AppProfilerLegacy(process_session, verbose=True, output_format="CMD", base_path=None, deactivate_unlink=False) profiler.instrument() # Old method name # ... profiler.finish_app_profiling() # Old method name ``` ### Sandroid 用法 为了在 Sandroid 中将其作为包运行,请确保您也安装了来自 [AndroidFridaManager](https://github.com/fkie-cad/AndroidFridaManager) 的 `JobManager`。这允许在不同的线程中运行多个 frida 会话。 您只需运行以下代码: ``` from AndroidFridaManager import JobManager from dexray_intercept import AppProfiler job_manager = JobManager() app_package = "net.classwindexampleyear.bookseapiececountry" profiler = AppProfiler(job_manager.process_session, True, output_format="JSON", base_path=None, deactivate_unlink=False) frida_script_path = profiler.get_frida_script() job_manager.setup_frida_session(app_package, profiler.on_appProfiling_message) job = job_manager.start_job(frida_script_path, custom_hooking_handler_name=profiler.on_appProfiling_message) # 仅关闭 job 且 frida session 保持活动状态以运行其他 frida 脚本 # job_manager.stop_job_with_id(job.job_id) job_manager.stop_app_with_closing_frida(app_package) # stops the frida session and the app and all frida jobs profiler.write_profiling_log() # write the log data to profile.json # 不将其写入文件,而是直接返回 JSON output # profiler.get_profiling_log_as_JSON() ``` 请确保代码中没有其他部分试图连接到 frida server(即没有其他 frida 会话)。 为了测试这一点,您可以尝试以下样本:[catelites_2018_01_19.apk](https://gitlab.fkie.fraunhofer.de/def/androidmalwaremotionmonitor/-/blob/main/samples/unpacking/catelites_2018_01_19.apk?ref_type=heads)。该包的名称是 `net.classwindexampleyear.bookseapiececountry`。请确保您的 AVD 运行的是 Android 9,以便该样本可以执行其所有恶意代码。您可以使用 `adb install samples/unpacking/catelites_2018_01_19.apk` 简单地安装此样本。 ## 编译与开发 为了编译此项目,请确保您的系统上运行着 `npm` 和 `frida-compile` 并已安装到您的路径中。自 frida 版本 17.0 起,`frida-compile` 通过 `pip install frida-tools` 安装。 然后只需调用以下命令即可获取最新编译的 frida agent: ``` $ cd > Dexray Intercept@0.0.1.5 build > frida-compile agent/hooking_profile_loader.ts -o src/dexray_intercept/profiling.js $ npm install frida-java-bridge@latest --save $ npm install --save-dev @types/frida-gum@latest > Dexray Intercept@0.0.1.5 prepare > npm run build up to date, audited 75 packages in 6s 19 packages are looking for funding run `npm fund` for details found 0 vulnerabilities ``` 这确保了在 `dexray-intercept` 中使用最新的 frida 脚本/hooks。 为了对 python 代码进行调整,建议利用可编辑模式通过 pip 安装 `dexray-intercept`: ``` python3 -m pip install -e . ``` 这样,python 代码中的本地更改将立即生效,而无需创建新版本的包。 ## 📚 文档 提供涵盖安装、使用、API 参考和开发的详尽文档: - **[📖 完整文档](https://your-username.github.io/Sandroid_Dexray-Intercept/)** - 完整的文档站点 - **[🚀 快速入门指南](https://your-username.github.io/Sandroid_Dexray-Intercept/quickstart.html)** - 几分钟内快速上手 - **[🐍 Python API 参考](https://your-username.github.io/Sandroid_Dexray-Intercept/api/python-api.html)** - 编程用法 - **[🔧 TypeScript API 参考](https://your-username.github.io/Sandroid_Dexray-Intercept/api/typescript-api.html)** - 自定义 hook 开发 - **[💻 CLI 使用指南](https://your-username.github.io/Sandroid_Dexray-Intercept/user-guide/cli-usage.html)** - 命令行界面 - **[⚙️ Hook 配置](https://your-username.github.io/Sandroid_Dexray-Intercept/user-guide/hook-configuration.html)** - Hook 类别和选项 ## 系统要求 只需在此目录中调用以下命令,`setup.py` 即可用于将 `dexray-intercept` 作为本地 python 包安装到您的系统: ``` python3 -m pip install . ``` ### 开发环境 为了编译 TypeScript frida hooks,我们需要 `frida-compile` ([链接](https://github.com/frida/frida-compile)) 项目。它将与 `frida-tools` 一起打包。 ``` python3 -m pip install frida-tools ``` 除此之外,我们还需要对 `frida-java-bridge` 和内部 frida 类型的支持: ``` npm install frida-java-bridge@latest --save npm install --save-dev @types/frida-gum@latest ``` ### 深度脱壳 在脱壳时,应用程序可能会将 DexCode(之前指向不同的内存块)加载到 DexFile 中,这代表了正在执行的代码。例如,某些应用程序可能会在执行前立即恢复指令。在这种情况下,Sandroid 无法将指令还原到 DexFile 中。需要进一步研究来解决这个问题。 ## 致谢 Dexray Intercept 建立在 Android 安全和动态分析社区中各种开源项目和研究人员的杰出工作之上。我们要感谢以下项目,它们启发或贡献了我们的实现: ### 核心 Frida 框架 - **[Frida](https://frida.re/)** - 为我们的运行时分析能力提供支持动态插桩工具包 - **[frida-java-bridge](https://github.com/frida/frida-java-bridge)** - 对 Java/Android 运行时插桩至关重要 ### Hook 实现与技术 - **[AppMon](https://github.com/dpnishant/appmon)** 作者 @dpnishant - 为运行时分析、IPC 监控、剪贴板访问和数据库操作提供了基础 hooks - **[Android-Malware-Sandbox](https://github.com/Areizen/Android-Malware-Sandbox)** 作者 @Areizen - Base64 编码 hooks 和 socket 监控技术 - **[RMS-Runtime-Mobile-Security](https://github.com/m0bilesecurity/RMS-Runtime-Mobile-Security)** 作者 @m0bilesecurity - Keystore 分析和证书锁定检测 - **[Medusa](https://github.com/Ch0pin/medusa)** 作者 @Ch0pin - 运行时分析模式和 DEX 脱壳技术 - **[frida-android-libbinder](https://github.com/Hamz-a/frida-android-libbinder)** 作者 @Hamz-a - Android Binder IPC 分析 - **[frida-snippets](https://github.com/iddoeldor/frida-snippets)** 作者 @iddoeldor - 位置欺骗和实用函数 ### Android 安全研究 - **[BlackDex](https://github.com/CodingGay/BlackDex)** 作者 @CodingGay - DEX 脱壳和反分析绕过技术 - **[Frida-Python-Binding](https://github.com/Mind0xP/Frida-Python-Binding)** 作者 @Mind0xP - Frida 的 Python 集成模式 ### SQLite 与数据库分析 - **[SQLite Database Hook](https://codeshare.frida.re/@ninjadiary/sqlite-database/)** 作者 @ninjadiary - 数据库监控技术 我们要向这些项目及其维护者表示感谢,感谢他们推动了 Android 安全分析的发展并将其工作分享给社区。 ## 路线图 - [ x ] 为我们要安装的不同 hook 创建模板,以获取运行时配置文件 - [ ] 创建一个测试应用程序,使用我们想要 hook 的所有不同功能(我们需要某种基本事实来测试我们的 hooks) - [ ] 实现实际的 hooks - [ x ] 打印监控信息的格式 - [ ] https://attack.mitre.org/matrices/mobile/ 将此添加为最终结果,以便我们可以说出应用程序正在使用何种攻击 - [ ] 我们还想跟踪诸如“这是隐私问题”、“这可能导致错误”之类的事情...
标签:AMSI绕过, Android, API追踪, DAST, DEX分析, Docker支持, DSL, Frida, Hook技术, Python, Root环境, 云资产清单, 加密监测, 威胁检测, 恶意软件分析, 数据库审计, 文件系统监控, 无后门, 暗色界面, 沙箱, 目录枚举, 移动安全, 网络安全, 自定义脚本, 自定义脚本, 自定义脚本, 运行时剖析, 逆向工具, 逆向工程, 隐私保护