Signing the APK
Decompiling, Modifying, and Signing Android Apps
APKTOOL - Decompile
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.apkIf errors persist, consider using alternative decompilers like jadx or androguard.
APKTOOL - Compile
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.
Creating a New Keystore
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 365The 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.apkThe aligned file outfile.apk can now be signed.
Signing the App
Sign the APK with the following command:
$ apksigner sign --ks ~/android-app-hack.keystore new-debug.apkThis creates a new signed application new-debug.apk, ready for installation.
New Version - Steps
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.apkModify the SMALI content /
AndroidManifest.xml.Rebuild the APK:
$ java -jar apktool_2.5.0.jar b org.secuso.privacyfriendlydicer_8Navigate to the
distdirectory:$ cd distAlign the APK:
$ zipalign 4 app-debug.apk new-debug.apkSign the APK:
$ apksigner sign --ks ~/tools/keystore/android-app-hack.keystore new-debug.apkInstall the APK:
$ adb install -r new-debug.apk
Blue Box Key Vulnerability
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.
Last updated
Was this helpful?