Insecure Local Storage
Mobile apps frequently store sensitive data locally without proper encryption. This guide covers identifying and exploiting insecure data storage on both Android and iOS platforms.
OWASP M9: Insecure Data Storage
Android Storage Locations
The interesting question here is not whether a file can be read but what the read cost the
attacker. Mode bits decide that: a file readable by other apps, or reachable through a backup, is
exposed without root, while one behind the app uid needs the device compromised first. The
allowBackup
flag is the same question in reverse — an allowBackup finding is weaker where device backup is
encrypted and keyed to the user, so check how backup is configured before grading it.
Read these as a ladder, not a list. Preferences, databases, files and the cache share one default — the app's uid and file mode — which keeps a co-resident app out but not root, a debuggable build or a backup. The rungs differ in content and lifetime: a preference keeps a token until it is overwritten, the cache can be evicted, a database keeps deleted rows until the file is vacuumed. A finding is a value in a place, never the path alone.
SharedPreferences
XML files storing key-value pairs. Often contain tokens, credentials, and settings:
# Location on device
/data/data/<package>/shared_prefs/
# List all SharedPreferences files
adb shell run-as com.target.app ls shared_prefs/
# Read preferences (rooted device)
adb shell cat /data/data/com.target.app/shared_prefs/*.xml
# Using Frida to dump SharedPreferences
Java.perform(function() {
var context = Java.use('android.app.ActivityThread').currentApplication().getApplicationContext();
var prefs = context.getSharedPreferences("app_prefs", 0);
var all = prefs.getAll();
var it = all.entrySet().iterator();
while (it.hasNext()) {
var entry = it.next();
console.log(entry.getKey() + ": " + entry.getValue());
}
});
The default is the directory's, so the read needs the app uid: root, or
run-as
on a debuggable build. A release build answers with a denial, and a debug build is not the shipped
artifact, so the access path belongs in the severity. The finding is a credential-valued key a server
still accepts, plus its survival of logout; the file is not one.
SQLite Databases
Local databases often store user data, messages, and cached content:
# Database location
/data/data/<package>/databases/
# Pull database
adb shell run-as com.target.app cat databases/app.db > app.db
# Or on rooted device
adb pull /data/data/com.target.app/databases/app.db
# Analyze with SQLite
sqlite3 app.db
.tables
.schema users
SELECT * FROM users;
# Look for sensitive data
SELECT * FROM sqlite_master WHERE type='table';
A database inherits that protection, so the questions become format and content. A file that
file
reports as SQLite 3 is readable in place; one wrapped by SQLCipher or an app-level envelope is not.
Read the write-ahead log too, since the newest rows land there, and grep column names that look like
credentials before dumping every table.
Internal Files
# Internal storage location
/data/data/<package>/files/
/data/data/<package>/cache/
# List all files
adb shell run-as com.target.app find . -type f
# Search for sensitive patterns
adb shell run-as com.target.app grep -rE "password|token|key|secret" files/
# Check file permissions
adb shell run-as com.target.app ls -la files/
files/
holds exports, downloads and hand-rolled token caches;
cache/
is the same directory under an eviction contract the platform enforces without asking. That contract
moves the grade — a cached response cleared on logout is smaller than a refresh token that outlives
the account change. Anything in
no_backup/
is excluded from backup by construction.
External Storage
Scope Depends on the Path
/sdcard/Android/data/<package>/
private to the app that owns it, so another app on the device cannot read it. The risk survives
elsewhere: files written to shared storage outside that directory, media in the shared
collections, and anything the app leaves readable in a device backup. Before scoping, the app's
own external directory was readable by any app holding storage permission.
# External storage locations
/sdcard/
/sdcard/Android/data/<package>/
# Search for app data
adb shell find /sdcard -name "*target*" 2>/dev/null
# Check for exported files
adb shell ls -la /sdcard/Android/data/com.target.app/
Readable without root is narrower than a path list suggests, and the boundary moved between releases,
so it is not restated here. What holds is that
adb shell
runs as the shell uid, not the app uid: a directory the shell can list is not proof another app can
read it. Record the uid. What survives scoping is shared space — files written outside the app's
directory, media rows it inserted.
iOS Storage Locations
iOS answers with two attributes instead of mode bits. A keychain item carries an accessibility class — whether it is readable while the device is locked, and whether it migrates to a new device — and a file carries a protection class. Both decide whether a plaintext read on a jailbroken device is a finding or a working control: a value readable only while unlocked and marked non-migrating is materially stronger than a plaintext file, and a value in a database the app encrypts under a key held in the keystore sits at a different risk again.
Keychain
iOS secure storage. Can be dumped on jailbroken devices:
# Using keychain-dumper (on device)
./keychain-dumper
# Using Objection
objection -g com.target.app explore
ios keychain dump
# Using Frida
ObjC.schedule(ObjC.mainQueue, function() {
var query = ObjC.classes.NSMutableDictionary.alloc().init();
query.setObject_forKey_(ObjC.classes.kSecClassGenericPassword, "class");
query.setObject_forKey_(ObjC.classes.kSecMatchLimitAll, "limit");
query.setObject_forKey_(true, "returnData");
var result = ObjC.classes.SecItemCopyMatching(query, null);
console.log(result);
});
The dump is only as interesting as the attributes. The accessibility class says whether a value is
readable while the device is locked and whether it is device-restricted; the access group says who
else can read it. An
AfterFirstUnlock
item that is not ThisDeviceOnly
is extractable from a backup and usable elsewhere; a
WhenUnlockedThisDeviceOnly
item shared only with the app's extensions is close to a control.
NSUserDefaults / Plist Files
# Plist locations
/var/mobile/Containers/Data/Application/<UUID>/Library/Preferences/
# Read plist files
plutil -p /path/to/com.target.app.plist
# Using Objection
ios plist cat com.target.app.plist
# Frida to dump NSUserDefaults (iOS, no Java bridge involved)
ObjC.schedule(ObjC.mainQueue, function() {
var defaults = ObjC.classes.NSUserDefaults.standardUserDefaults();
var dict = defaults.dictionaryRepresentation();
console.log(dict.toString());
});Defaults are a plist in the preferences directory, under the file's protection class. The property that settles the grade is migration: a value restored to a replacement device under the same bundle identifier is not device-bound. A registration identifier is not a finding at any class.
SQLite & Core Data
# Database locations
/var/mobile/Containers/Data/Application/<UUID>/Documents/
/var/mobile/Containers/Data/Application/<UUID>/Library/
# Find all databases
find /var/mobile/Containers/Data/Application/<UUID> -name "*.sqlite" -o -name "*.db"
# Copy to computer
scp root@device:/path/to/database.sqlite .
# Analyze
sqlite3 database.sqlite
.tables
SELECT * FROM sensitive_table;Core Data is a SQLite store with an object graph in front of it, and it can move large binary values into a sibling blob directory, so a search for database files alone under-reports. A store whose pages do not parse as SQLite is encrypted, and the grade then turns on where the key lives: the keystore is a control, a preferences file beside the database is not.
Cache & Cookies
# Cache locations
/var/mobile/Containers/Data/Application/<UUID>/Library/Caches/
# Cookies database
/var/mobile/Containers/Data/Application/<UUID>/Library/Cookies/Cookies.binarycookies
# Using Objection
ios cookies get
# Check for sensitive cached data
find /var/mobile/Containers/Data/Application/<UUID>/Library/Caches -type f -exec file {} \;The cache directory and the cookie store are where a session outlives its screen: a cookie the server accepts without device binding is a credential like any other, and the app-switcher snapshot is a further copy of the last screen. Grade all three by the login and logout capture.
Backup as the Weak Path
A private directory is private on the device it was written to. Both platforms also move app data off
the device, and there the sandbox stops being an argument: the reader needs the backup, not the
handset. On Android,
allowBackup
decides whether the app's data joins the platform backup transport, and the rules file declared
through
fullBackupContent
or its successor — the attribute name follows the target API level — decides which paths are
included. An allowBackup finding is therefore a statement about configuration, and the evidence is
the extracted file rather than the flag.
# Android: what the app's data actually contains
adb backup -f target.ab -noapk com.target.app
# The stream is a 24-byte header followed by zlib
dd if=target.ab bs=24 skip=1 | zlib-flate -uncompress > target.tar
tar -tf target.tar
# Which paths are included or excluded, from the merged manifest
grep -E "allowBackup|fullBackupContent|dataExtractionRules" merged/AndroidManifest.xml
# iOS: a local backup, whose encryption state decides what it carries
idevicebackup2 backup --full ./backupdir
plutil -p ./backupdir/Manifest.plist
On iOS, a local backup made with encryption carries keychain items and one made without it does not,
and both carry the container unless the app set
NSURLIsExcludedFromBackupKey;
an iCloud backup adds the question of who holds the account. Because the accessibility class decides
migration, a backup finding and a keychain finding are often one finding reported once.
Automated Analysis
Android - Objection Commands
# Explore the app
objection -g com.target.app explore
# List files in app directory
env
android root disable # If needed
# SQLite commands
sqlite connect app.db
sqlite execute query SELECT * FROM users;
# Monitor file system access
android filesystem watch /data/data/com.target.app/iOS - Objection Commands
# Connect to app
objection -g com.target.app explore
# Environment info
env
# Dump keychain
ios keychain dump
# Get cookies
ios cookies get
# List bundles
ios bundles list
# Dump NSUserDefaults
ios nsuserdefaults getSecurity Comparison
Read this table by column rather than by row. The risk of a storage class is set by what protects it and by who can reach it, and the same value can move between rows depending on where its key lives. Data written by an analytics or ads SDK into its own container belongs to that SDK, so the exposure appears in the app while the fix may sit outside the app owner's control; and values created only by the test account deserve a caveat, because they may not reflect what a real user's session stores.
| Storage | Encrypted | Accessible | Risk |
|---|---|---|---|
| Android Keystore | Yes (hardware-backed) | Root + app context | Low |
| iOS Keychain | Yes (SEP) | Jailbreak + tools | Low |
| SharedPreferences | No (plaintext XML) | Root or backup | Medium |
| NSUserDefaults | No (plaintext plist) | Jailbreak or backup | Medium |
| SQLite | No (unless SQLCipher) | Root/jailbreak | Medium |
| Android app-private files | No by default | App uid, root or debuggable run-as | Medium |
| iOS app container files | Protection class | Jailbreak, or an unlocked device | Medium |
| Device backup | Depends on backup config | Whoever holds the backup | Depends on content |
| External Storage | No | Owner app, shell or backup | Medium |
Sensitive Data to Find
Capture each surface before login, after login and after logout. That sequence is what separates a cache from a retained credential, and it is the difference between a medium and a high on the same path. A cache with no reachable consequence — a thumbnail, say — should be graded against what else the same path reaches rather than on its own, and a session identifier the server revokes, which reveals nothing offline, is not equivalent to a stored password or a long-lived refresh token.
Authentication Data
- Usernames and passwords
- Session tokens / JWT
- API keys
- OAuth tokens
- Remember me tokens
Personal Information
- Names, emails, phone numbers
- Credit card data
- Health information
- Location history
- Private messages
Cryptographic Material
- Private keys
- Encryption keys
- Certificates
- Encryption IVs
Application Data
- Backend URLs
- Debug flags
- Feature toggles
- Internal IDs
Reporting Findings
Practice Lab
Write a value to SharedPreferences from your own app, extract it through adb backup or run-as on a debuggable build, and quote what came out — done when the file is located, its contents quoted, and the risk stated as what an attacker holding the device or the archive would need. The finding is the extracted file, never the allowBackup flag on its own.
Evidence to Capture
Device and OS: Platform, version, patch level and root or jailbreak state.
Application identity: Bundle or package name, version and build, with the APK or IPA hash.
Path and uid: The absolute file path and the uid that read it.
Redacted content: The key and value structure with the sensitive portion masked, plus a record count where the volume matters.
Protection attributes: Android file mode or iOS file protection class, and for Keychain items the accessibility attribute and access group.
Before and after: The same artefact captured before login, after login and after logout.
Likely False Positives
- Root or jailbreak requirement: A sandbox file readable only on an instrumented device.
- Server-issued opaque reference: A revocable identifier that reveals nothing offline.
- Encrypted under a keystore-backed key: A value encrypted under a key held in the platform keystore.
- Test-account data: A value that only the test account stores.
- Third-party SDK directories: Data in an analytics or ads SDK container.
- Cache with no reachable consequence: A cache that leads nowhere else.
- Backup flag with encrypted backup: An allowBackup finding under encrypted device backup.
Testing Checklist
Android surfaces
- ☐ SharedPreferences, databases, files and cache enumerated
- ☐ External storage and media store locations reviewed
- ☐ Keystore usage identified and checked for actual keys
- ☐ Logcat, clipboard and keyboard cache checked
- ☐ allowBackup and backup rules reviewed
iOS surfaces
- ☐ Documents, Library and Caches enumerated
- ☐ Keychain items classified by accessibility and access group
- ☐ NSUserDefaults, plists and Core Data reviewed
- ☐ Shared app-group containers checked
- ☐ App-switcher snapshot and pasteboard behaviour tested
What is stored
- ☐ Authentication and refresh tokens searched for
- ☐ Personal-data fields recorded with counts
- ☐ Cryptographic material, keys and IVs recorded as paths
- ☐ Session state after logout verified empty
Evidence
- ☐ Absolute paths and hashes recorded
- ☐ Redacted snippets retained alongside the originals
- ☐ Device and root state recorded for every artefact
- ☐ Reproduction steps recorded so the client can repeat without the lab device
Remediation & Defense
Client storage
- • Use the platform keystore for credentials instead of preferences, defaults or plain files
- • Encrypt local databases that hold personal data, with the key in the platform keystore
- • Clear tokens and caches on logout and on account change
- • Disable backup of sensitive files, or apply an explicit exclusion rule
- • Keep logs and the clipboard free of tokens and personal data
iOS specifics
- • Set an explicit file protection class on files holding personal data
- • Choose keychain accessibility attributes that match the feature
- • Exclude derived caches from backup
Server
- • Bind tokens to a device so a copied token cannot be replayed elsewhere
- • Shorten access-token lifetime and support per-device revocation
- • Treat a replayed token from an unexpected device as an incident signal
Detection
- • Add a release-build check that fails on plaintext secret patterns
- • Review storage schema changes for newly added personal-data fields
- • Alert on token use from a device fingerprint that changed