id: CVE-2024-56337 info: name: Apache Tomcat - Write-Enabled Default Servlet (TOCTOU RCE Exposure) author: DhiyaneshDk severity: critical description: | Apache Tomcat (9.0.0.M1-9.0.97, 10.1.0-M1-10.1.33, 11.0.0-M1-11.0.1, and EOL 8.5.x) is vulnerable to a TOCTOU race condition during JSP compilation (CVE-2024-56337, an incomplete fix for CVE-2024-50379). On a case-insensitive file system, a concurrent read and upload of the same file bypasses Tomcat's case-sensitivity check, causing an uploaded file to be treated as a JSP and leading to remote code execution. Exploitation requires the default servlet to be configured with write support enabled (readonly=false), which is not the default. This template actively confirms that necessary precondition - it uploads a benign file via PUT and reads it back to prove the default servlet is write-enabled - without performing the destructive race or uploading a JSP. impact: | A write-enabled default servlet lets an unauthenticated attacker upload files to the web root. Combined with a vulnerable Tomcat version on a case-insensitive file system (and, on Java 8/11, sun.io.useCanonCaches left at true), this enables remote code execution via the TOCTOU race. remediation: | Set the default servlet readonly to true (the default) unless write access is required, upgrade Tomcat to 9.0.98 / 10.1.34 / 11.0.2 or later, and on Java 8/11 set the system property sun.io.useCanonCaches to false. reference: - https://nvd.nist.gov/vuln/detail/CVE-2024-56337 - https://lists.apache.org/thread/2bjnh3p78b89n5hw539hh31sr7tt7m22 - https://github.com/advisories/GHSA-27hp-xhwr-wr2m classification: cvss-metrics: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H cvss-score: 9.8 cve-id: CVE-2024-56337 epss-score: 0.19029 epss-percentile: 0.97376 cwe-id: CWE-367 metadata: verified: true max-request: 3 shodan-query: title:"Apache Tomcat" fofa-query: title="Apache Tomcat" tags: cve,cve2024,tomcat,apache,rce,race-condition,toctou,intrusive,vkev variables: canary: "{{rand_base(18)}}" filename: "{{rand_base(10)}}.txt" flow: http(1) && http(2) && http(3) http: - raw: - | PUT /{{filename}} HTTP/1.1 Host: {{Hostname}} Content-Type: text/plain {{canary}} matchers: - type: dsl dsl: - "status_code == 201" - "status_code == 204" condition: or internal: true - raw: - | GET /{{filename}} HTTP/1.1 Host: {{Hostname}} matchers-condition: and matchers: - type: dsl name: file-written-and-served dsl: - "status_code == 200" - "contains(body, canary)" condition: and - type: regex name: tomcat-default-servlet part: header regex: - 'W/"[0-9]+-[0-9]+"' extractors: - type: regex part: header group: 1 regex: - '(?i)etag: (W/"[0-9]+-[0-9]+")' - raw: - | DELETE /{{filename}} HTTP/1.1 Host: {{Hostname}} matchers: - type: dsl dsl: - "status_code >= 100" internal: true # digest: 4a0a0047304502205a64e9382d0d5831d70f5ae29301e1f362c926cc83867b4e46e7157d2bc2a928022100e5092a38012cfe3d45cb836ca8e394a8fa86d1ffbdb4e8a74ca7c4fb46601c89:922c64590222798bb761d5b6d8e72950