MASTG-DEMO-0106: Extracting Sensitive Data from Cipher.doFinal via Frida Hooking
Download MASTG-DEMO-0106 APK Open MASTG-DEMO-0106 Folder Build MASTG-DEMO-0106 APK
Sample¶
This sample encrypts and decrypts a sensitive API key using AES/GCM via the Android KeyStore. The app does not implement any runtime hook detection mechanisms. On the contrary, Detecting Frida hooks and terminating the application on response demonstrates a runtime hook detection mechanism.
Note
This is a series of correlated tests.
- This test is a failed test (failed defence/successful attack) against a data exfiltration attack.
- Detecting Frida hooks and terminating the application on response 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 | |
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
- Stop the script by pressing
Ctrl+Cand/orqto quit the Frida CLI
1 2 3 4 5 6 7 8 9 10 11 | |
1 2 | |
Observation¶
The output contains all instances of Cipher.doFinal() method calls found at runtime. A backtrace is also provided to help identify the location in the code. The first doFinal call reveals the sensitive API key in plaintext as the input parameter during encryption and the second call reveals it as the return value during decryption.
| output.json | |
|---|---|
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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 | |
Evaluation¶
The test fails because the hook executes successfully and the sensitive API key sk-OWASP-MAS-SuperSecretKey-1234567890 is extracted in plaintext from the Cipher.doFinal() calls. The app lacks runtime integrity verification, allowing instrumentation tools to intercept cryptographic operations without any defensive response.