HackTheBox Flag Casino | Reverse Engineering Writeups

HackTheBox Flag Casino | Reverse Engineering Writeups

Mission Brief: Your team has breached a derelict gambling hall from the pre-war era. Amidst the dust and skeletal remains of former patrons, the automated staff has reactivated. A robotic dealer offers you a game of chance. The prize? Funding for the mission. The catch? The house always wins unless you can reverse engineer the odds.

Objective: Analyze the provided binary, identify the flaw in its random number generation, and extract the flag.

Phase 1: Initial Reconnaissance

Before diving into the assembly, we observe the binary’s behavior in a controlled environment. We run the executable to gauge the user interaction.

$ ./robo_casino
[ ** WELCOME TO ROBO CASINO **]
, ,
(\____/)
(_oo_)
(O)
__||__ \)
[]/______\[] /
/ \______/ \/
/ /__\
(\ /____\
---------------------
[*** PLEASE PLACE YOUR BETS ***]
> 5
[ * INCORRECT * ]
[ *** ACTIVATING SECURITY SYSTEM - PLEASE VACATE *** ]

Observation: The program prompts for input (bets). Upon entering a value (5), it immediately fails and terminates. This suggests a classic password check or value comparison logic hidden beneath the casino theme.

If all 0x1c entries match correctly, we complete the process successfully.

int32_t main(int32_t argc, char** argv, char** envp)
puts(str: "[ ** WELCOME TO ROBO CASINO **]")
puts(str: " , ,\n (\____/)\n (_oo_)\n (O)\n __…")
puts(str: "[*** PLEASE PLACE YOUR BETS ***]")
int32_t i
= 0
while (true) {
if (i u> 0x1c) {
puts(str: "[ ** HOUSE BALANCE $0 - PLEASE COME BACK LATER ** ]")
return 0
}
printf(format: "> ")
char inp
if (__isoc99_scanf(format: " %c", &inp) != 1) {
exit(status: 0xffffffff)
noreturn
}
srand(x: sx.d(inp))
if (rand() != check[sx.q(i)]) {
break
}
puts(str: "[ * CORRECT *]")
i = i + 1
}
puts(str: "[ * INCORRECT * ]")
puts(str: "[ *** ACTIVATING SECURITY SYSTEM - PLEASE VACATE *** ]")
exit(status: 0xfffffffe)

rand() is a predictable random number generator—calling srand(x) followed by rand() will always produce the same result for a given seed. So, we can script a solution to uncover the mapping.

By using the ctypes library in Python, we can easily call C functions like srand() and rand() directly from our Python code to assist in this process.

Next, we’ll use the pwntools library to interact with the binary. This will allow us to open the binary and extract each target integer that we need to compare against during the process. By automating this with pwntools, we can streamline the extraction and verification of the necessary values.

In the for loop, to index into the check array, multiply the current index by 4 to account for the size of each 32-bit integer. Then, use e.u32() (from pwntools) to extract each 32-bit integer from the binary data. This allows us to read the correct values from the check array during each iteration.

Full solution python script:

import ctypes

libc = ctypes.CDLL('libc.so.6')mapping = {}
for i in range(255):
libc.srand(i)
mapping[libc.rand()] = chr(i)flag = ""
from pwn import *
casino = ELF("./casino", checksec=False)
for b in range(29):
val = casino.u32(casino.sym["check"] + b * 4)
flag += mapping[val]
print(flag)

You can also watch:

0 comments

Leave a comment

Our Best Pick of Cyber Security Notes

Cyber Security Certification Notes
Certified Security Blue Team Level 2 (BTL2) Study Notes (Unofficial)

Cyber Security Certification Notes

Cyber Security Study Guides
The Kali Linux Pentesting Cheat Sheet

Cyber Security Study Guides

AI & ML Study Guides
Master AI for Content Creation, Business & Marketing

AI & ML Study Guides

IT Study Guides
The Definitive Networking Cheat Sheet (Tools)

IT Study Guides

Cybersecurity · Offensive & Defensive · Practitioner-First

Stop reading docs.
Start thinking like an attacker.

Field-ready notes, methodology breakdowns, and certification cheat sheets built by a practitioner for practitioners.

62K+YouTube Subscribers
20K+Web Visitors
4K+Students and Professionals Using The Notes

What's in the vault

Two tiers.
One clear mission.

Whether you're just getting started or deep in the trenches, there's a tier built for where you are right now. Free notes cover the essentials — premium unlocks the full playbook.

Free Access

The essentials,
on the house.

A curated library of beginner and intermediate notes you can access right now — no signup, no friction.

  • Introductory walkthroughs on core concepts
  • Tool overviews: Nmap, Burp Suite, Metasploit & more
  • Selected HTB writeup summaries
  • Foundational blue team methodology notes
  • YouTube companion write-ups
Start Reading Free
Premium

The full
practitioner playbook.

Every note, every cheat sheet, every methodology breakdown — structured the way a senior analyst actually thinks.

  • Full OSCP, CPTS, OSWE, HTB CDSA prep DISCOUNTS
  • Complete HTB machine writeups (Guardian, Expressway & more)
  • AI Red Teaming tooling comparison notes
  • SOC analyst learning roadmaps & playbooks
  • Threat intelligence methodology guides
  • Malware analysis case studies (NotPetya & more)
  • New content added continuously
Become a Member →

Coverage

What you'll actually use.

Notes built around real engagements, real exam objectives, and real SOC workflows — not a rehash of vendor documentation.

#Penetration TestingOSCP · CPTS · HTB
#Web App SecurityOSWE · Bug Bounty
#SOC & Blue TeamCDSA · SIEM · IR
#Threat IntelligenceTAXII · YARA · MITRE
#Malware AnalysisReverse Engineering
#AI Red TeamingGarak · PyRIT · LLM Sec
#Network SecurityActive Directory · Pivoting
#Tooling & AutomationScripts · Integrations

Cert Coverage

OSCP CPTS OSWE HTB CDSA CEH CompTIA Sec+ eJPT

The author

Motasem Hamdan

I'm a cybersecurity practitioner, technical writer, and content creator who got tired of resources that treat readers like beginners forever.

My notes are built the way I wish someone had built them when I was grinding through certs and CTFs — methodology-first, practitioner-grade, and structured for how analysts actually think on the job.

Over 62,000 people on YouTube follow along. Thousands more read on the site every month. These aren't notes for passing an exam and forgetting everything — they're references you'll keep coming back to.

motasem_notes — practitioner.sh
whoami
motasem_hamdan — cybersec_practitioner

cat expertise.txt
offensive_security: advanced
blue_team_soc:      advanced
threat_intel:       advanced
technical_writing:  practitioner-grade

ls content/
htb_writeups/  cert_cheatsheets/
ai_red_team/   soc_methodology/
threat_intel/  malware_analysis/

cat philosophy.txt
"teach how to think,
 not just what to type."

_

Membership

One subscription.
Everything unlocked.

Skip the hours lost searching fragmented resources. One membership gives you the full library, updated continuously as the threat landscape evolves.

Free $0 forever
  • Foundational notes library
  • Selected HTB summaries
  • YouTube companion write-ups
  • Tool overview guides
Start Reading
Store : One-Time Pay What You Want
  • Buy individual cheat sheets
  • Downloadable PDFs & guides
  • No recurring commitment
  • Yours to keep permanently
Browse Store

FAQ

Good questions.


The free tier has solid foundational content. Premium notes are written for intermediate-to-advanced practitioners — they assume you know the basics and want to go deeper. If you're grinding toward OSCP or working in a SOC, you'll feel right at home.
Continuously. New walkthroughs, methodology updates, and cheat sheets drop regularly — aligned with new HTB machines, cert updates, and emerging threat topics. As a member, you get access to everything as it lands.
Yes, absolutely. Membership is managed through Buy Me a Coffee — you can cancel any time directly from your account. No long-term lock-in, no awkward cancellation flows.
The membership gives you ongoing access to the full library for a monthly fee. The store lets you buy individual resources once and own them permanently — good if you just need one specific cert pack.
Definitely. Head to @MotasemHamdan on YouTube — over 62K subscribers and a large back-catalogue of walkthroughs, tool demos, and methodology breakdowns. Best way to see if the teaching style clicks for you before committing to anything.