Web Exploitation · Term

What is Spring4Shell?

A request parameter that Spring bound onto an object could walk all the way to Tomcat's logging settings and write a web shell. Spring4Shell arrived months after Log4Shell and borrowed its name.

TL;DR

Spring4Shell is the name for CVE-2022-22965, a remote code execution flaw in Spring Framework disclosed on March 31, 2022 with a CVSS score of 9.8. Spring MVC and WebFlux data binding let request parameters set nested object properties, and on JDK 9 or later a parameter path starting with class.module.classLoader reached the class loader. On Apache Tomcat with a WAR deployment, attackers used it to reconfigure the access log and write a JSP web shell. Fixed in Spring Framework 5.3.18 and 5.2.20.

By Pranav Khune, Lead Pentester, SecureLayer7Updated

What Spring4Shell is

Spring's data binding maps request parameters onto Java objects: a parameter named user.address.city sets that nested property on a form object. Spring had long blocked paths through class.classLoader to stop parameters from reaching internals. Java 9 added Class.getModule(), which opened a new path, class.module.classLoader, that the old block did not cover.

Through that path, request parameters could set properties on the web server's class loader. On Apache Tomcat, those properties include the access log valve configuration. The preconditions were specific: JDK 9 or later, Spring MVC or WebFlux, deployment as a WAR on Tomcat, and a controller that binds request parameters to a plain object. That narrowed the real exposure well below the initial panic.

How the attack works

Shown for defensive context, the public exploit sent a series of parameters that rewrote Tomcat's access log settings:

  • class.module.classLoader.resources.context.parent.pipeline.first.pattern set the log line to contain JSP code.
  • ...first.directory and ...first.prefix pointed the log file into the web root, and ...first.suffix=.jsp made it executable.
  • A follow-up request with a header carrying the JSP fragment was then logged into that file, creating a web shell reachable at a URL like /shell.jsp?cmd=id.

Defenders hunting for it looked for class.module.classLoader in request parameters and newly created .jsp files in Tomcat web roots.

How to fix and defend

  • Upgrade Spring Framework to 5.3.18 or 5.2.20 or later (Spring Boot 2.6.6 or 2.5.12 or later pulls them in). Current Spring 6.x lines are not affected.
  • Upgrade Tomcat to 10.0.20, 9.0.62 or 8.5.78 or later, which closed the access-log path from the server side.
  • Restrict binding. Use @InitBinder with setDisallowedFields or an allowlist of bindable fields so request parameters cannot reach unexpected properties. That is good practice beyond this CVE.
  • Hunt for unexpected JSP files in web roots and class.module strings in access logs.

References

  1. [1]Spring: CVE-2022-22965 advisory(Spring)
  2. [2]NVD: CVE-2022-22965(NIST NVD)
  3. [3]CISA Known Exploited Vulnerabilities Catalog(CISA)
  4. [4]MITRE ATT&CK: Exploit Public-Facing Application (T1190)(MITRE)
Related terms
Related service
Web & API Penetration Testing
Manual, exploit-grade testing of your web apps and APIs, mapped to OWASP, with fixes a developer can ship.
Web & API testing

Common questions

Spring4Shell, asked often

Want your servers and dependencies tested for flaws like this?

Test your application

Find the path to a shell before an attacker does.

Our testers check what your servers actually run, prove whether a named vulnerability is exploitable in your environment, and hand your developers a reproducible finding and a fix.

See web application penetration testing30-min scoping call, fixed-price proposal in 48 hours.