MASTG-DEMO-0058: Use of Insecure ECB Block Mode in KeyGenParameterSpec
Download MASTG-DEMO-0058 APK Open MASTG-DEMO-0058 Folder Build MASTG-DEMO-0058 APK
Sample¶
The code below generates symmetric encryption keys meant to be stored in the Android KeyStore, but it does so using the ECB block mode, which is considered broken due to practical known-plaintext attacks and is disallowed by NIST for data encryption. The method used to set the block modes is KeyGenParameterSpec.Builder#setBlockModes(...)
:
public KeyGenParameterSpec.Builder setBlockModes (String... blockModes)
Current versions of Android prohibit the usage of keys with for ECB in some cases. For example, it is not possible to use the key to encrypt data by the default. Nevertheless, there are some case, where ECB can still be used:
- Decrypt data
- Encrypt data with a key given
setRandomizedEncryptionRequired
is set tofalse
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 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
|
Steps¶
- Install the app on a device ( Installing Apps)
- Make sure you have Frida for Android installed on your machine and the frida-server running on the device
- Run
run.sh
to spawn the app with Frida - Click the Start button
- Stop the script by pressing
Ctrl+C
and/orq
to quit the Frida CLI
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
1 2 |
|
Observation¶
The output shows all instances of block modes mode that were found at runtime. A backtrace is also provided to help identify the location in the code.
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 117 118 119 120 121 122 |
|
Evaluation¶
The method setBlockModes
has now been called three times with ECB as one of the block modes.
The test fails, as key used with these KeyGenParameterSpec
can now be used used to insecurely encrypt data.
You can automatically evaluate the output using tools like jq
as demonstrated in evaluation.sh
.
evaluate.sh | |
---|---|
1 2 3 4 5 6 7 8 9 |
|
See Broken Symmetric Encryption Modes for more information.