MASTG-DEMO-0018: Uses of Broken Encryption Algorithms in CommonCrypto with r2
Download MASTG-DEMO-0018 IPA Open MASTG-DEMO-0018 Folder Build MASTG-DEMO-0018 IPA
Sample¶
The snippet below shows sample code that uses the insecure 3DES encryption algorithm when encrypting data with CommonCrypto's CCCrypt function. 3DES is considered weak due to its shorter effective key length and vulnerabilities to specific attacks.
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 | |
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 | |
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 | |
Steps¶
- Unzip the app package and locate the main binary file ( Exploring the App Package), which in this case is
./Payload/MASTestApp.app/MASTestApp. - Open the app binary with radare2 (iOS) with the
-ioption to run this script.
| cccrypt.r2 | |
|---|---|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | |
| run.sh | |
|---|---|
1 2 | |
Observation¶
The output contains the disassembled code of the function using CCCrypt.
| output.asm | |
|---|---|
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 | |
Evaluation¶
Inspect the disassembled code to identify the use of insecure algorithms.
In CommonCryptor.h, you can find the definition of the CCCrypt function:
CCCryptorStatus CCCrypt(
CCOperation op, /* kCCEncrypt, etc. */
CCAlgorithm alg, /* kCCAlgorithmAES128, etc. */
CCOptions options, /* kCCOptionPKCS7Padding, etc. */
const void *key,
size_t keyLength,
const void *iv, /* optional initialization vector */
const void *dataIn, /* optional per op and alg */
size_t dataInLength,
void *dataOut, /* data RETURNED here */
size_t dataOutAvailable,
size_t *dataOutMoved);
There you will also find the alg and the op:
/*!
@enum CCAlgorithm
@abstract Encryption algorithms implemented by this module.
@constant kCCAlgorithmAES128 Advanced Encryption Standard, 128-bit block
@constant kCCAlgorithmDES Data Encryption Standard
@constant kCCAlgorithm3DES Triple-DES, three key, EDE configuration
@constant kCCAlgorithmCAST CAST
@constant kCCAlgorithmRC4 RC4 stream cipher
*/
enum {
kCCAlgorithmAES128 = 0,
kCCAlgorithmDES,
kCCAlgorithm3DES,
kCCAlgorithmCAST,
kCCAlgorithmRC4,
kCCAlgorithmRC2
};
typedef uint32_t CCAlgorithm;
/*!
@enum CCOperation
@abstract Operations that an CCCryptor can perform.
@constant kCCEncrypt Symmetric encryption.
@constant kCCDecrypt Symmetric decryption.
*/
enum {
kCCEncrypt = 0,
kCCDecrypt,
};
With this information, we can now inspect the disassembled code, and we'll see that the 3DES algorithm (kCCAlgorithm3DES) can be found by its numeric value 2 in the second argument of the CCCrypt function (w1). The CCCrypt function is called with a padding option of PKCS7, no initialization vector, and a key of 24 bytes:
| evaluation.txt | |
|---|---|
1 2 3 4 5 6 7 8 9 | |
The test fails because the 3DES encryption algorithm was found in the code.
Note
Using artificial intelligence, we're able to decompile the disassembled code and review it. The output is a human-readable version of the assembly code. The AI-decompiled code may not be perfect and might contain errors, but in this case, it clearly shows the use of CCCrypt and the associated algorithm.