CVE-2023-36479
Jetty vulnerable to errant command quoting in CGI Servlet
Description
If a user sends a request to a org.eclipse.jetty.servlets.CGI Servlet for a binary with a space in its name, the servlet will escape the command by wrapping it in quotation marks. This wrapped command, plus an optional command prefix, will then be executed through a call to Runtime.exec. If the original binary name provided by the user contains a quotation mark followed by a space, the resulting command line will contain multiple tokens instead of one. For example, if a request references a binary called file” name “here, the escaping algorithm will generate the command line string “file” name “here”, which will invoke the binary named file, not the one that the user requested.
if (execCmd.length() > 0 && execCmd.charAt(0) != '"' && execCmd.contains(" "))
execCmd = "\"" + execCmd + "\"";
Exploit Scenario
The cgi-bin directory contains a binary named exec and a subdirectory named exec” commands, which contains a file called bin1. The user sends to the CGI servlet a request for the filename exec” commands/bin1. This request will pass the file existence check on lines 194 through 205. The servlet will add quotation marks around this filename, resulting in the command line string “exec” commands/bin1”. When this string is passed to Runtime.exec, instead of executing the bin1 binary, the server will execute the exec binary with the argument commands/file1”. In addition to being incorrect, this behavior may bypass alias checks, and it may cause other unintended behaviors if a command prefix is configured.
If the useFullPath configuration setting is off, the command need not pass the existence check. The attack would not rely on a binary and subdirectory having similar names, and the attack will succeed on a much wider variety of directory structures.
Impact
Users of the org.eclipse.jetty.servlets.CGI Servlet with a very specific command structure may have the wrong command executed.
Patches
No patch.
In Jetty 9.x, 10.x, and 11.x the org.eclipse.jetty.servlets.CGI has been deprecated.
In Jetty 12 (all environments) the org.eclipse.jetty.servlets.CGI has been entirely removed.
Workarounds
The org.eclipse.jetty.servlets.CGI Servlet should not be used. Fast CGI support is available instead.
References
- https://github.com/eclipse/jetty.project/pull/9516
- https://github.com/eclipse/jetty.project/pull/9889
- https://github.com/eclipse/jetty.project/pull/9888
Affected Maven artifacts (4)
| Artifact | Affected versions | Fixed in |
|---|---|---|
| org.eclipse.jetty » jetty-servlets | >= 9.0.0, < 9.4.52>= 10.0.0, < 10.0.16>= 11.0.0, < 11.0.16 | 9.4.52, 10.0.16, 11.0.16 |
| org.eclipse.jetty.ee10 » jetty-ee10-servlets | < 12.0.0-beta2 | 12.0.0-beta2 |
| org.eclipse.jetty.ee8 » jetty-ee8-servlets | < 12.0.0-beta2 | 12.0.0-beta2 |
| org.eclipse.jetty.ee9 » jetty-ee9-servlets | < 12.0.0-beta2 | 12.0.0-beta2 |
Blast radius
57% of the dependent artifacts (3,932) still pull an affected version in their latest release.
| Depth | Dependent versions |
|---|---|
| Direct | 47,608 |
| 2 hops | 141,762 |
| 3 hops | 149,545 |
| 4 hops | 75,251 |
| 5 hops | 27,726 |
| 6 hops | 26,464 |
Most used dependents
- org.apache.spark » spark-sql3,174 usages
- org.apache.kafka » kafka-clients3,135 usages
- org.apache.spark » spark-core2,899 usages
- com.github.tomakehurst » wiremock1,838 usages
- org.apache.kafka » kafka1,450 usages
- com.github.tomakehurst » wiremock-jre81,180 usages
- org.codehaus.mojo » gwt-maven-plugin1,170 usages
- org.apache.kafka » connect-api1,026 usages
- com.google.gwt » gwt-dev1,025 usages
- io.dropwizard » dropwizard-core894 usages
- org.apache.spark » spark-mllib831 usages
- org.wiremock » wiremock733 usages
- org.apache.hive » hive-exec699 usages
- org.apache.spark » spark-streaming670 usages
- org.apache.kafka » connect-transforms659 usages
Computed from the dependency graph of build 20261124.0621 (compile and runtime scopes, nearest version wins). Exclusions and dependency management in consuming projects are not applied, so dependents are potentially affected. When several artifacts are affected, a dependent version that pulls more than one of them is counted once per artifact.
References
- Webhttps://github.com/eclipse/jetty.project/security/advisories/GHSA-3gh6-v5v9-6v9j
- Advisoryhttps://nvd.nist.gov/vuln/detail/CVE-2023-36479
- Webhttps://github.com/eclipse/jetty.project/pull/9516
- Webhttps://github.com/eclipse/jetty.project/pull/9888
- Webhttps://github.com/eclipse/jetty.project/pull/9889
- Packagehttps://github.com/eclipse/jetty.project
- Webhttps://lists.debian.org/debian-lts-announce/2023/09/msg00039.html
- Webhttps://www.debian.org/security/2023/dsa-5507
