Unsafe Deserialization
← Input Validation (OWASP Mobile M4)
unsafe_deserialization HARD
| Category | Input Validation (OWASP Mobile M4) |
| OWASP Mobile (2024) | M4 |
| MASVS | MASVS-CODE-4 |
| MASWE | MASWE-0050 |
| MASTG (v2 tests) | iOSMASTG-TEST-0386AndroidMASTG-TEST-0337 |
| MASTG demos | iOSNone publishedAndroidMASTG-DEMO-0100 |
| CWE | CWE-502 |
| Platform | AndroidiOS |
Description
Deserializes untrusted data into typed objects with no validation.
How it works
Untrusted JSON is deserialized straight into a privileged session object with no validation, so attacker-supplied fields (isAdmin, role) and even a payload-named type are trusted. The built object is then persisted to the local key-value store (SharedPreferences on Android, UserDefaults on iOS), so the injected privilege survives on disk and is recoverable across launches (recover the backing file, SharedPreferences XML on Android or a UserDefaults plist on iOS, with adb or on a rooted/jailbroken device). Edit the payload below to grant yourself admin. The secure path validates against a strict schema/allowlist and never lets input choose privilege or a type.
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 Input Validation (OWASP Mobile M4) 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:frida,r2frida· Android:jadx· iOS:class-dump. - Locate the target. From the home index, open Unsafe Deserialization (
unsafe_deserialization). 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. Feed the crafted/malformed input (serialized blob, intent extra, media file, deep link) into the parsing path and confirm the app trusts it - state change, crash/DoS, or code path it should reject.
- 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-0337, MASTG-TEST-0386 for the canonical procedure and remediation.
Tools (optional)
Android
iOS
Attack inputs
Payloads/artifacts you author for the on-device attack. The demo already ships and simulates these in-process (e.g. the malicious companion app / crafted intent is emulated inside the screen), so you only need to craft them to reproduce the exploit on a real device:
crafted payloads