MathanKumar Stalin
MathanKumar Stalin

Solution Engineer

System Engineer

DevOps Engineer

Ethical Hacker

Cyber Security

MathanKumar Stalin

Solution Engineer

System Engineer

DevOps Engineer

Ethical Hacker

Cyber Security

TryHackMe Writeup | SQ2: Box Office (Spoiler-Free)

This challenge from TryHackMe for Advent of Cyber 2026, starts with what looks like an ordinary video file and turns into a mix of binary patching, reverse engineering, and automated puzzle solving. Below is the methodology I used to solve it, with the final flag and exact solution sequence redacted so you can still complete the room yourself.

1. Initial Enumeration & Finding the Riddle

Whenever a CTF hands you a media file, running strings is a quick way to check for hidden metadata or appended payloads:

Bash

strings challenge.mp4

Scrolling through the output revealed a short riddle near the end, followed by a 64-byte hexadecimal string starting with 7f454c46.

In hex, 7f 45 4c 46 translates to \x7fELF—the magic bytes for a Linux executable. The riddle hinted at replacing the first 64 bytes of the video file with this hex string to reveal the executable hidden inside.

2. Patching the File Header

To convert the video into a runnable binary without wiping out the rest of the file, I made a working copy and used xxd and dd with conv=notrunc:

Bash

cp challenge.mp4 challenge_elf
echo -n "<64-byte-hex-header-from-strings>" | xxd -r -p | dd of=challenge_elf bs=1 count=64 conv=notrunc

After patching, I verified the file type and executed it:

Bash

file challenge_elf
chmod +x challenge_elf
./challenge_elf

file confirmed it was now a valid 64-bit ELF executable. Running it launched a terminal-based Sokoban-style puzzle (RANSOMMIT). The goal: push four crates (A, B, C, D) onto the letter tiles at the top of the board in ascending order from left to right to form the flag.

3. Reverse Engineering the Board

Because the board is tight and easy to deadlock by hand, I decided to extract the exact map layout from the binary and write a solver.

First, I checked the program headers with readelf:

Bash

readelf -l challenge_elf

This showed a single LOAD segment and an entry point near the very end of the file, meaning the actual executable code sits in the last few kilobytes after the video data.

Disassembling from the entry point with objdump revealed a small XOR decryption function that unpacks a 76×28 character grid from the end of the file using a simple coordinate-based key: (0x37 + 11*x + 29*y) & 0xff.

Using a quick Python one-liner, I decrypted that region directly from the binary:

Python

data = open("challenge_elf", "rb").read()[0x965176:0x9659c6]
for y in range(28):
    row = "".join(chr(data[y*76 + x] ^ ((0x37 + 0xb*x + 0x1d*y) & 0xff)) for x in range(76))
    print(row)

This printed the exact ASCII layout of the Sokoban walls, crates, player position, and target letter tiles.

4. Automating the Puzzle Solution

With the exact grid in hand, I wrote a Python Breadth-First Search (BFS) solver.

A naive step-by-step BFS explodes in state space with four crates, so I optimized it by:

  • Branching only on crate pushes (calculating all reachable player positions between pushes).
  • Pruning deadlocks (ignoring any push that traps a crate in a corner outside the target row).

The solver found a valid move sequence (around 200 moves). Rather than typing 200 arrow keys manually and risking a typo, I piped the ANSI arrow-key escape sequences (\x1b[A, \x1b[B, \x1b[C, \x1b[D) directly into the binary using Python’s subprocess module:

Python

import subprocess, time

moves = "<YOUR_SOLVER_OUTPUT>".split()
key_map = {"^": b"\x1b[A", "v": b"\x1b[B", "->": b"\x1b[C", "<-": b"\x1b[D"}

p = subprocess.Popen(["./challenge_elf"], stdin=subprocess.PIPE)
for move in moves:
    p.stdin.write(key_map[move])
    p.stdin.flush()
    time.sleep(0.02)

time.sleep(3)
p.terminate()

Watching the script play through the board automatically placed all four crates in ascending order on the top row, revealing the final flag.

Key Takeaways

  • Polyglot / disguised files: A file’s extension and header can be swapped to hide a completely different format; conv=notrunc in dd is essential when patching headers in place.
  • Static analysis saves time: Even when a binary is a playable game, inspecting its disassembly (readelf + objdump) lets you extract the underlying data cleanly.
  • Automate repetitive input: Pairing a state-space solver with subprocess eliminates human error on long terminal puzzles.
Related Posts
Write a comment