For demo, debug version of DIVA (Damn insecure and vulnerable App) is used as the target Android App and Kali Linux is used as the tooling platform.
Download debug version of DIVA
- Visit the DIVA download page at DIVA download page and go to the section “Where can I get Diva?”
- Capture the download link and download the file by wget.
Then, extract “diva-beta.tar.gz”
tar xvzf diva-beta.tar.gz
What is APK?
- Android Package Kit (APK) is the package file format used by the Android operating system for distribution and installation of mobile apps and middleware. It is a type of archive file, specifically in zip format packages.
- But, the containing files can’t be just simply unzipped to obtain their original forms.
- classes.dex is the Dalvik (virtual machine in Google’s Android operating system) Bytecode of the APK file. dex2jar could be used to convert Dalvik Bytecode (DEX) to Java Bytecode (JAR). JD-GUI could be used to display Java source codes with a friendly GUI.
- apktool could be used to decode resources (e.g. xml files) within APK file to nearly original forms.
But, for ease of reverse-engineering (decompiling/editing) & recompiling of android application binaries within a single user-interface, APK Studio will be used. It is a cross-platform IDE with a friendly IDE like layout, with a code editor which supports syntax highlighting for Android SMALI (*.smali) code files.
Convert the APK into Java source code for detail review
- Extract the classes.dex from APK
unzip diva-beta.apk classes.dex
- Convert Dalvik Bytecode (DEX) into Java Bytecode (JAR)
- (Skip this step, if JD-GUI has been installed already) Download JD-GUI installation package and install it
dpkg -i jd-gui_1.4.0-0_all.deb
- Open classes-dex2jar.jar by JD-GUI
java -jar /opt/jd-gui/jd-gui.jar /root/classes-dex2jar.jar
Decode APK resources and SMALI code editing (decompile -> edit -> recompile)
- (Skip this step, if APK Studio has been installed already)
Install the android adb
sudo apt-get install android-tools-adb
Download the source of APK Studio from APK studio official website
Change the download executable “apkstudio-d49d3de-linux.run” and run
chmod +x apkstudio-d49d3de-linux.run
- Open APK Studio and open the APK file
- Review and edit the XML and SMALI code
(Sign and export APK will not be discussed here, that should be simple.)
- Converted Java source code is good for understanding the detail program structure (assume code obfuscation is not implemented)
- SMALI code is good for quick edit (by making reference to Java source code)
Thanks for reading!