ksg97031/frida-gadget

GitHub: ksg97031/frida-gadget

这是一个自动化修补Android APK以集成Frida Gadget的工具,用于动态分析和安全测试。

Stars: 406 | Forks: 50

# frida-gadget |Codacy-Grade| |Docker| |LICENCE| | ``frida-gadget`` 是一个用于修补 Android 应用程序以集成 `Frida Gadget `_ 的工具。 | 此工具自动化了下载 Frida gadget 库并将 ``loadLibrary`` 代码注入主活动的过程。 ## 安装说明 |Py-Versions| |PyPI-Downloads| .. code:: sh ``` pip install frida-gadget --upgrade ``` ## 前置条件 | 您需要安装 ``apktool`` 并将其添加到您的 ``PATH`` 环境变量中。 | .. code:: sh # 在 macOS 上安装 Apktool brew install apktool # 将 Apktool 添加到 PATH 环境变量 export PATH=$PATH:$HOME/.brew/bin | 对于其他操作系统,例如 ``Windows``,您可以参考 `安装指南 `_。 ## 使用方法 .. code:: sh ``` $ frida-gadget --help Usage: cli.py [OPTIONS] APK_PATH Patch an APK with the Frida gadget library Options: --arch TEXT Specify the target architecture of the device. (options: arm64, x86_64, arm, x86) --config TEXT Specify the Frida configuration file. --js TEXT Specify the Frida gadget JavaScript file. --js-delay INTEGER Specify seconds to wait before executing the JavaScript file. --force-manifest Force modify AndroidManifest.xml even if it already has required permissions. --custom-gadget-name TEXT Specify a custom name for the Frida gadget. --no-res Skip decoding resources. --main-activity TEXT Specify the main activity if known. --sign Automatically sign the APK using uber-apk-signer. --skip-decompile Skip the decompilation step. --skip-recompile Skip the recompilation step. --use-aapt2 Use aapt2 instead of aapt for resource processing. --decompile-opts TEXT Specify additional options for apktool decompile. --recompile-opts TEXT Specify additional options for apktool recompile. --apktool-path TEXT Specify the path or command to run apktool. --frida-version TEXT Specify the Frida version to use. --ks TEXT The keystore file. If not provided, will use debug keystore. --ks-alias TEXT The alias of the used key in the keystore. --ks-key-pass TEXT The password for the key. --ks-pass TEXT The password for the keystore. --version Show the version and exit. --help Show this message and exit. ``` ### 如何开始? | 只需提供带有目标架构的 APK 文件即可。 | .. code:: sh ``` $ frida-gadget target.apk --sign [INFO] Auto-detected frida version: 16.1.3 [INFO] APK: '[REDACTED]/demo-apk/target.apk' [INFO] Auto-detected architecture via ADB: arm64-v8a # Alternatively, specify the architecture with --arch arm64 [INFO] Gadget Architecture(--arch): arm64(default) [DEBUG] Decompiling the target APK using apktool [DEBUG] Downloading the frida gadget library for arm64 [DEBUG] Checking internet permission and extractNativeLibs settings [DEBUG] Adding 'android.permission.INTERNET' permission to AndroidManifest.xml [DEBUG] Searching for the main activity in the smali files [DEBUG] Found the main activity at '[REDACTED]/frida-gadget/tests/demo-apk/target/smali/com/google/mediap/apps/target/MainActivity.smali' [DEBUG] Locating the onCreate method and injecting the loadLibrary code [DEBUG] Recompiling the new APK using apktool ... [INFO] APK signing finished: ./target/dist/target-aligned-debugSigned.apk (72.78 MiB) ``` ### 使用 Docker | 您也可以通过 Docker 使用此工具。以下是使用方法: | | 1. 首先,拉取 Docker 镜像: | .. code:: sh ``` docker pull ksg97031/frida-gadget ``` | 2. 将本地包含 APK 文件的目录挂载到容器中: | .. code:: sh ``` docker run -v $(pwd):/workspace/mount ksg97031/frida-gadget /workspace/mount/your-app.apk --arch arm64 ``` | 注意:将 ``your-app.apk`` 替换为您的实际 APK 文件名。修补后的 APK 将在与原始 APK 相同的目录中创建。 | | 例如,如果您的 APK 名为 ``example.apk``: | .. code:: sh ``` docker run -v $(pwd):/workspace/mount ksg97031/frida-gadget /workspace/mount/example.apk --arch arm64 # 已修补的 APK 将位于 ./example/dist/example.apk ``` ## 兼容性 ### 设备架构 | 当连接 ADB 设备时,该工具会自动检测设备架构。您也可以使用 ``--arch`` 选项手动指定架构。 | | 要确定您设备的架构,请连接您的设备并运行以下命令: | .. code:: sh ``` adb shell getprop ro.product.cpu.abi ``` | 此命令将输出您设备的架构,例如 ``arm64-v8a``、``armeabi-v7a``、``x86``、``x86_64`` 或 ``multi-arch``。 | 自动检测示例: | .. code:: sh ``` $ frida-gadget target.apk --sign [INFO] Auto-detected architecture via ADB: arm64-v8a ``` | 手动指定示例: | .. code:: sh ``` $ frida-gadget target.apk --arch arm64 --sign [INFO] Gadget Architecture(--arch): arm64 ``` ### Android 版本支持 | 下表显示了不同 Android 版本所需的最低 Frida 版本: | (注意:此信息可能并非完全准确) .. list-table:: :header-rows: 1 * - Android 版本 - 最低 Frida 版本 - 备注 * - Android 5.x ~ 7.x (Lollipop~Nougat) - Frida 14.2+ - Frida 12.6 改进了对旧版 Android 的支持。Frida 14.2 包含了针对 libc 检测错误的修复并恢复了 Houdini(翻译器)支持。最新的 Frida (16.x) 仍支持 Android 5~7。 * - Android 8.0 ~ 8.1 (Oreo) - Frida 12.6.6+ - Java API 问题如 Java.choose 在 Frida 12.6.3+ 中已解决。32 位 ARM 设备上的 Java 集成问题在 Frida 12.6.6 中修复。Frida 14.x 及更新版本在 Oreo 上运行稳定。 * - Android 9.0 (Pie) - Frida 12.7+ - Frida 在 Pixel 3 (Android 9) 上进行了广泛测试。Frida 12.x ~ 15.x 版本在基于 AOSP 的 Android 9 上运行稳定。最新的 Frida 16.x 也支持 Android 9。(对于模拟器,推荐使用 Google 提供的 arm/arm64 的 Android 9 镜像。) * - Android 10 (Q) - Frida 14.2+ - 虽然没有针对 Android 10 的特定重大更改,但为获得整体稳定性建议使用 Frida 14.2+。Frida 14.2 包含了对 Android 10 前后版本的多项兼容性改进。最新的 Frida 15.x 和 16.x 版本在 Android 10 上运行无问题。 * - Android 11 (R) - Frida 14.2+ - Frida 14.2 包含了针对 Android 11 中 ART 更改和 ARM->x86 转换的修改。Android 11 建议使用 Frida 14.2 或更高版本。Frida 15.x~16.x 完全支持 Android 11。(在三星等自定义 ROM 上可能存在独立问题。) * - Android 12 (S) - Frida 15.0+ - Android 12 的官方支持首次在 Frida 15.0 中添加。初始的 15.0 版本存在一些小的兼容性问题,但 Frida 15.1.23 包含了针对 Android 12 的多项稳定性改进。Android 12 设备建议使用 Frida 15.1.23 或更高版本(最好是 15.2 或最新的 16.x)。 * - Android 13 (T) - Frida 15.1.23+ - 对 Android 13 的初步支持在 Frida 15.1.23 中引入,并在 Frida 16.x 版本中成熟。Android 13 设备至少需要 Frida 15.1.23,但建议使用最新的 Frida 16 版本(包含针对 Android 13 内部行为更改的修复)。 * - Android 14 (UpsideDownCake) - Frida 16.2.0+ - 由于 Android 14 中的 ART 结构更改,初始的 Frida 16.0~16.1 版本在 Java hook 方面存在问题,但 Frida 16.2.0 改进了对 Android 14 的 hook 支持。Android 14 建议使用 Frida 16.2 或更高版本(Frida 16.2 添加了对 Android 14 新 ART 入口点的支持)。 ### 如何识别注入? | 您可以观察主活动以查看注入的 ``loadLibrary`` 代码。 | 此外,Frida gadget 库将存在于您的 APK 中。 .. code:: sh ``` $ unzip -l [REDACTED]/demo-apk/target/dist/target.apk | grep libfrida-gadget 21133848 09-15-2021 02:28 lib/arm64-v8a/libfrida-gadget-16.1.3-android-arm64.so ``` ## 提示 ### 指定不同的主活动 | 如果未自动检测到主活动,您可以使用 ``--main-activity`` 选项手动指定: | .. code:: sh ``` $ frida-gadget target.apk --main-activity com.example.MainActivity --no-res --sign ``` ### 使用 --js 创建自带 SSL 旁路的应用 | 1. 下载 `@akabe1/frida-multiple-unpinning `_ 脚本。 | 2. 使用 ``--js`` 标志将脚本注入目标应用。 .. code:: sh ``` frida-gadget target.apk --js frida-multiple-unpinning.js --sign --no-res ``` | 3. 在您的设备或模拟器上运行注入后的应用。 | 4. 使用代理工具如 `Burp Suite `_ 或 `Caido `_ 观察网络流量。 | | 注意:如果应用崩溃,请尝试添加 ``--js-delay 2`` 来延迟脚本执行: .. code:: sh ``` frida-gadget target.apk --js frida-multiple-unpinning.js --js-delay 2 --sign --no-res ``` | 这给了应用在应用 hook 之前进行初始化的时间。 | | 您还可以使用 ``--frida-version`` 指定自定义的 Frida 版本: .. code:: sh ``` frida-gadget target.apk --js frida-multiple-unpinning.js --frida-version 16.1.3 --sign --no-res ``` | 当出于兼容性原因需要使用特定 Frida 版本时,这很有用。 ### 使用自定义 Apktool | 您可以使用 ``--apktool-path`` 选项指定自定义的 apktool 路径或命令。 | 例如,您可以使用脚本或特定的 jar 文件: | .. code:: sh ``` $ frida-gadget target.apk --apktool-path ./tools/apktool.bat --sign # Windows $ frida-gadget target.apk --apktool-path "java -Xmx16g -jar ~/Download/apktool.jar" --sign # Java with 16GB memory ``` ### 自定义 Apktool 选项 | 您还可以使用 ``--decompile-opts`` 和 ``--recompile-opts`` 选项为 apktool 的反编译和重新编译指定自定义选项。 | 例如,您可以向 apktool 传递额外的标志: | .. code:: sh ``` $ frida-gadget target.apk --decompile-opts "--only-main-classes --no-res" --recompile-opts "--force-all" --sign ``` ## 贡献 .. image:: CONTRIBUTORS.svg :target: ./CONTRIBUTORS.svg .. |Coverage-Status| image:: https://img.shields.io/coveralls/github/ksg97031/frida-gadget/master?logo=coveralls :target: https://coveralls.io/github/ksg97031/frida-gadget .. |Branch-Coverage-Status| image:: https://codecov.io/gh/ksg97031/frida-gadget/branch/master/graph/badge.svg :target: https://codecov.io/gh/ksg97031/frida-gadget .. |Codacy-Grade| image:: https://app.codacy.com/project/badge/Grade/a1e2ef93fd3842e4b9e92971c135ed3f :target: https://app.codacy.com/gh/ksg97031/frida-gadget/dashboard .. |CII Best Practices| image:: https://bestpractices.coreinfrastructure.org/projects/3264/badge :target: https://bestpractices.coreinfrastructure.org/projects/3264 .. |GitHub-Status| image:: https://img.shields.io/github/tag/ksg97031/frida-gadget.svg?maxAge=86400&logo=github&logoColor=white :target: https://github.com/ksg97031/frida-gadget/releases .. |GitHub-Forks| image:: https://img.shields.io/github/forks/ksg97031/frida-gadget.svg?logo=github&logoColor=white :target: https://github.com/ksg97031/frida-gadget/network .. |GitHub-Stars| image:: https://img.shields.io/github/stars/ksg97031/frida-gadget.svg?logo=github&logoColor=white :target: https://github.com/ksg97031/frida-gadget/stargazers .. |GitHub-Commits| image:: https://img.shields.io/github/commit-activity/y/ksg97031/frida-gadget.svg?logo=git&logoColor=white :target: https://github.com/ksg97031/frida-gadget/graphs/commit-activity .. |GitHub-Issues| image:: https://img.shields.io/github/issues-closed/ksg97031/frida-gadget.svg?logo=github&logoColor=white :target: https://github.com/ksg97031/frida-gadget/issues?q= .. |GitHub-PRs| image:: https://img.shields.io/github/issues-pr-closed/ksg97031/frida-gadget.svg?logo=github&logoColor=white :target: https://github.com/ksg97031/frida-gadget/pulls .. |GitHub-Contributions| image:: https://img.shields.io/github/contributors/ksg97031/frida-gadget.svg?logo=github&logoColor=white :target: https://github.com/ksg97031/frida-gadget/graphs/contributors .. |GitHub-Updated| image:: https://img.shields.io/github/last-commit/ksg97031/frida-gadget/master.svg?logo=github&logoColor=white&label=pushed :target: https://github.com/ksg97031/frida-gadget/pulse .. |Gift-Casper| image:: https://img.shields.io/badge/dynamic/json.svg?color=ff69b4&label=gifts%20received&prefix=%C2%A3&query=%24..sum&url=https%3A%2F%2Fcaspersci.uk.to%2Fgifts.json :target: https://cdcl.ml/sponsor .. |PyPI-Downloads| image:: https://static.pepy.tech/badge/frida-gadget :target: https://pepy.tech/project/frida-gadget .. |Py-Versions| image:: https://img.shields.io/pypi/pyversions/frida-gadget :target: https://pypi.org/project/frida-gadget .. |Conda-Forge-Status| image:: https://img.shields.io/conda/v/conda-forge/frida-gadget.svg?label=conda-forge&logo=conda-forge :target: https://anaconda.org/conda-forge/frida-gadget .. |Docker| image:: https://img.shields.io/badge/docker-pull-blue.svg?logo=docker&logoColor=white :target: https://github.com/ksg97031/frida-gadget/pkgs/container/frida-gadget .. |Libraries-Dependents| image:: https://img.shields.io/librariesio/dependent-repos/pypi/frida-gadget.svg?logo=koding&logoColor=white :target: https://github.com/ksg97031/frida-gadget/network/dependents .. |OpenHub-Status| image:: https://www.openhub.net/p/frida-gadget/widgets/project_thin_badge?format=gif :target: https://www.openhub.net/p/frida-gadget?ref=Thin+badge .. |awesome-python| image:: https://awesome.re/mentioned-badge.svg :target: https://github.com/vinta/awesome-python .. |LICENCE| image:: https://img.shields.io/pypi/l/frida-gadget.svg :target: https://raw.githubusercontent.com/ksg97031/frida-gadget/master/LICENCE .. |DOI| image:: https://img.shields.io/badge/DOI-10.5281/zenodo.595120-blue.svg :target: https://doi.org/10.5281/zenodo.595120 .. |binder-demo| image:: https://mybinder.org/badge_logo.svg :target: https://mybinder.org/v2/gh/ksg97031/frida-gadget/master?filepath=DEMO.ipynb
标签:AndroidManifest修改, Android安全, APKtool, APK修补, APK反编译, APK重编译, DAST, Frida gadget, SEO: Android APK patching, SEO: frida-gadget, 云资产清单, 动态二进制插桩, 安全测试, 恶意软件分析, 攻击性安全, 数字取证, 移动应用安全, 移动应用逆向, 签名工具, 自动化脚本, 请求拦截, 逆向工具, 逆向工程