-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathjolokia-parser.py
More file actions
executable file
·86 lines (76 loc) · 2.72 KB
/
Copy pathjolokia-parser.py
File metadata and controls
executable file
·86 lines (76 loc) · 2.72 KB
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
#!/usr/bin/env python
import sys
import json
import requests
import os.path
def usage():
print(
f"""Usage:
{sys.argv[0]} path/to/jolokia/list.json
{sys.argv[0]} http://127.0.0.1:8080/jolokia"""
)
exit(42)
def jolokia_escape(string):
for c in ["!", '"', "/"]:
string = string.replace(c, f"!{c}")
return string
if len(sys.argv) != 2 or "-h" in sys.argv or "--help" in sys.argv:
usage()
uri = sys.argv[1].rstrip("/")
if uri.startswith("http://") or uri.startswith("https://"):
if not uri.endswith("/jolokia"):
usage()
req = requests.get(f"{uri}/list", verify=False)
blob = req.text
base_url = uri
else:
if not os.path.isfile(uri):
print(f"File {uri} does not exist")
usage()
with open(uri, "r") as f:
blob = f.read().strip()
base_url = "/jolokia"
try:
json_blob = json.loads(blob)
except Exception as e:
print("Error: ", e)
print("Couldn't parse the json blob, received:")
print(blob)
exit(42)
for package, mbeans in json_blob["value"].items():
package = jolokia_escape(package)
for mbean, props in mbeans.items():
mbean = jolokia_escape(mbean)
for prop in props:
if prop == "desc":
print("[+] DESC :", props["desc"])
elif prop == "attr":
for method, method_props in props["attr"].items():
print(f"{base_url}/read/{package}:{mbean}/{method}")
if method_props["rw"]:
print(
f"{base_url}/write/{package}:{mbean}/{method}/${method_props['type']}"
)
elif prop == "class":
print("[+] CLASS :", props["class"])
elif prop == "op":
for method, method_props in props["op"].items():
if "desc" in method_props:
print(
"[+] DESC :",
method_props["desc"],
f"// returns {method_props['ret']}",
)
if type(method_props) == dict:
method_props = [method_props]
for method_prop in method_props:
if len(method_prop["args"]) == 0:
print(f"{base_url}/exec/{package}:{mbean}/{method}")
else:
args = "/".join(
[f"${arg['type']}" for arg in method_prop["args"]]
)
print(f"{base_url}/exec/{package}:{mbean}/{method}/{args}")
else:
print(f"Unknown prop: {prop}")
exit(42)