CyberKavach QuestCon Series: The Upside Down

 

The Upside Down

Welcome to the CyberKavach QuestCon reverse engineering series! This post will walk you through solving “The Upside Down,” a CTF challenge that will test your static analysis, binary patching, and code understanding skills.

Author: Sarthak Warale

Challenge Details

  • Category: Reverse Engineering

  • Difficulty: Medium

  • Description: The true prize is buried in the binary's Upside Down. Your objective is to reverse engineer and patch a stripped Linux ELF binary that mimics the classic 2048 game. Simply reaching the 2048 tile doesn't provide the real flag—the binary is hiding it behind an impossible win condition.

  • Flag Format: questCON{…}


Overview

The challenge provides a stripped Linux binary named easygame. Running it feels like playing 2048, but reaching 2048 prints only a bait message. The actual flag logic exists but can never trigger through normal gameplay.


Tools Used

  • Ghidra (for decompilation and patching)

  • Python 3 (for optional static flag extraction script)

  • Bash


Step-by-Step Walkthrough

1. Initial Reconnaissance

Start by granting execution permissions and running the game.


2. Analyzing the Binary in Ghidra

  • Create a new project and import easygame.

  • Use default analysis options.

  • Open the main function from the Functions tree and inspect the decompiler output.

A key segment is found: a guarded flag-printing block only runs when score meets a specific threshold and certain anti-debug logic is not tripped.


3. Locating the Win Condition

The comparison checks if the score is a nearly impossible value. In assembly, this appears as cmp edi, 0x5f5e0ff.


4. Patching Method 1: Lower the Required Score

  • In Ghidra, right-click the cmp edi, 0x5f5e0ff instruction and select "Patch Instruction."

  • Change the immediate value (e.g., 0x5f5e0ff) to 0x1. Now just one move is required.

  • Export the modified program: File > Export Program > Format: Binary (tick "Export User Byte Modifications"), save as easygame_patched.


5. Patching Method 2: Remove the Conditional Jump

  • Identify the conditional jump (jl failpath) after the comparison.

  • In Ghidra listing, right-click the instruction, patch it to NOP NOP to always fall through.


6. Test the Patch

Make the file executable again and run it.

chmod +x easygame_patched

./easygame_patched


After the first move, the patched flag logic triggers and the true flag is revealed:

questCON{yoursecretflaghere}

You didn’t just play—you hacked your way to the flag!


7. Alternative: Static Flag Extraction

Don't want to patch or run the binary? Extract the encflag and keybytes arrays from the binary via Ghidra, then re-implement their decryption routine in Python:


encflag = [...]

key = [...]

flagbytes = []

for i, b in enumerate(encflag):

    decrypted = b ^ key[i % len(key)] ^ 0xFF

    flagbytes.append(decrypted)

print(bytes(flagbytes).decode())


Running the script outputs the flag, bypassing the binary entirely.


Lessons Learned

  • Reverse engineering binaries often requires analyzing both logic and data.

  • Impossible in-game conditions can be bypassed with patching.

  • Static extraction can save time when dynamic analysis is hard or risky.


Congratulations if you navigated the Upside Down and emerged with the flag!


Comments

Popular posts from this blog

CyberKavach QuestCon Series: Upside-Down Vault

From Open Networks to Safe Systems: How Firewalls Block the Hacker’s Doorway

CyberKavach QuestCon Series: VecNet