APKrypt
APKrypt
Description
Objective
Difficulty
Easy
Flag
HTB{3nj0y_y0ur_v1p_subscr1pt1on}
Release:
/release/APKrypt.zip
( b9913b674cb4a4977fa20398ce55aa64435b41cf7b1f306cc8b2df27a376c213 )
Notes
Android Emulator will perform much better on a native operating system (not a virtual
machine).
Challenge
Unzipping the APKrypt.zip file reveals the file APKrypt.apk . In order to run the
APKey.apk file, we have to set up an Android emulator. To achieve this, we are going to
use Android Studio IDE.
wget https://redirector.gvt1.com/edgedl/android/studio/ide-
zips/4.2.1.0/android-studio-ide-202.7351085-linux.tar.gz
tar xvzf android-studio-ide-202.7351085-linux.tar.gz
sh android-studio/bin/studio.sh
On the setup wizard we click OK , then we click on Next , and finally click on Finish .
Next, we wait for the Android Studio to download the components.
On the AVD Manager menu, click on the green "play" button to start the emulator.
Once the device is started, It should be looking like this.
Then, we install adb so we can communicate with it.
While the device is running, we can execute the following command to install the
application on the device.
Finally, from the device, we can locate and start application we just installed.
This is an application featuring a system that issues VIP tickets. Let's put a random code to
see the output.
The output is Wrong VIP code! . Let's reverse the APK file. Using d2j-dex2jar we can
create a JAR file, and then using JD-GUI we can read the source code of the APK file.
d2j-dex2jar APKrypt.apk
jd-gui
On the top left we choose the file icon and we select the JAR file we just created. Then we
click Open .
Reading the source code, we conclude that the VIP code (flag) is encrypted using AES.
In the MainActivity.java of the project we created earlier on android studio, we add the
following code to decrypt the flag, using the secrete key Dgu8Trf6Ge4Ki9Lb that is shown
above.
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Base64;
import android.util.Log;
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
decrypt();
} catch (Exception e) {
e.printStackTrace();
}
}
On the top right, we click on the green "play" button to start the application.
On the run tab, we can see the output of the execution.