Skip to content
Pwnversity
MOB-STORAGEintermediate · 6 min · upd. 2026-10

Insecure Storage

CWE-312

One of the most common and easy-to-find flaw classes in mobile apps is storing sensitive data —tokens, passwords, keys, PII, session information— on the device unencrypted or in accessible locations. Since the device can be rooted/jailbroken (or backed up), anything the app writes in the clear is exposed. It’s the MASVS-STORAGE category of the OWASP standard and almost always produces findings.

flowchart TD
    APP["App"] --> SP["SharedPreferences / NSUserDefaults"]
    APP --> DB["SQLite / Realm"]
    APP --> FS["Files / cache"]
    APP --> SEC["Keystore / Keychain"]
    SP --> LEAK["Leak if cleartext"]
    DB --> LEAK
    FS --> LEAK
    SEC --> OK["OK if protection class is right"]
    LEAK --> BK["Backups / another app / root"]

The attacker who exploits insecure storage has some degree of access to the device or its copies:

  • Root/jailbreak: reads any file in the app’s container.
  • Backup: extracts data from adb backup (Android) or an iTunes/iCloud backup (iOS).
  • Another app: reads external storage or poorly permissioned directories.
  • Physical access: lost/stolen device without effective disk encryption.

What they want: session tokens and JWTs, passwords, API keys, PINs, encryption keys, and PII. The classic mistake is encrypting data but storing the key next to it.

Ventana de terminal
/data/data/<package>/
shared_prefs/*.xml # SharedPreferences (key-value, often cleartext)
databases/*.db # SQLite (app data)
files/ # internal files
cache/ # cache
# external storage (historically: readable by other apps with permission)
/sdcard/Android/data/<package>/
# the right place for secrets:
# Android Keystore -> hardware-backed keys (TEE/StrongBox)
Ventana de terminal
/var/mobile/Containers/Data/Application/<UUID>/
Library/Preferences/*.plist # NSUserDefaults (key-value, cleartext)
Documents/ Library/ tmp/ # files, SQLite, cache
# the right place for secrets:
# Keychain -> system encrypted store, with protection classes
Ventana de terminal
# with root or run-as (if the app is debuggable)
adb shell run-as com.target.app cat /data/data/com.target.app/shared_prefs/prefs.xml
adb shell "su -c 'ls -la /data/data/com.target.app/'"
# databases
adb pull /data/data/com.target.app/databases/app.db
sqlite3 app.db ".tables"
# backup without root (if allowBackup=true)
adb backup -f backup.ab -noapk com.target.app # extract with abe.jar
Ventana de terminal
# with jailbreak, SSH to the device, or Objection
objection -g com.target.app explore
ios keychain dump # dump the app's Keychain
ios nsuserdefaults get # NSUserDefaults (cleartext keys)
env # app container paths
Ventana de terminal
# in the app container, any format (prefs, SQLite, files, cache, logs)
grep -rniE 'token|password|secret|api[_-]?key|BEGIN|jwt|bearer' /data/data/com.target.app/
  • Session tokens / JWTs (see JWT), passwords, API keys, PINs.
  • Encryption keys stored next to the encrypted data (classic mistake).
  • PII, card data, messages, histories.
Ventana de terminal
# logs: the app writes sensitive data to logcat / NSLog
adb logcat | grep -i target
  • Keyboard cache and pasteboard (iOS), background screenshots (snapshot on minimise).
  • WebView cache, uncleared in-memory data.
  • Cloud backups (iCloud / Google Backup) that include sensitive data.
  • Logging/crash libraries (Crashlytics, Sentry) that capture sensitive parameters.

Testing against an app you own or have permission to test:

  • Map the container and dump shared_prefs/.plist, SQLite, and files; grep for cleartext secrets.
  • Dump the Keystore/Keychain and check whether secrets are where they belong, with the right protection class.
  • Test the backup: adb backup and, on iOS, an unencrypted backup with extraction tools.
  • Watch logs and pasteboard while using sensitive features (login, payment).
  • Check the crypto: if there’s encrypted data, look for the key in the same container or derive it with Frida by hooking the encryption.
  • Secrets in the secure store: Android Keystore / iOS Keychain (with the right protection class), never in SharedPreferences/NSUserDefaults/cleartext files.
  • Minimise: don’t store what you don’t need; short-lived, renewable tokens.
  • Correct encryption: don’t store the key next to the data; use non-extractable keys (hardware-backed). On Android, EncryptedSharedPreferences/SQLCipher; derive keys with the Keystore.
  • allowBackup=false (Android) or exclude sensitive data from the backup; Data Protection (iOS, WhenUnlocked).
  • Don’t log sensitive data; clear cache/pasteboard; protect the background capture (blank screen when backgrounding).
  • Locate the app’s data directories (Android/iOS)
  • Cleartext SharedPreferences / NSUserDefaults
  • SQLite/Realm databases with sensitive data
  • Files, cache, and external storage
  • Keystore/Keychain: are they used? right protection class?
  • Encryption keys stored next to the data
  • Leaks in logs, pasteboard, background screenshots, crash reports
  • Extractable backup (allowBackup / unencrypted backup)