12. Gateway interface - Tomcat CGI

`CVE-2019-0232` is a critical security issue that could result in remote code execution. This vulnerability affects Windows systems that have the `enableCmdLineArguments` feature enabled. An attacker can exploit this vulnerability by exploiting a command injection flaw resulting from a Tomcat CGI Servlet input validation error, thus allowing them to execute arbitrary commands on the affected system. Versions `9.0.0.M1` to `9.0.17`, `8.5.0` to `8.5.39`, and `7.0.0` to `7.0.93` of Tomcat are affected.

CGI Servlet is vital component of apache tomcat that enables webservers to communicate with external applications beyond tomcat JVM Ext. apps are typically CGI scripts written in langs like perl,python,bash. CGI Servlet function is to receive requests from browser and forward them to CGI scripts for processing

CGI Servlet is a program that runs on a webserver - to support execution of external app that confirm to CGI specification. Middleware.

Utilized for several reasons but there's some big disadvantages

Advantages Disadvantages
It is simple and effective for generating dynamic web content. Incurs overhead by having to load programs into memory for each request.
Use any programming language that can read from standard input and write to standard output. Cannot easily cache data in memory between page requests.
Can reuse existing code and avoid writing new code. It reduces the server's performance and consumes a lot of processing time.

enableCmdLineArguments

http://example.com/cgi-bin/booksearch.cgi?action=title&query=the+great+gatsby

action param set to title - indicating script search books by title. query param specifies search term.

http://example.com/cgi-bin/booksearch.cgi?action=author&query=fitzgerald

action set to author, etc.

allows easily switching different search actions based on user input.

Problem arises when enableCmdLineArguments is enabled on win systems because cgi servlet fails to properly validate input from web browser before passing it to cgi script. Leads to OS cmd injection attacks, exec arbitrary commands on tgt sys

i.e. attack can append dir to valid command using & separator

http://example.com/cgi-bin/hello.bat?&dir

&dir passed as arg to hello.bat and executes dir

example nmap ![](/img/Pasted image 20250118000505.png)

tomcat 8080

Finding CGI dirbusting ffuf w/ dirb common.txt wordlist. knowing default dir for cgi scripts is /cgi , attempt url: http://10.129.204.227:8080/cgi/FUZZ.cmd or http://10.129.204.227:8080/cgi/FUZZ.bat

since OS is windows we aim to fuzz for batch scripts

ffuf -w /usr/share/dirb/wordlists/common.txt -u http://10.129.204.227:8080/cgi/FUZZ.bat
ffuf -w /usr/share/dirb/wordlists/common.txt -u http://10.129.204.227:8080/cgi/FUZZ.cmd

exploit CVE-2019-0232 appending commands with & ![](/img/Pasted image 20250118001429.png)

keep note it may be necessary to both: