arkup/dexbgd

GitHub: arkup/dexbgd

基于 JVMTI 的原生 Android DEX 调试器,支持字节码级单步执行、实时变量检视和运行时操控。

Stars: 2 | Forks: 0

# dexbgd - DEX 调试器

BGD Logo

一款真正的 Android 应用调试器。它不是 hook 框架,也不是 JDWP —— 这是一个原生 JVMTI 调试器,允许你暂停任何 Java 方法,逐条 Dalvik 字节码指令单步执行,检查每一个局部变量和寄存器,搜索活动堆内存,并强制方法返回你想要的任何值。 专为 CTF、恶意软件分析和逆向工程打造。应用内是轻量级 C++ agent,主机端是 Rust TUI。

BGD Screenshot

## 它与 Frida 有何不同? Frida 用 JavaScript hook 替换函数。dexbgd **暂停执行** 并让你观察状态。不同的工具解决不同的问题。 | | dexbgd | Frida | |---|---|---| | 在任意字节码处停止 | 是 | 否 (仅方法级) | | 逐条指令单步执行 | 是 | 否 | | 暂停时读取每个局部变量/寄存器 | 是 | 仅限 hook 捕获的内容 | | 动态强制返回值 | 是, `fr false` | 是 (需编写 hook 脚本) | | 内置 DEX 反汇编器 | 是, 实时 PC & 栈帧 | 需要外部工具 (jadx, baksmali) | | 实时堆内存搜索 | `heap SecretKey` | 需要自定义脚本 | | 自动拦截动态类加载 | 内置 | 需要脚本 | | Native 代码 | 否 (仅 DEX 字节码) | 是 (多架构 native) | | 检测特征 | 标准调试 API + 可选 ptrace | frida-server, gadget, ptrace | | 需要可调试 | 是 (或通过 root + ptrace 绕过) | 否 (需要 root 或重打包) | **使用 dexbgd** 当你需要细粒度地观察执行过程时 —— 单步跟踪 root 检测、观察执行期间的加密状态、追踪动态类加载,或逐条指令绕过逻辑。 ## 它能做什么 / 快速开始 ``` // Terminal 1 > adb forward tcp:12345 localabstract:dexbgd > adb shell cmd activity attach-agent com.sketchy.apkapp libart_jit_tracer.so // Terminal 2 (server TUI) > launch com.sketchy.apkapp (same as adb shell am start -n com.sketchy.apkapp/.MainActivity) Connected (pid=12847, Android 14, arm64) Loaded APK: 847 classes, 6203 methods > bp-detect Set 14 breakpoints on root/tamper detection APIs > c Breakpoint #3 hit: Debug.isDebuggerConnected @0 > fr false [forced return false, paused at caller] > c Breakpoint #7 hit: RootBeer.isRooted @0 > fr false [app thinks device is clean, continues] > bp-crypto > c Breakpoint #31 hit: Cipher.init @0 > locals opmode = 1 (ENCRYPT) key = SecretKeySpec{AES, [4b 65 79 31 32 33 ...]} > eval v2.getAlgorithm() "AES/CBC/PKCS5Padding" > strings http [apk] "https://c2server.evil.com/exfil" [apk] "http://license.check.net/verify" > xref-bp c2server Set bp on MainActivity.sendData (loads "https://c2server.evil.com/exfil") ``` ## 功能特性 ### 断点配置文件 一条命令覆盖整个攻击面: ``` bp-crypto Cipher, SecretKeySpec, IvParameterSpec, Mac, MessageDigest, KeyGenerator, KeyStore bp-network URL, HttpURLConnection, HttpsURLConnection, Socket, OkHttp bp-exec Runtime.exec, ProcessBuilder, DexClassLoader, PathClassLoader, InMemoryDexClassLoader, Method.invoke, Class.forName, ClassLoader.loadClass bp-detect Debug.isDebuggerConnected, SafetyNet, Play Integrity, File.exists, SystemProperties, ActivityManager, Settings$Secure, signature checks bp-exfil TelephonyManager, ContentResolver, SMS, Location, PackageManager.getInstalledPackages bp-ssl NetworkSecurityTrustManager, SSLContext.init, HttpsURLConnection, OkHttp CertificatePinner, Conscrypt TrustManagerImpl bp-all All of the above ``` ### 强制返回 让任何方法在挂起时返回你想要的任何内容。agent 会自动推断返回类型。 ``` fr true isRooted() -> true? Not anymore. fr false isDebuggerConnected() -> false. fr null getSignature() -> null. Signature check bypassed. fr 42 getRetryCount() -> 42. Why not. ``` 强制返回后,执行会在调用者的下一条指令处暂停,以便你在继续之前查看效果。 ### 动态 DEX 拦截 当 `bp-exec` 处于活动状态且应用在运行时加载代码(DexClassLoader, InMemoryDexClassLoader)时,dexbgd 会自动: 1. 转储加载的 DEX 字节 2. 解析类/方法/字符串表 3. 将它们合并到可搜索的符号数据中 因此 `strings` 和 `xref` 涵盖了原始 APK 和动态加载的 payload —— 即恶意软件真正试图隐藏的东西。 ### 条件断点 ``` bp Cipher init --when "v1 == 1" Break only on ENCRYPT mode bp HttpURLConnection connect --every 5 Break every 5th call bp LicenseCheck verify --hits 3 Break only on 3rd hit ``` 有关完整的表达式语法和更多示例,请参阅 [doc/breakpoint_cond.md](doc/breakpoint_cond.md)。 ### 调用记录 将安全相关的 API 调用记录为缩进的调用树: ``` > record > c [app runs for a while] > record Cipher.getInstance("AES/CBC/PKCS5Padding") SecretKeySpec.([...], "AES") Cipher.init(1, SecretKeySpec) Cipher.doFinal([...]) -> [encrypted bytes] URL.("https://c2server.evil.com/exfil") HttpURLConnection.connect() ``` ### AI 辅助分析 (实验性) 将 LLM 指向调试器并让它驱动: ``` > ai Find all crypto keys used by this app and trace where the ciphertext goes > ai ask Bypass root detection (confirms each tool call) > ai explain What is this method doing? (read-only inspection) ``` AI 可以访问所有调试器工具 —— 它可以设置断点、单步执行、检查变量、搜索字符串并生成报告。支持 Claude API 和本地 Ollama 模型。 有关设置说明,请参阅 [doc/ai_setup.md](doc/ai_setup.md)。 ## 命令参考 ### 连接 ``` procs / ps List debuggable processes attach Inject agent + connect + load symbols launch Start app + attach connect Manual connect (127.0.0.1:12345) disconnect / dc Disconnect ``` ### 探索 ``` cls [pattern] Search loaded classes methods / m List methods fields / f List fields threads / thd List all threads dis Disassemble method u Navigate to method (WinDbg-style unassemble) strings Search DEX constant pool xref Find code referencing a string xref-bp xref + set breakpoints apk Load APK symbols ``` ### 断点 ``` bp [sig] [@loc] Set breakpoint --hits N / --every N / --when "expr" bc / bd Clear breakpoint bc / bd * Clear all bl List breakpoints ``` ### 执行 ``` c / g / F5 Continue si / F7 Step into s / n / F8 Step over sout / finish / F9 Step out pause / F6 Suspend thread fr Force return (true/false/null/void/0/1/) ``` ### 检查 ``` locals / l Local variables stack / bt Call stack inspect / i Object fields eval / e Evaluate (v3.getAlgorithm()) hexdump / hd Hex dump arrays/strings hexdump / hd full Extended hex dump (32 rows) heap Search heap instances heapstr Search live strings r / regs Dump registers ``` ### 监视 ``` watch Add expression to watch list (re-evaluated on every suspension) unwatch Remove watch by index or expression unwatch * Remove all watches watch clear Same as unwatch * e.g. watch key watch v3 watch v3.getAlgorithm() ``` ### 书签 ``` Ctrl+B Toggle bookmark at bytecode cursor bm
标签:Android 安全, CTF 工具, Dalvik 字节码, DAST, DEX 调试器, Hook 技术, JVMTI, Root 检测绕过, Rust TUI, 云资产清单, 内存检查, 反调试对抗, 可视化界面, 堆搜索, 恶意软件分析, 目录枚举, 移动安全, 网络安全, 运行时篡改, 逆向工程, 通知系统, 隐私保护