How To Reverse Engineer An Android Application

Very first rule of the security is to never trust the security on the client-side in context of Android mobile app. The Client-side is not an environment we control and thus we should not rely on it by hard-coding or storing secrets that can disrupt our system. So the best way to secure your apps and do not getting caught by developers and hackers is to reverse engineer the application by yourself and fix the issues if possible.

 

Many Android developers fail to realize that the Android app they build can be easily reverse engineered. If you are one of them developers who think hard-coding secret keys or even storing it in gradle file will prevent it from going into the hands of hackers or other developers, you are wrong.


So, let’s get started. For reverse engineering an application, we would need a few things beforehand —

  • Java Decompiler Tool (I used JD-JUI in this article) to view the decompiled code.
  • dex2jar utility 
  • APK of the application.

Basic understanding of the Android app.

STEP-1: We would need the APK of the application we want to reverse-engineering. There are many ways to do that but a simple way that install the APK Extractor app from google play store on your device. Open APK Extractor app and select the application from the list inside the application. Once done, open File Explorer and go to the ExtractedApks folder present in the Internal Storage directory. There, you will find the .apk file. Copy that .apk file to your system and proceed with the STEP-2.

STEP-2: Once you have .apk file we will reverse it know and   view the code. For that,  rename .apk to .zip and  Extract the zip file

Here, we will rename our {app}.apk file to {app}.zip and extract it.

Inside the extracted folder, we will find the classes.dex file which contains the application code. A DEX file is Zipped Dalvik Executable(.dex) file which contains the compiled code and runs on the Android platform. DEX files consist of the following components:

  • File Header
  • String Table
  • Class List
  • Field Table
  • Method Table
  • Class Definition Table
  • Field List
  • Method List
  • Code Header
  • Local Variable List

For further information on .dex files, refer to the official Android documentation.

STEP-3: Now, we will use the classes.dex file we took from the APK zip file and convert it to JAR. For that, we require ‘dex2jar’ open-source tool which is available on sourceforge or github. Download the latest available zip file and extract it.

STEP-4: Copy the extracted classes.dex file which is we find it in STEP-2  and paste it inside the ‘dex2jar-x.x’ directory.

STEP-5: Open Terminal on your machine and go to the ‘dex2jar-x.x’ directory.  Now we will run the command -

d2j-dex2jar.bat classes.dex

This will convert the classes.dex file to a classes-dex2jar.jar file which we can view using any decompiler Tool.

STEP-6: We will use JD-JUI which is a simple Java decompiler tool. You can get it from java-decompiler.github.io. Download and extract the zip. Run the jd-gui.exe and open the classes-dex2jar.jar file and Voila! We reverse-engineered the application!!

In some cases, it is required to remove the code obfuscation, then you will get the source code.

Comments

Popular posts from this blog

Exploiting a Web Server - Using msfvenom generated PHP Web Payload

Automate SQL Injection Exploitation with SqlMap - DVWA

How To Imitate (Replicate) pbcopy And pbpaste Commands On Linux