Mobile - Red Light Green Light
Medium | 464 points | 86 solves
Description
You are stuck in a game of red light green light, to win you need to press the button when the light is green. Wait all you want, the light has never changed to green for me :(
Downloads
Solution
Decompile the .apk using an online decompiler.

Head over to sources -> com -> nahamcon2023 -> redlightgreenlight
and open up the MainActivity.java
file to find out what the app is doing.

The main logic of the app is in the checkLight()
function.

checklight()
It is also worth looking at the decrypt()
function in the Decrypt.java
file.

decrypt()
In summary, this is what the app is doing:
Get the decryption key using the Java native function
getKey()
Check if the light is red
If the light is red, the app will show that "You cannot move right now..."
If the light is not red, the app will decrypt the AES-encrypted image with the key from step 1 and display the decrypted image
The first thing I attempted was to look into the native getKey()
function and that function can be found in the following shared library file: resources\lib\x86_64\libredlightgreenlight.so

The decompilation is only a few lines of code but we will quickly see that the return value goes through a fastcall
before returning.

__fastcall
at line 46At this point I tried to use Frida to call this native function and to see the return value dynamically but unfortunately, I couldn't get Frida to attach to the app without crashing it.
Instead, I worked on modifying the .apk instead. Firstly, we need Apktool and the instructions on how to install it can be found here. Let's take a look again at the checkLight()
function.

checkLight()
Our goal is to modify line 33 and flip the predicate from if (!this.red)
to if (this.red)
.
The steps:
Using Apktool, we can decompile the .apk once again and get the smali files.
$ apktool d red_light_green_light.apk

Inside the decompiled folder, open up the AndroidManifest.xml file and change the
android:extractNativeLibs="false"
property totrue
. I am not sure why but if you skip this step, you will have issues installing the apk later.

Next, navigate to: red_light_green_light\smali\com\nahamcon2023\redlightgreenlight

Open up
MainActivity.smali
and what we are looking for is at line 115.

if (!this.red)
in smaliModify the predicate to
if-eqz
and rebuild the apk using Apktool
$ apktool b <folder_name> -o <output_apk_name>

Generate keystore for signing the .apk
keytool -genkey -v -keystore my.keystore -alias redlightks -sigalg MD5withRSA -keyalg RSA -keysize 2048 -validity 7300

Zipalign APK
zipalign.exe -v 4 <input_apk> <output_apk>

Sign APK
apksigner.bat sign --ks <keystore_name> <apk_to_sign>

Now we have successfully modified the .apk, launch our device in Android Studio and we can use adb to install the modified .apk (alternatively we can drag-and-drop the apk into the device but we won't be able to see the errors this way.)



Flag: flag{29b9edf8fd1e28ea8cd4faa37a6dbf25}
Last updated