Overview
Intended two-stage solve:
- Pass a device-integrity check → the app provisions an encrypted secret into local storage.
- Read that secret from app-private storage (normally requires root or a debuggable process).
Environment
- Host: Kali-like Linux (
cipher@GHSTFCE) - Tooling:
adb,apktool,jadx,radare2,ghidra,frida17.21.0 (+frida-server), Android SDK build-tools,zipalign/apksigner - Physical device: Unisoc
Neon_Ray_Ultra_M, Android 13,user/release-keys,armeabi-v7a, bootloader locked — rooting ruled out entirely. - Emulator: Pixel 6 AVD, Android 16, x86_64,
google_apis(userdebug), full root viaadb root.
Recon
Step 1 — Confirm the target stack
Goal: Establish the APK’s package, activity, and stack.
| Property | Value |
|---|---|
| Target | SecureVault_v1.apk |
| Package | com.example.securevault |
| Main Activity | com.example.securevault.MainActivity |
| Stack | Flutter 3.35-era / Dart 3.13.4 AOT release snapshot, sqflite + PointyCastle |
Vulnerability Analysis
The six checks:
checkTestKeys()—Build.TAGScontainstest-keyscheckRootPackages()— Magisk/SuperSU package namescheckEmulator()—Build.FINGERPRINT/MODEL/BRAND/DEVICE/PRODUCT/HARDWARE/MANUFACTURERsubstring matching +ro.kernel.qemu == "1"checkDebuggableBuild()—Build.TYPEin{userdebug, eng}, tags containdev-keys/test-keys,ro.debuggable == "1", orro.secure == "0"signingCertSha256()— SHA-256 of the APK’s own signing certificatecheckSuBinary()—File.exists()on 8 classicsupaths
Exploitation
Step 2 — Rule out the native/AOT path (dead end)
Goal: Confirm the integrity signal is not the emulator’s lib*_emulation.so files probed via access()/faccessat().
Initial Frida + strace showed access()/faccessat() calls to emulator-only EGL/GLES libraries, correlating with bits in an observed fingerprint. Six suppression approaches were tried (hooking access/faccessat, caller-module classification, Java-layer Os.access/File.exists, property spoofs, /proc/*//sys/* redirects, string-patching libapp.so) — all failed or crashed the renderer.
Root cause: these access() calls are Flutter/Skia’s own GPU backend probing for an emulated GL driver — ordinary engine behavior unrelated to the integrity check. Blocking them crashes the renderer, and Java-layer hooking never touched them because they bypass Java entirely.
Step 3 — Decompile the Java/Kotlin layer
Goal: Recover the actual integrity check, which is easier than the Dart AOT snapshot.
No jadx/apktool/aapt2/r2 were preinstalled in the analysis sandbox, so:
curl -sL -o jadx.zip https://github.com/skylot/jadx/releases/download/v1.5.0/jadx-1.5.0.zip
unzip -q jadx.zip -d jadx_tool
./jadx_tool/bin/jadx -d jadx_out --no-res SecureVault_v1.apk
MainActivity.kt registers the securevault/rootcheck MethodChannel exposing the six checks above. This explained the mystery:
- Emulator fingerprint
00000011→checkEmulator()= 1 andcheckDebuggableBuild()= 1 (Pixel 6 AVD isuserdebugwithsdk_gphone/emulatorfingerprint). - Phone + re-signed debuggable APK → clean bitmask but still “Device compromised” →
signingCertSha256()returns the hash ofdebug.keystoreinstead of the release signer, failing Dart’s separate expected-hash gate.
Step 4 — Compute the real signing certificate hash
Goal: Confirm Dart compares against a binary constant, not a greppable string.
from androguard.core.apk import APK
import hashlib
a = APK('SecureVault_v1.apk')
for cert in a.get_certificates_der_v2():
print(hashlib.sha256(cert).hexdigest())
# → a4cb6936b9be0310fd7f0ae72f41a804b81f3272816e5323701bb50f83d67f7
This hash did not appear as an ASCII string in libapp.so — confirming the Dart-side comparison is against a binary constant in the AOT data pool.
Step 5 — Confirm no pre-embedded secret
Goal: Verify the secret is only written at runtime.
find assets -type f
# → only fonts, shaders, AssetManifest, NOTICES, dexopt profiles
No bundled ciphertext — the secret materializes at runtime, written by a Dart function (_decryptFlag / writeSecret) into a sqflite database at databases/vault.db:
CREATE TABLE vault (id INTEGER PRIMARY KEY, secret TEXT)
Step 6 — Dynamically verify the check returns
Goal: Observe real return values with a diagnostic (non-overriding) Frida hook.
// sv_rootcheck_log.js
Java.perform(function () {
var MA = Java.use('com.example.securevault.MainActivity');
[
'checkTestKeys',
'checkRootPackages',
'checkEmulator',
'checkDebuggableBuild',
'checkSuBinary',
'signingCertSha256',
].forEach(function (m) {
var orig = MA[m];
orig.implementation = function () {
var ret = orig.call(this);
console.log('[rootcheck] ' + m + ' -> ' + ret);
return ret;
};
});
});
frida -U -f com.example.securevault -l sv_rootcheck_log.js --no-pause
Observed output:
[rootcheck] checkRootPackages -> 0
[rootcheck] checkSuBinary -> 0
[rootcheck] checkEmulator -> 1
[rootcheck] checkDebuggableBuild -> 1
[rootcheck] checkTestKeys -> 0
(signingCertSha256 only prints after the bitmask clears — a final gate.)
Step 7 — Bypass the integrity check
Goal: Neutralize the five environmental checks so the bitmask clears.
// sv_rootcheck_bypass.js
Java.perform(function () {
var MA = Java.use('com.example.securevault.MainActivity');
[
'checkTestKeys',
'checkRootPackages',
'checkEmulator',
'checkDebuggableBuild',
'checkSuBinary',
].forEach(function (m) {
MA[m].implementation = function () {
return '0';
};
});
});
frida -U -f com.example.securevault -l sv_rootcheck_bypass.js --no-pause
Result: fingerprint dropped to 00000000 and “Secret provisioned” was displayed. signingCertSha256() was left unforced — the original unmodified APK’s real signer naturally satisfied Dart’s expected-hash comparison, so only the five environmental booleans needed neutralizing.
Step 8 — Extract the secret
Goal: Pull the provisioned sqflite database from the rooted emulator.
adb root
adb shell ls -la /data/data/com.example.securevault/
# databases/ <- now present
# files/
adb pull /data/data/com.example.securevault/databases/vault.db .
sqlite3 vault.db "select * from vault;"
╭────┬────────────────────────────────────────────────╮
│ id │ secret │
╞════╪═══════════════════════════════════════════════════╡
│ 1 │ safctf{REDACTED} │
╰────┴────────────────────────────────────────────────╯
Interpretation: run-as was unnecessary — full root on the AVD let us read the app-private data directory directly.
Flag
safctf{REDACTED}
Read from vault.db (vault.secret) after bypassing the integrity check.
Lessons / Takeaways
- A tool-compatibility gap (Blutter vs. Dart 3.13.4) initially pushed analysis toward the harder native/AOT path, when the actual target was one
jadx -daway the whole time. - Syscalls that correlate with emulator-only state are not proof of causation — verify a suspected check is actually read by the code path you’re trying to influence, by hooking the app’s own classes/methods directly.
- A diagnostic (log-only) hook before any override confirms the bit mapping empirically instead of relying on inference.
- Full root on the AVD made final extraction trivial —
run-asrequires the app to be debuggable, not the device to be rooted.
Mitigations
- Perform integrity checks in native code (NDK) with anti-tampering, not solely in Java/Kotlin hookable from Frida.
- Bind the signing-certificate check and environmental checks together so bypassing one invalidates the other.
- Use root detection with multiple, independently verified signals and randomize check timing.
- Encrypt locally stored secrets with a key derived from hardware-backed keystore material, not provisioned in plaintext.
Techniques
References
- jadx: https://github.com/skylot/jadx
- androguard: https://github.com/androguard/androguard
- Frida: https://frida.re/

