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

Source: https://www.youtube.com/watch?v=m0XAPRAOJ8A
Recap page: https://rapidrecap.app/video/m0XAPRAOJ8A
Generated: 2025-09-15T17:02:57.514+00:00

---
## 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 check_data 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.

![Screenshot at 00:12: IDA Pro interface showing the disassembled assembly code for the "flagcasino" program, highlighting function calls and data structures.](https://ss.rapidrecap.app/screens/m0XAPRAOJ8A/00-00-12.png)

**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 `rand()` and `srand()` 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 `srand()` with the loop counter and then printing the output of `rand()`. This sequence of numbers is crucial for solving the challenge. The presenter then uses the `strings` 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 `srand()`, and the resulting random number is checked against a value derived from `check_data`. A Python script is developed to automate this process. The script parses the raw `check_data` 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{r4nd_1s_v3ry_pr3d1ct4bl3}.



### Program Analysis

- The "flagcasino" program is analyzed using IDA Pro, revealing its use of `rand()` and `srand()` functions, a loop structure, and a critical `check_data` array.

### Reverse Engineering Logic

- The video explains how the program's random number generation is deterministic based on the seed, allowing for prediction of outputs.

### Python Script Development

- A Python script is created to parse the `check_data`, build a lookup table (LUT), and map inputs to outputs.

### Flag Extraction

- The script iterates through possible inputs, uses the LUT to find the correct sequence, and ultimately extracts the flag "HTB{r4nd_1s_v3ry_pr3d1ct4bl3}".

![Screenshot at 00:01: Hex-rays logo displayed, indicating the software used for disassembly.](https://ss.rapidrecap.app/screens/m0XAPRAOJ8A/00-00-01.png)
![Screenshot at 00:12: The Hack The Box CTF interface is shown, displaying various "Reversing" challenges.](https://ss.rapidrecap.app/screens/m0XAPRAOJ8A/00-00-12.png)
![Screenshot at 00:34: The "FlagCasino" challenge overview is displayed, with an option to download the scenario file.](https://ss.rapidrecap.app/screens/m0XAPRAOJ8A/00-00-34.png)
![Screenshot at 00:37: A terminal window shows the "casino" executable running, displaying ASCII art and a prompt for bets.](https://ss.rapidrecap.app/screens/m0XAPRAOJ8A/00-00-37.png)
![Screenshot at 01:02: The output of file casino command, identifying it as an ELF 64-bit executable.](https://ss.rapidrecap.app/screens/m0XAPRAOJ8A/00-01-02.png)
![Screenshot at 01:07: The output of xxd casino \| less command, showing the hexadecimal dump of the binary.](https://ss.rapidrecap.app/screens/m0XAPRAOJ8A/00-01-07.png)
![Screenshot at 01:32: The program prompts the user to "PLEASE PLACE YOUR BETS \*\*\*".](https://ss.rapidrecap.app/screens/m0XAPRAOJ8A/00-01-32.png)
![Screenshot at 02:01: The output of strings casino \| less command, revealing strings used by the program.](https://ss.rapidrecap.app/screens/m0XAPRAOJ8A/00-02-01.png)
![Screenshot at 02:57: The IDA Pro interface is shown with the pseudocode of the main function.](https://ss.rapidrecap.app/screens/m0XAPRAOJ8A/00-02-57.png)
![Screenshot at 04:28: IDA Pro's hex view displays the check array with its hexadecimal values.](https://ss.rapidrecap.app/screens/m0XAPRAOJ8A/00-04-28.png)
