Blogs

Path Traversal Attacks and the Waratek Rules That Stop Them

One rule, two very different exploits, and no product-specific changes

Two path traversal payloads, GlassFish's overlong %c0%ae%c0%ae/ and Struts' top.UploadFileName=../, both reach the same ../ inside the Java application, where one Waratek rule blocks them

Summary

  • Waratek’s Path Traversal rule follows untrusted data from the request to the file the JVM opens, and blocks the file operation if that data climbs out of the folder it started in.
  • We look at two CVEs here by way of example: CVE-2017-1000028 (GlassFish) and CVE-2024-53677 (Apache Struts). The rule blocked both exploits with no app-specific changes, and non-exploit requests to the same pages work as normal.
  • The rule looks at the path after the server has decoded it, so encoding tricks like GlassFish’s %c0%ae don’t get past it.
  • Some path traversal never shows up in the request. In Apache Jetspeed CVE-2016-0709 the ../ is inside an uploaded ZIP file, so the Path Traversal rule doesn’t see it.
  • Waratek Filesystem rules that protect specific folders add a second layer of defense, and blocked the Jetspeed web shell.
  • One Tomcat CVE filed as path traversal was an XXE vulnerability at heart, which the Waratek XXE rule mitigates.

Path traversal is one of the oldest and most persistent security bugs. An application builds a file path from something the user sent, the user sends ../../../etc/passwd, and the application reads a file it was never meant to serve. It still turns up in new CVEs every month, usually in a form that slips past whatever the developers checked for.

Waratek’s Path Traversal rule blocks the behavior rather than the CVE. We tested it against real products with published exploits, and it blocked them as they came, with no changes to the rule. While testing, we also found a path traversal attack, that was only stopped when using our security hardening rules for JVM - combining and layering our XML External Entity (XXE) prevention rule or Filesystem read/write rules.

How the rule works

The Waratek agent runs inside the JVM. It marks data that comes from outside, such as HTTP request parameters, headers, paths and uploaded form fields, as untrusted, and follows that data as the application copies and concatenates it. When the application opens, reads or writes a file, the agent checks the final path. If the untrusted part of the path takes it out of the folder it started in, the rule blocks the call and logs a security event.

Two things follow from that:

  • The rule doesn’t care how the .. was spelled or encoded. It looks at the path the JVM is actually about to open, after the server and the application have finished decoding it. URL encoding, double encoding and overlong UTF-8 all end up as the same .. by then.
  • A .. that the application wrote itself is fine. A path like config/../templates/home.html from the application’s own code isn’t untrusted, so normal application behavior doesn’t trigger the rule.

You can set it up in the Portal’s Rules Wizard, or write it as a rule like this using our ARMR DSL:

filesystem("Block path traversal"):
    input(http, database, deserialization)
    traversal()
    protect(message: "Path traversal blocked", severity: High)
endfilesystem

input(...) says which untrusted sources to follow, and traversal() names the behavior to stop. Swap protect for detect and the agent logs the attack without blocking it.

Two very different CVEs, one unchanged rule

For each CVE we installed the vulnerable version, confirmed that the published exploit worked with the agent attached and no rules, then ran it again in Detect and in Protect mode. In Protect mode we also checked that normal requests to the same feature still worked.

CVEProductWhere the path comes fromResult in Protect
CVE-2017-1000028GlassFish 4.1 admin consoleThe URL, using overlong UTF-8 %c0%ae for each .File read blocked with no code changes, theme files still served
CVE-2024-53677Apache Struts 6.3 file uploadA form field that overrides the uploaded file’s nameWrite blocked with no code changes, normal uploads still work

Two path traversal exploits take different routes to the same file call. GlassFish CVE-2017-1000028 hides the dots as overlong UTF-8 %c0%ae in the URL, and GlassFish decodes them to theme/META-INF/../../…/etc/passwd. Apache Struts CVE-2024-53677 adds a top.UploadFileName form field, and Struts uses it as the file name, giving a path ending in ../escaped/pwn.txt. Both reach the point where the JVM opens the file, where the Waratek Path Traversal rule checks whether untrusted input takes the path out of its folder. Without Waratek, GlassFish returns /etc/passwd and Struts writes outside the upload folder. With Waratek, the agent blocks the call and logs a security event.

GlassFish: the encoding trick

GlassFish 4.1 serves its admin console themes from /theme/META-INF/ on port 4848, and it doesn’t need a login to do so. The exploit asks for a theme file with %c0%ae%c0%ae/ repeated in the path:

GET /theme/META-INF/%c0%ae%c0%ae/%c0%ae%c0%ae/ ... /etc/passwd

%c0%ae is an overlong UTF-8 encoding of ., which a strict decoder should reject. GlassFish’s decoder accepts it, so a filter that looks for .. or %2e%2e in the URL sees nothing, and the server walks out of the theme folder to /etc/passwd.

The Waratek agent checks the path at the moment GlassFish tries to open the file. GlassFish has decoded the URL by then, so the agent sees a plain ../../etc/passwd that climbs out of the theme folder, and blocks the read. The console’s real theme files kept loading as normal. Nothing in the rule mentions this encoding, and nothing needed to.

Apache Struts: the file name from a form field

CVE-2024-53677 is a critical bug in Struts’ file upload. Struts cleans the name of an uploaded file, but it also lets the request set action properties by name. An attacker who adds a form field called top.UploadFileName replaces the cleaned name with their own, such as ../escaped/pwn.txt, and the application writes the upload wherever that points. Published exploits use this to drop a JSP web shell.

The rule follows the form field’s value into the path that the application writes to, and blocked the write. A normal upload with the same app still worked.

Blocking it without code changes matters more than usual for this CVE. Upgrading Struts isn’t enough on its own: the Apache advisory says you must also rewrite your upload actions to use Struts’ new file upload mechanism, because staying on the old one leaves you vulnerable, even on a fixed version. Struts 2.3 and 2.5 are end of life, and the advisory lists no fix for them. The Waratek agent blocked the exploit on the unmodified application (we tested 6.3), with no code changes and no upgrade, which buys time to do the migration properly.

More flavors of path traversal in Java

Some path traversal never shows up in the request. Apache Jetspeed’s CVE-2016-0709 is an example. Jetspeed 2.3.0 lets an admin import site content as a ZIP file. It unpacks the ZIP into a temporary folder, using each entry’s name as the file’s path. An entry named ../../webapps/jetspeed/x.jsp climbs out of that folder and drops a JSP web shell into the web app, where Tomcat will run it. This kind of bug is known as Zip Slip.

The import needs an admin login, but that is less of a barrier than it sounds. The published Metasploit module first creates its own admin user through Jetspeed’s unsecured User Manager REST API, then uploads the ZIP.

We reproduced the exploit on Jetspeed 2.3.0, and the Path Traversal rule logged nothing in either Detect or Protect mode. That’s expected. The .. is real, but it comes from inside an uploaded file rather than from a request parameter, header or path, so the agent never marks it as untrusted. With no untrusted input in the path, the rule has nothing to judge.

That doesn’t mean Jetspeed can’t be protected.

Protecting the folders that matter

The Path Traversal rule asks whether untrusted input moved a path out of its folder. A Filesystem rule asks a simpler question: should anything be written here at all? A web shell is only useful if it lands where the server will run it, such as Tomcat’s webapps folder, so that’s the folder to protect:

filesystem("Block writes to web apps"):
    write("/opt/tomcat/webapps/*")
    protect(message: "Write to webapps blocked", severity: High)
endfilesystem

There’s no input(...) line, so the rule doesn’t depend on where the path came from in this case. Against Jetspeed it blocked the web shell: the JSP was never written, and a request for it returned 404.

A rule this broad also covers the server’s own writes, so add Filesystem rules with the allow action for the folders your application legitimately writes to.

When the exploit isn’t path traversal at heart

Apache Tomcat’s CVE-2007-5461 is categorized by its CWE as path traversal. When we tested it, the Path Traversal rule wasn’t triggered by the exploit. The exploit sends a WebDAV LOCK request whose XML body declares an external entity pointing at a local file, and Tomcat’s WebDAV servlet copies the file’s contents into its response. That’s XML External Entity injection (XXE), and Waratek’s XXE rule blocked it, even though the XML was parsed inside Tomcat’s own servlet rather than application code. We tested the XXE rule against a range of other CVEs, and we’ll cover those in a follow-up post.

If your Java apps handle file paths

Fix the code first. Check that every path built from user input, or from an archive entry, stays inside its base folder before you open it. Keep frameworks and servers up to date, because, as GlassFish, Struts and Jetspeed show, the vulnerable code is often not yours.

Then:

  • Enable the Waratek Path Traversal rule. It blocked the GlassFish and Struts exploits as published, encoding tricks included, with no changes for either product.
  • Enable Waratek Filesystem rules to protect the folders that matter. One stopped the Jetspeed web shell that the Path Traversal rule couldn’t catch.
  • Look at how the exploit works, not just how the CVE is labeled. A CVE filed as path traversal, like Tomcat’s CVE-2007-5461, may need a different rule.

References

  1. Waratek VRT, Java vulnerability data for every CVE in this post: https://vrt.services.waratek.com
  2. Apache Struts security bulletin S2-067 (CVE-2024-53677): https://cwiki.apache.org/confluence/display/WW/S2-067
  3. Apache Jetspeed security reports (CVE-2016-0709): https://portals.apache.org/jetspeed-2/security-reports.html
  4. Metasploit module for Apache Jetspeed (CVE-2016-0709): https://github.com/rapid7/metasploit-framework/blob/master/modules/exploits/multi/http/apache_jetspeed_file_upload.rb
  5. MITRE CWE-22, Improper Limitation of a Pathname to a Restricted Directory: https://cwe.mitre.org/data/definitions/22.html
Share Article