To decompile an APK, you can use the apktool command:
$ apktool d <apk file>
If you encounter problems, try decompiling with the -r parameter, which skips the resource files:
$ apktool d -r game_test.apk
If errors persist, consider using alternative decompilers like jadx or androguard.
After making modifications, you can rebuild the app:
$ apktool b game_test/
Ensure you provide the directory path and not the APK file when building.
To sign the APK, you need to create a keystore. Use the following command:
$ keytool -genkey -v -keystore ~/android-app-hack.keystore -alias alias_name -keyalg RSA -keysize 2048 -validity 365
The alias name can be any identifier you choose. It identifies the correct certificate within the keystore, which can hold multiple certificates.
Before signing the APK, align the file using zipalign to ensure all uncompressed data start with a 4-byte alignment. This reduces the RAM required by the application:
$ zipalign 4 app-debug.apk outfile.apk
The aligned file outfile.apk can now be signed.
Sign the APK with the following command:
$ apksigner sign --ks ~/android-app-hack.keystore new-debug.apk
This creates a new signed application new-debug.apk, ready for installation.
Here is a summary of all commands in the new version of android systems 11,12:
-
Decompile the APK:
$ java -jar apktool_2.5.0.jar d org.secuso.privacyfriendlydicer_8.apk -
Modify the SMALI content /
AndroidManifest.xml. -
Rebuild the APK:
$ java -jar apktool_2.5.0.jar b org.secuso.privacyfriendlydicer_8 -
Navigate to the
distdirectory:$ cd dist -
Align the APK:
$ zipalign 4 app-debug.apk new-debug.apk -
Sign the APK:
$ apksigner sign --ks ~/tools/keystore/android-app-hack.keystore new-debug.apk -
Install the APK:
$ adb install -r new-debug.apk
To exploit the Blue Box key vulnerability:
- Add
classez.dexto the APK. - Use a hex editor (like
ghex) and search forclassez.dex. - Replace
zwiths. - Now the APK will have two
classes.dexfiles. - If the vulnerability exists, the APK will validate and accept the latest added
classes.dexfrom the attacker.
This vulnerability allows attackers to inject malicious code into an APK by adding an additional classes.dex file and manipulating its name.