--- name: android-crypto-keystore description: Audit Android cryptography and AndroidKeyStore usage — weak algorithms (DES/RC4/ECB/MD5/SHA1), hardcoded/static keys and IVs, insecure Random, missing authenticated encryption, and keystore misuse (no auth-binding, no hardware backing). Tier 1. Use when the app does local crypto. Aligns to OWASP MASTG MASVS-CRYPTO. --- # Android Cryptography & Keystore Review Find broken crypto and keystore misuse that make "encrypted" data decryptable or forgeable. ## Trigger phrases `weak crypto, ecb, des, rc4, md5, hardcoded key, static iv, insecure random, securerandom, androidkeystore, keystore misuse, setuserauthenticationrequired` ## Method 1. **Static grep** of decompiled code: ``` grep -rniE "DES|RC4|ECB|MD5|SHA1|Cipher.getInstance|IvParameterSpec|SecretKeySpec|SecureRandom|Random\(" app_java/ ``` Flag: `Cipher.getInstance("AES/ECB/...")`, DES/3DES/RC4, MD5/SHA1 for integrity, hardcoded keys/IVs, static `IvParameterSpec`, `java.util.Random` for secrets. 2. **Runtime crypto trace** (recover keys/IVs/plaintext): - `frida -U -f -l tracer-cipher.js --no-pause` — hook `Cipher`/`SecretKeySpec`/`IvParameterSpec` to dump key material and plaintext at runtime (see `android-frida-objection-instrumentation`). 3. **Keystore review:** - Are keys generated in `AndroidKeyStore` vs stored in prefs/files/code? - `setUserAuthenticationRequired(true)` for sensitive keys? `setInvalidatedByBiometricEnrollment(true)`? StrongBox/hardware backing? - Hook keystore APIs with Frida to see whether key material is derivable/exportable in app memory. ## Modern / rare techniques - **[RARE] Auth-bound key not actually used:** a keystore key marked auth-required but the operation never uses it to decrypt real data → ties to `android-biometric-bypass` (the biometric gate is cosmetic). - **Static/predictable IV with CBC** → identical plaintext leaks / chosen-ciphertext issues; missing GCM/HMAC → malleable ciphertext. - **Key derived in-app** for EncryptedSharedPreferences/SQLCipher → recover it at runtime and decrypt the store (chain `android-insecure-storage`). ## Bypass / evasion When keys live only in memory at use-time, dump them with a Frida `Cipher` hook or `fridump` rather than relying on static recovery. ## Escalation / chaining Decryptable at-rest data, forgeable tokens, broken integrity → feeds `android-insecure-storage` (decrypt the store) and `android-biometric-bypass` (unused auth-bound key); recovered keys may unlock backend data. ## Backend & tooling Preferred Kali path (native Kali / WSL+Kali / Kali-SSH / Kali-MCP / HexStrike). Needs the user's device/emulator (frida-server) + Kali tooling (jadx/Frida). Windows-local last resort. See `zazy-orchestrator`. ## Verification (background, before reporting) Confirm the weakness is exploitable, not merely present — recover a key/IV and actually decrypt data, or show the auth-bound key is bypassable — before marking CONFIRMED. A weak-algorithm string alone is a lower-confidence finding; prove impact where feasible. ## Evidence The crypto call site / keystore config, the recovered key/IV (redacted) or decrypted data, and impact. Remediation: AES-GCM (or AES-CBC+HMAC); random per-message IV; keys in hardware-backed AndroidKeyStore, auth-bound and invalidated on new biometric enrollment; `SecureRandom` for all secrets.