Native Code Memory Bugs (JNI buffer overflow)
native_code_memory_bugs HARD
| Category | Code Quality & Build Config |
| OWASP Mobile (2024) | M7 |
| MASVS | MASVS-CODE-4 |
| MASWE | MASWE-0050 |
| MASTG (v2 tests) | iOSMASTG-TEST-0086AndroidMASTG-TEST-0043 |
| CWE | CWE-120CWE-787 |
| Platform | AndroidiOS |
Description
A small JNI/FFI routine with a classic unbounded copy (optional/high-effort).
How it works
A JNI routine does strcpy into a fixed 16-byte stack buffer with no bounds check, so oversized input overwrites the adjacent canary (a classic stack smash). A second routine frees a heap record and keeps using it through the dangling pointer before freeing it again (use-after-free plus double free). On a device both run real compiled C in libdvma_native.so, inspectable with Ghidra/gdb/frida, and report what was clobbered; off-device the strcpy falls back to an offline model so the demo stays testable.
How to exercise it. DVMA is the harness - open this module from the home index and tap the demo action. The screen ships the malicious input and simulates the attacker (e.g. the companion app, crafted intent, or scanned payload) in-process, and the evidence panel prints the proof. The Tools (optional) and Attack inputs below are only needed to reproduce the exploit end-to-end on a real device.
Exploit steps
- Set up. Build DVMA with a flavor that enables the Code Quality & Build Config category (e.g.
--dart-define-from-file=config/flavors/dev.json) and run on an emulator/simulator you control. The demo needs no external tooling; for the optional on-device reproduction the relevant tools are:r2,r2ghidra,Ghidra,JEB,frida,r2frida,IDA· Android:gdb,jadx· iOS:lldb,Hopper,class-dump. - Locate the target. From the home index, open Native Code Memory Bugs (JNI buffer overflow) (
native_code_memory_bugs). The How it works section above describes this module’s specific weakness; the screen states the intended-secure behavior and exposes the vulnerable action. - Exploit. Statically inspect the shipped artifact (
jadx,strings,nm,aapt dump badging) and confirm the build/quality weakness is present in the release binary. - Observe the evidence. Trigger the vulnerable action and read the evidence panel - it prints the concrete proof (leaked value, accepted replay, executed payload, or unauthorized result).
- Contrast with the secure path. Run the module’s secure/hardened action (where provided) and confirm the same attack is rejected - this is what a correct implementation should do.
- Map it back. Cross-reference the MASTG v2 test(s) MASTG-TEST-0043, MASTG-TEST-0086 for the canonical procedure and remediation.
Tools (optional)
Android
iOS