-
Notifications
You must be signed in to change notification settings - Fork 36
/
serializekiller.py
executable file
·353 lines (315 loc) · 10.8 KB
/
serializekiller.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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/usr/bin/env python
# ------------------------------------------------------------------------------
# Name: SerializeKiller
# Purpose: Finding vulnerable java servers
#
# Author: (c) John de Kroon, 2015
# Version: 1.0.2
# ------------------------------------------------------------------------------
import subprocess
import threading
import time
import socket
import sys
import argparse
import urllib2
import ssl
from socket import error as socket_error
from datetime import datetime
import thread
import time
mutex = thread.allocate_lock()
parser = argparse.ArgumentParser(
prog='serializekiller.py',
formatter_class=argparse.RawDescriptionHelpFormatter,
description="Scan for Java Deserialization vulnerability.")
parser.add_argument('--url', nargs='?', help="Scan a single URL")
parser.add_argument('file', nargs='?', help='File with targets')
args = parser.parse_args()
def saveToFile(result):
with open('result.txt', 'a') as f:
f.write(result)
f.close()
def nmap(host, *args):
global shellCounter
global threads
global target_list
# All ports to enumerate over for jboss, jenkins, weblogic, websphere
port_list = ['80', '81', '443', '444', '1099', '5005',
'7001', '7002', '8080', '8081', '8083', '8443',
'8880', '8888', '9000', '9080', '9443', '16200']
# Are there any ports defined for this host?
if not target_list[host]:
found = False
cmd = 'nmap --host-timeout 5 --open -p %s %s' % (','.join(port_list), host)
try:
p = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
shell=True)
out, err = p.communicate()
for this_port in port_list:
if out.find(this_port) >= 0:
if websphere(host, this_port) or weblogic(host, this_port) or jboss(host, this_port) or jenkins(host, this_port):
found = True
if found:
shellCounter += 1
except ValueError, v:
print " ! Something went wrong on host: %s: %s" % (host, v)
return
else:
for port in target_list[host]:
if websphere(
host,
port) or weblogic(
host,
port) or jenkins(
host,
port) or jboss(
host,
port):
shellCounter += 1
return
def websphere(url, port, retry=False):
try:
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
output = urllib2.urlopen(
'https://' + url + ":" + port,
context=ctx,
timeout=8).read()
if "rO0AB" in output:
mutex.acquire()
print " - (possibly) Vulnerable Websphere: " + url + " (" + port + ")"
saveToFile('[+] Websphere: ' + url + ':' + port + '\n')
mutex.release()
return True
except urllib2.HTTPError as e:
if e.getcode() == 500:
if "rO0AB" in e.read():
mutex.acquire()
print " - (possibly) Vulnerable Websphere: " + url + " (" + port + ")"
saveToFile('[+] Websphere: ' + url + ':' + port + '\n')
mutex.release()
return True
except:
pass
try:
output = urllib2.urlopen(
'http://' + url + ":" + port,
timeout=3).read()
if "rO0AB" in output:
mutex.acquire()
print " - (possibly) Vulnerable Websphere: " + url + " (" + port + ")"
saveToFile('[+] Websphere: ' + url + ':' + port + '\n')
mutex.release()
return True
except urllib2.HTTPError as e:
if e.getcode() == 500:
if "rO0AB" in e.read():
mutex.acquire()
print " - (possibly) Vulnerable Websphere: " + url + " (" + port + ")"
saveToFile('[+] Websphere: ' + url + ':' + port + '\n')
mutex.release()
return True
except:
pass
# Used this part from https://github.com/foxglovesec/JavaUnserializeExploits
def weblogic(url, port):
try:
server_address = (url, int(port))
sock = socket.create_connection(server_address, 4)
sock.settimeout(2)
# Send headers
headers = 't3 12.2.1\nAS:255\nHL:19\nMS:10000000\nPU:t3://us-l-breens:7001\n\n'
sock.sendall(headers)
try:
data = sock.recv(1024)
except socket.timeout:
return False
sock.close()
if "HELO" in data:
mutex.acquire()
print " - (possibly) Vulnerable Weblogic: " + url + " (" + str(port) + ")"
saveToFile('[+] Weblogic: ' + url + ':' + str(port) + '\n')
mutex.release()
return True
return False
except socket_error:
return False
# Used something from https://github.com/foxglovesec/JavaUnserializeExploits
def jenkins(url, port):
try:
cli_port = False
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
try:
output = urllib2.urlopen('https://'+url+':'+port+"/jenkins/", context=ctx, timeout=8).info()
cli_port = int(output['X-Jenkins-CLI-Port'])
except urllib2.HTTPError, e:
if e.getcode() == 404:
try:
output = urllib2.urlopen('https://'+url+':'+port, context=ctx, timeout=8).info()
cli_port = int(output['X-Jenkins-CLI-Port'])
except:
pass
except:
pass
except:
mutex.acquire()
print " ! Could not check Jenkins on https. Maybe your SSL lib is broken."
mutex.release()
pass
if cli_port is not True:
try:
output = urllib2.urlopen('http://'+url+':'+port+"/jenkins/", timeout=8).info()
cli_port = int(output['X-Jenkins-CLI-Port'])
except urllib2.HTTPError, e:
if e.getcode() == 404:
try:
output = urllib2.urlopen('http://'+url+':'+port, timeout=8).info()
cli_port = int(output['X-Jenkins-CLI-Port'])
except:
return False
except:
return False
# Open a socket to the CLI port
try:
server_address = (url, cli_port)
sock = socket.create_connection(server_address, 5)
# Send headers
headers = '\x00\x14\x50\x72\x6f\x74\x6f\x63\x6f\x6c\x3a\x43\x4c\x49\x2d\x63\x6f\x6e\x6e\x65\x63\x74'
sock.send(headers)
data1 = sock.recv(1024)
if "rO0AB" in data1:
mutex.acquire()
print " - (possibly) Vulnerable Jenkins: " + url + " (" + str(port) + ")"
saveToFile('[+] Weblogic: ' + url + ':' + str(port) + '\n')
mutex.release()
return True
else:
data2 = sock.recv(1024)
if "rO0AB" in data2:
mutex.acquire()
print " - (possibly) Vulnerable Jenkins: " + url + " (" + str(port) + ")"
saveToFile('[+] Jenkins: ' + ':' + str(port) + '\n')
mutex.release()
return True
except:
pass
return False
def jboss(url, port, retry=False):
try:
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE
output = urllib2.urlopen(
'https://' +
url +
':' +
port +
"/invoker/JMXInvokerServlet",
context=ctx,
timeout=8).read()
except:
try:
output = urllib2.urlopen(
'http://' +
url +
':' +
port +
"/invoker/JMXInvokerServlet",
timeout=8).read()
except:
# OK. I give up.
return False
if "\xac\xed\x00\x05" in output:
mutex.acquire()
print " - (possibly) Vulnerable JBOSS: " + url + " (" + port + ")"
saveToFile('[+] JBoss: ' + ':' + port + '\n')
mutex.release()
return True
return False
def urlStripper(url):
url = str(url.replace("https:", ''))
url = str(url.replace("http:", ''))
url = str(url.replace("\r", ''))
url = str(url.replace("\n", ''))
url = str(url.replace("/", ''))
return url
def read_file(filename):
f = open(filename)
content = f.readlines()
f.close()
return content
def worker():
global threads
content = read_file(args.file)
for line in content:
if ":" in line:
item = line.strip().split(':')
if item[0] not in target_list:
target_list[item[0]] = [item[1]]
else:
target_list[item[0]].append(item[1])
else:
if line.strip() not in target_list:
target_list[line.strip()] = []
print str(len(target_list)) + " targets found."
total_jobs = len(target_list)
current = 0
for host in target_list:
current += 1
while threading.active_count() > threads:
mutex.acquire()
print " ! We have more threads running than allowed. Current: {} Max: {}.".format(threading.active_count(), threads)
mutex.release()
if threads < 100:
threads += 1
sys.stdout.flush()
time.sleep(2)
mutex.acquire()
print " # Starting test {} of {} on {}.".format(current, total_jobs, host)
sys.stdout.flush()
mutex.release()
threading.Thread(target=nmap, args=(host, False, 1)).start()
# We're done!
while threading.active_count() > 2:
mutex.acquire()
print " # Waiting for everybody to come back. Still {} active.".format(threading.active_count() - 1)
sys.stdout.flush()
mutex.release()
time.sleep(4)
mutex.acquire()
print
print " => scan done. " + str(shellCounter) + " vulnerable hosts found."
print "Execution time: " + str(datetime.now() - startTime)
mutex.release()
exit()
if __name__ == '__main__':
startTime = datetime.now()
mutex.acquire()
print "Start SerializeKiller..."
print "This could take a while. Be patient."
print
mutex.release()
try:
ssl.create_default_context()
except:
print " ! WARNING: Your SSL lib isn't supported. Results might be incomplete."
pass
target_list = {}
shellCounter = 0
if args.url:
target_list[urlStripper(args.url)] = []
nmap(urlStripper(args.url))
elif args.file:
threads = 30
worker()
else:
mutex.acquire()
print "ERROR: Specify a file or a url!"
mutex.release()