MASTG-DEMO-0107: Detecting Frida hooks and terminating the application on response
Download MASTG-DEMO-0107 APK Open MASTG-DEMO-0107 Folder Build MASTG-DEMO-0107 APK
Sample¶
This sample encrypts and decrypts a sensitive API key using AES/GCM via the Android KeyStore. Unlike the unprotected variant in Extracting Sensitive Data from Cipher.doFinal via Frida Hooking, this version includes a runtime hook detection mechanism that reads /proc/self/maps to check for the presence of Frida-related libraries (e.g., frida-agent, frida-gadget). If detected, the app terminates the process immediately via Process.killProcess() before any cryptographic operations are performed.
Note
This is a series of correlated tests.
- Extracting Sensitive Data from Cipher.doFinal via Frida Hooking is a failed test (failed defence/successful attack) against a data exfiltration attack.
- This test is a successful test (successful defense/failed attack) against the attack of Extracting Sensitive Data from Cipher.doFinal via Frida Hooking.
- Bypassing Frida Detection in /proc/self/maps to Extract Sensitive Data is a failed test (failed defence/successful attack) against the defenses of Detecting Frida hooks and terminating the application on response by using a more "complex" attack.
| MastgTest.kt | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | |
Steps¶
- Install the app on a device ( Installing Apps)
- Make sure you have Frooky installed on your machine and the frida-server running on the device
- Run
run.shto spawn the app with Frida - Click the Start button
- Observe that the app terminates before the hooks can capture any data
1 2 3 4 5 6 7 8 9 10 11 | |
1 2 | |
Observation¶
The output contains no instances of Cipher method calls found at runtime. The app terminated before any hooks could capture data.
| output.json | |
|---|---|
1 | |
Evaluation¶
The test passes because the hooking attempt fails due to the app's defensive response. The app detects the Frida agent by scanning /proc/self/maps for entries containing "frida" or "gadget" and terminates the process via Process.killProcess(). The process terminates before Cipher.doFinal() hooks execute, so no sensitive data is extracted.
Note
Even if the test case passes, it might still be possible to bypass the app's defensive response. For example, an attacker could hook the detectHooking() method itself or lower level APIs such as the file reading APIs to hide Frida from the process memory map. Bypassing Frida Detection in /proc/self/maps to Extract Sensitive Data demonstrates such a bypass. Detection of Reverse Engineering Tools and Runtime Integrity Verification describe such challenges.