This repository is intended to demonstrate how easy it is to produce a tampered version of an Android app using a decompiler.
This demo will require you to build an Android app and run multiple server applications on your machine. As such, you'll need to have the following installed on your machine:
- Android SDK
- .NET Core
- NodeJS
-
Build and start the
MoneyBankServer.Within the
MoneyBankServerdirectory:
dotnet run
-
Start an Android Virtual Device on your machine.
-
Install the App via Gradle.
From the
MoneyBankdirectory, run./gradlew installRelease -
Launch the Money Bank demo on the Android Virtual Device. You should be able to log in with the username "steve" and the password "password".
The ModifyMoneyBank directory within the repository contains a Gradle build that will build a modified version of a class from our app and use that modified class to build a modified version of the Money Bank app.
ModifyMoneyBank/src/main/java/com/preemptive/moneybank/api/RequestQueueSingleton.java contains code generated by a decompiler for the com.preemptive.moneybank.api.RequestQueueSingleton class, but modified in order to send HTTP request bodies to a command and control server.
The modifications made to the original decompiled code are marked with // BEGIN MODIFIED CODE and // END MODIFIED CODE.
The tampering process requires some initial setup on your machine.
- Create a
local.propertiesfile within theModifyMoneyBankdirectory and add the following properties:
APKSIGNER- A path to anapksignerexecutable on your machine.KEYSTORE- A path to an Android Debug Keystore on your machine.ANDROID_SDK_JAR- A path to an Android SDK Jar on your machine.
E.g.:
APKSIGNER=/Users/username/Library/Android/sdk/build-tools/29.0.0/apksigner
KEYSTORE=/Users/username/.android/debug.keystore
ANDROID_SDK_JAR=/Users/username/Library/Android/sdk/platforms/android-29/android.jar
-
Download a Dex2Jar zip and extract its contents to
ModifyMoneyBank/tools/dextools. Its.shand.batscripts should be directly withinModifyMoneyBank/tools/dextools. -
Copy the built Money Bank app to
ModifyMoneyBank/app.apk. It will reside inMoneyBank/build/outputs.
We are now ready to make a tampered version of our app.
From the ModifyMoneyBank directory, run ./gradlew resign.
This will run the following Gradle tasks:
unpackDex- Extract theclasses.dexfromapp.apk.undex- Use Dex2Jar to convert classes.dex into a JAR file containing Java classes.unpackClasses- Extract the classes from the jar produced byundex.extractVolley- Extract the classes.jar from the Volley Android Library in order to build the modified code.build- Compile the modified version ofcom.preemptive.moneybank.api.RequestQueueSingleton.replaceClass- Create a new JAR using the classes extracted byunpackClassesand the new class built bybuild.redex- Create a newclasses.dexfile using the new jar created byreplaceClass.unpackApk- Extract the files fromapp.apkother thanclasses.dexin order to produce a new APK.replaceDex- Create a new APK with the files unpacked byunpackApkand the DEX file created byredex.resign- Sign the new APK produced byreplaceDexusing a Debug key.
- Uninstall the original app from the Android Virtual Device and install the tampered app.
adb uninstall com.preemptive.moneybank
adb install ModifyMoneyBank/build/output-apk/app.apk
- Start the Command and Control Server.
From the SpyServer directory:
node endpoint.js
This will print information about HTTPS requests it receives to the console.
- Run the Money Bank application and log in with the usual credentials. Note that the Command and Control server has received and printed the body of the request.