Everything Is Open Source If You Can Reverse Engineer (Hack With Me)

Quick Overview

Reverse engineering the "flagcasino" program from Hack The Box requires understanding its assembly code, specifically how it uses the rand() and srand() functions to generate random numbers. By analyzing the program's logic and the data structures it uses, one can write a Python script to reconstruct the look-up table (LUT) and extract the flag.

Key Points: The "flagcasino" program uses the rand() and srand() functions to generate random numbers, which are critical for determining the correct input. IDA Pro is used to disassemble the "flagcasino" binary, revealing the assembly code and program flow. The program's logic involves a loop that iterates 256 times, seeding rand() with the loop counter and then printing the result. A lookup table (LUT) is constructed by mapping specific input values to their corresponding random outputs. A Python script is developed to parse the checkdata array, extract the relevant byte values, and reconstruct the LUT. By using the constructed LUT, the script can determine the correct input sequence to satisfy the program's random number generation and ultimately reveal the flag.

Context: This video demonstrates the process of reverse engineering a Capture The Flag (CTF) challenge, specifically the "flagcasino" program. The presenter guides viewers through analyzing the binary using IDA Pro to understand its functionality, particularly its use of random number generation. The goal is to reverse the process and determine the correct input to obtain the flag.

Detailed Analysis

The video begins by explaining the concept of reverse engineering and its importance in CTF challenges. The presenter then downloads the "flagcasino" binary from Hack The Box and proceeds to analyze it using IDA Pro. The disassembly reveals that the program uses the and functions, which are standard C library functions for pseudo-random number generation. The core logic involves a loop that iterates from 0 to 255, seeding with the loop counter and then printing the output of . This sequence of numbers is crucial for solving the challenge. The presenter then uses the command to identify potentially useful strings within the binary. To decipher the program's logic, the presenter uses IDA Pro's pseudocode view, which translates the assembly code into a more readable C-like representation. This pseudocode shows a loop where user input is taken, then used to seed , and the resulting random number is checked against a value derived from . A Python script is developed to automate this process. The script parses the raw from IDA Pro, converts it into a usable format, and builds a lookup table (LUT) that maps input values to their corresponding random outputs. Finally, the script iterates through the possible inputs, uses the LUT to predict the program's random number output, and determines the correct sequence of inputs that satisfies the program's conditions, ultimately revealing the flag: HTB{r4nd1sv3rypr3d1ct4bl3}.

Raw markdown version of this recap