Keychain/Keystore Misuse
keychain_keystore_misuse MEDIUM
| Category | Insecure Data Storage |
| OWASP Mobile (2024) | M9 |
| MASVS | MASVS-STORAGE-1MASVS-CRYPTO-2 |
| MASWE | MASWE-0003 |
| MASTG (v2 tests) | iOSMASTG-TEST-0300MASTG-TEST-0301AndroidMASTG-TEST-0287 |
| MASTG demos | iOSNone publishedAndroidMASTG-DEMO-0059 |
| CWE | CWE-312CWE-522 |
| Platform | AndroidiOS |
| Platform notes | Android Keystore/EncryptedSharedPreferences; iOS Keychain (kSecAttr* accessibility). |
Description
Secrets stored without hardware-backed protection / with weak accessibility flags.
How it works
The secret is stored in the platform secret store with the weakest accessibility class (kSecAttrAccessibleAlways / no user-auth, no hardware backing). On device the value lands in the local key-value store (SharedPreferences on Android, UserDefaults on iOS) in cleartext, so it is readable while the device is locked, is copied into backups, and is recoverable via adb or a rooted/jailbroken device. The stronger exploit is platform-level (keychain-dumper / frida); the weak flags and the missing auth gate are the faithful core of the finding.
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 Insecure Data Storage 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:objection,frida,r2frida· Android:adb,run-as,KeyStore inspection,jadx· iOS:objection,keychain-dumper,plutil. - Locate the target. From the home index, open Keychain/Keystore Misuse (
keychain_keystore_misuse). 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. Exercise the flow that persists data, then inspect on-device storage (
adb shell run-as <pkg>/ pull the app sandbox, orobjection’sandroid keystore/ios nsuserdefaultshelpers) and confirm the sensitive value is present in cleartext or without hardware backing. - 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-0287, MASTG-TEST-0300, MASTG-TEST-0301 for the canonical procedure and remediation.
Tools (optional)
Android
iOS
Real-world references
Concrete public disclosures that match this vulnerability class: