📖
CTF Wiki
  • 🚩Arne's CTF Writeups!
  • 2025
    • TUCTF
      • Forensics - Security Rocks
    • San Diego CTF
      • Crypto - RustSA
      • Misc - Triglot
  • 2024
    • Lexington CTF
      • Misc - a little bit of tomcroppery
    • Imaginary CTF
      • Web - Journal
    • Space Heroes CTF
      • Web - Antikythera
    • HTB Cyber Apocalypse
      • Pwn - Sound of Silence
      • Misc - MultiDigilingual
  • 2023
    • NahamConCTF
      • Mobile - Red Light Green Light
    • BucketCTF
      • Rev - Schematic
      • Rev - Random security
    • HTB Cyber Apocalypse
      • Rev - Cave System
      • Rev - Somewhat Linear
      • Pwn - Void
  • 2022
    • DownUnderCTF 2022
      • Cloud - Jimmy Builds a Kite
    • Ã¥ngstromCTF 2022
      • Pwn - really obnoxious problem
      • Pwn - whatsmyname
    • Engineer CTF
      • Misc - Not really random
      • Misc - Broken Pieces
    • KnightCTF 2022
    • HTB CTF: Dirty Money
      • Forensics - Perseverance
  • 2021
    • MetaCTF CyberGames 2021
    • HTB - Cyber Santa
      • RE - Infiltration
    • Securebug CTF Thor 2021
      • Web - Tricks 1
      • Web - Tricks 2
      • RE - Hidden in Plain Sight
    • TFC CTF 2021
      • RE - Crackity
      • Pwn - Jumpy
      • Misc - Weird Friend
    • K3RN3L CTF 2021
      • Crypto - Pascal RSA
    • DamCTF 2021
      • Misc - library-of-babel
      • Pwn - cookie-monster
    • Killer Queen CTF 2021
      • Pwn - Tweety Birb
      • Forensics - Tippy Tappies
      • Pwn - I want to break free
    • BuckeyeCTF 2021
      • Web - pay2win
      • Misc - USB Exfiltration
Powered by GitBook
On this page
  • Description
  • Downloads
  • Solution
  1. 2023
  2. NahamConCTF

Mobile - Red Light Green Light

Medium | 464 points | 86 solves

Last updated 11 months ago

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.

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

In summary, this is what the app is doing:

  1. Get the decryption key using the Java native function getKey()

  2. Check if the light is red

  3. If the light is red, the app will show that "You cannot move right now..."

  4. 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.

At 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.

Our goal is to modify line 33 and flip the predicate from if (!this.red) to if (this.red).

The steps:

  1. Using Apktool, we can decompile the .apk once again and get the smali files.

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

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

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

  1. Modify the predicate to if-eqz and rebuild the apk using Apktool

$ apktool b <folder_name> -o <output_apk_name>
  1. Generate keystore for signing the .apk

keytool -genkey -v -keystore my.keystore -alias redlightks -sigalg MD5withRSA -keyalg RSA -keysize 2048 -validity 7300
  1. Zipalign APK

zipalign.exe -v 4 <input_apk> <output_apk>
  1. 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}

4MB
red_light_green_light.zip
archive
Decompile .apk
Decompiled .java file from .dex format
checklight()
decrypt()
The native function as seen in IDA
__fastcall at line 46
checkLight()
Decompile using Apktool
Inside AndroidManifest.xml
smali files
if (!this.red) in smali
Rebuild .apk
Keystore generation
zipalignment
Sign APK
Install apk using adb
redlightgreenlight apk installed
flag