This tool is intended for educational and research purposes only.
Titanium SDK is a JavaScript framework for creating native mobile apps. One of the features it offers, specifically for Android, is asset encryption. With this functionality enabled, all code and assets used from the JS side are encrypted during the build process, remaining that way in the compiled app, and are only decrypted in memory at application startup.
This project automates the extraction of the encryption key, which in such apps is embedded in a native library named libti.cloak.so, and the IV from the app's AssetCryptImpl class.
The assets are encrypted during the build process using AES-128 in CBC mode. A 16-byte long key and equally long IV are randomly generated, and used to encrypt each file.
Then, the key is XORed with the IV, and inserted into a prebuilt libti.cloak.so at offset 0x2008, with some scrambling. The reconstructed structure definition is located in key_block.rs.
The IV is inserted into the AssetCryptImpl class, as literal values in a byte[].
- The prebuilt library (last updated in 2020) contains a 64 byte long structure at the aforementioned offset
0x2008, which is also exported as a symbol namedKEY_BLOCK, - The key block is filled with random data,
- The key is split into 4 equally-sized parts,
- The parts are written into the structure, with parts 1, 3 and 4 being written at offsets
0x01,0x0Fand0x1E, respectively, - The second part is written into the region at a random offset,
- The offset of the second part is written at offset
0x3E.
Extract the libti.cloak.so library from the target app using any tool (apktool, zip, WinRAR, ...). Run the tool as follows:
$ libcloak-key-ripper native <path/to/libti.cloak.so> <path/to/output_key_xored.bin>The output is the encryption key XORed with the IV, so to both get the original key and to use it, the IV is required.
Disassemble the AssetCryptImpl class to get a .smali file. Run the tool as follows:
$ libcloak-key-ripper smali <path/to/AssetCryptImpl.smali> <path/to/output_iv.bin>XOR the files together. Run the tool as follows:
$ libcloak-key-ripper xor <path/to/output_key_xored.bin> <path/to/output_iv.bin> <path/to/output_key.bin>Use any software (e.g. OpenSSL) with AES-128-CBC to decrypt the assets, using the resulting key and the salt value as the IV.
Example usage with OpenSSL:
$ openssl aes-128-cbc -d \
-K "$(xxd -p path/to/output_key.bin)" \
-iv "$(xxd -p path/to/output_iv.bin)" \
-in path/to/encrypted_asset.ext.bin \
-out path/to/decrypted_asset.ext