Listen to this Post

Introduction:
Mobile app integrity is under constant assault from root access, hooking frameworks (LSPosed, Zygisk), and custom ROMs that bypass standard security controls. A recently open-sourced repository provides detection techniques for these threats, giving developers and red teamers alike a powerful arsenal to test and harden Android applications against advanced tampering.
Learning Objectives:
- Implement runtime root detection using file-based and process-based heuristics.
- Detect hooking frameworks (LSPosed, Xposed, Frida) and Zygisk injection.
- Identify custom ROMs and system integrity violations via build properties and SELinux state.
You Should Know:
- Detecting Root, Zygisk, and LSPosed with Native Code
The open-source repository (https://lnkd.in/gdEi5HxS) includes methods to check for common root indicators and hooking frameworks. Below is an extended implementation guide combining Linux/Android commands and C++ native detection.
Step‑by‑step guide – Root & Zygisk detection:
- Check for common root binaries and packages (run on device via ADB or within app):
adb shell su -c "ls /data/local/tmp/ /system/bin/su /system/xbin/su /sbin/su" pm list packages | grep -E "magisk|supersu|kernelsu"
-
Detect Magisk/Zygisk by checking for mount namespaces and process maps:
Look for Magisk daemon ps -A | grep magiskd Check Zygisk injection cat /proc/self/mounts | grep zygisk
3. Implement native C++ detection (compile with NDK):
bool isRootDetected() {
FILE fp = popen("which su", "r");
if (fp) { fclose(fp); return true; }
// Check build tags
char prop[bash];
__system_property_get("ro.build.tags", prop);
if (strstr(prop, "test-keys") != nullptr) return true;
return false;
}
- Detect LSPosed by scanning for its package and Xposed bridge:
List installed Xposed modules pm list packages | grep -i "lsposed|de.robv.android.xposed" Check runtime properties getprop ro.dalvik.vm.native.bridge
Windows-side analysis (for reverse engineering APKs):
Use `apkanalyzer` (Android SDK) to inspect manifest and native libs:
apkanalyzer manifest print app.apk | findstr "READ_LOGS" apkanalyzer files list app.apk | findstr ".so"
2. Detecting Custom ROMs and System Tampering
Custom ROMs (LineageOS, crDroid, Pixel Experience) often change build fingerprints and SELinux policies. Use the following detection logic.
Step‑by‑step guide – ROM detection:
- Collect build properties via `adb` or `Build` class:
adb shell getprop ro.build.display.id adb shell getprop ro.build.version.incremental adb shell getprop ro.product.name
-
Compare against known stock fingerprints (example Python script):
import subprocess props = subprocess.check_output(["adb", "shell", "getprop"]).decode() if "lineage" in props.lower() or "crDroid" in props: print("Custom ROM detected") -
Check SELinux status – permissive mode often indicates tampering:
adb shell getenforce Should be "Enforcing" on stock
4. Verify bootloader lock state:
adb shell "su -c 'cat /proc/cmdline | grep verifiedbootstate'"
If `orange` or `yellow`, device is unlocked.
5. For in-app detection (Java/Kotlin) :
fun isCustomRom(): Boolean {
val buildTags = Build.TAGS
val buildBrand = Build.BRAND
return buildTags.contains("test-keys") || buildBrand.lowercase() == "generic"
}
3. Hooking Framework Detection via Memory Scanning
Advanced anti-tampering requires detecting Frida, Objection, and Xposed at runtime.
Step‑by‑step – Frida detection (Linux/Android):
1. Check for Frida server ports:
netstat -an | grep -E "27042|27043" lsof -i :27042
2. Scan /proc for Frida artifacts:
grep -r "frida" /proc//maps 2>/dev/null
- Use native signal handling to detect breakpoints (C++):
include <signal.h> void sigill_handler(int sig) { // Frida often triggers illegal instruction exit(1); } signal(SIGILL, sigill_handler);
4. Detect Xposed by checking for `de.robv.android.xposed` classloader:
try {
Class.forName("de.robv.android.xposed.XposedBridge");
// Hooked
} catch (ClassNotFoundException e) { / clean / }
Windows-side (for analyzing mobile app traffic) : Use Burp Suite or mitmproxy to detect API calls that bypass certificate pinning after hooking.
4. Mitigation and Hardening Techniques for Developers
Once you’ve identified detection gaps, implement these countermeasures.
Step‑by‑step – Hardening your app:
- Obfuscate native detection code using LLVM obfuscator (Obfuscator-LLVM):
Compile with control flow flattening clang -mllvm -fla -mllvm -sub test.c -o libtest.so
2. Implement integrity checks on the DEX file:
Compute hash of classes.dex sha256sum app.apk Compare at runtime
- Use SafetyNet Attestation API (Google Play Services) for hardware-backed integrity:
SafetyNet.getClient(context).attest(nonce, apiKey)
4. Add runtime self-integrity checks (C++):
bool checkCodeIntegrity() {
// Read /proc/self/maps and verify loaded libraries
// against known hashes
}
- For cloud backend – enforce API request signing with a rotating secret derived from device attestation.
5. Testing Your Detections with Red Team Tools
Use the same open-source repository to simulate attacks and validate your detections.
Step‑by‑step – Red team simulation (Linux host with Android device):
- Install Magisk with Zygisk on a test device, then enable LSPosed.
2. Use Frida to hook detection functions:
frida -U -f com.your.app -l bypass.js
Example `bypass.js`:
Java.perform(function() {
var RootDetector = Java.use("com.your.app.RootDetector");
RootDetector.isRooted.implementation = function() { return false; };
});
- Run the open-source detection test suite (from the repo):
git clone https://github.com/example/root-hook-detector actual repo from link cd root-hook-detector ./run_tests.sh --device emulator-5554
-
Check for false positives – ensure your detection doesn’t flag legitimate custom ROM users incorrectly.
-
Automate with Appium for continuous integrity testing in CI/CD.
-
API Security and Cloud Hardening for Tampered Clients
If root/hooking bypasses client checks, your backend must detect anomalies.
Step‑by‑step – Backend hardening:
1. Implement device fingerprinting (Linux/Node.js example):
const fingerprint = crypto.createHash('sha256')
.update(req.headers['user-agent'] + req.ip + req.headers['accept-language'])
.digest('hex');
- Validate attestation tokens from SafetyNet or Play Integrity API:
On server, verify JWT signature curl -X POST https://www.googleapis.com/androidcheck/v1/attestations/verify?key=YOUR_API_KEY
-
Monitor for API abuse – high request rates from same fingerprint may indicate scripted bypass.
-
Use rate limiting and behavioral analytics (e.g., fail2ban for APIs):
Install fail2ban and configure an API jail sudo apt install fail2ban sudo nano /etc/fail2ban/jail.local
What Undercode Say:
- Key Takeaway 1: Open-source detection methods are double-edged – they empower defenders but also give attackers a blueprint. Use them to patch gaps before they are weaponized.
- Key Takeaway 2: No single technique catches all tampering; layered detection combining native code, server-side attestation, and behavioral monitoring is essential for production apps.
The repository shared by Govind Sharma is a goldmine for mobile security engineers. However, relying solely on client-side detection is futile – determined attackers will always bypass it. The real value lies in using these techniques to raise the cost of tampering and shifting trust to server-side verification. Developers must also consider usability: overly aggressive root detection can alienate power users and custom ROM enthusiasts. A balanced approach – warn, log, but allow graceful degradation – often works better than hard failures.
Prediction:
As root and hooking frameworks become more stealthy (e.g., KernelSU, Dobby), open-source detection will shift toward hardware-backed attestation (Android StrongBox, TEE). Within 18 months, we’ll see widespread adoption of server-driven integrity checks using zero-knowledge proofs, making client-side root detection largely obsolete. Meanwhile, the cat-and-mouse game will intensify on ARM TrustZone and hypervisor-based anti-tampering.
▶️ Related Video (82% Match):
🎯Let’s Practice For Free:
IT/Security Reporter URL:
Reported By: Apkunpacker If – Hackers Feeds
Extra Hub: Undercode MoN
Basic Verification: Pass ✅


