-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathMinIO_GetVersion.py
138 lines (126 loc) · 5.11 KB
/
MinIO_GetVersion.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
import requests
import sys
requests.packages.urllib3.disable_warnings()
session = requests.session()
def loginMinIO(url, username, password):
print("[*] Try to login:" + url)
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36",
"Content-Type": "application/json",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-US,en;q=0.9"
}
target = url + "/api/v1/login"
d = {"accessKey": username,
"secretKey": password,
}
try:
res = session.post(target, headers=headers, json=d, verify = False, timeout = 10)
if res.status_code == 204:
print('[+] Login Success')
print(" Cookie:")
print(" token=" + res.cookies['token'])
return url
else:
print('[-] Login error')
if "An error occurred when parsing the HTTP request POST at" in res.text and "9000" in url:
print(" Wrong port,try to use 9001")
newurl = url.rsplit(':9000')[0] +":9001"
print("[*] Try to login:" + newurl + "/api/v1/login")
res = session.post(newurl + "/api/v1/login", headers=headers, json=d, verify = False, timeout = 10)
if res.status_code == 204:
print('[+] Login Success')
print(" Cookie:")
print(" token=" + res.cookies['token'])
return newurl
else:
print('[-] Login error')
print(" Wrong port,try to use another port")
sys.exit(0)
else:
print(res.status_code)
print(res.text)
sys.exit(0)
except Exception as e:
print("[!]")
print(e)
sys.exit(0)
def getversion(url):
print("[*] Try to get version")
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36",
"Content-Type": "application/x-www-form-urlencoded",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-US,en;q=0.9"
}
target = url + "/api/v1/admin/info"
try:
res = session.get(target, headers=headers, verify = False, timeout = 10)
if res.status_code == 200:
dictt = res.json()["servers"]
for k in dictt:
print(" +server: " + str(k["network"]))
print(" state: " + k["state"])
print(" uptime: " + str(k["uptime"]))
print(" version: " + k["version"])
else:
print('[-] Login error')
print(res.status_code)
print(res.text)
except Exception as e:
print("[!]")
print(e)
sys.exit(0)
def getinfo(url):
print("[*] Try to get info")
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36",
"Content-Type": "application/x-www-form-urlencoded",
"Accept-Encoding": "gzip, deflate",
"Accept-Language": "en-US,en;q=0.9"
}
target = url + "/api/v1/admin/info"
try:
res = session.get(target, headers=headers, verify = False, timeout = 10)
if res.status_code == 200:
print(" buckets: " + str(res.json()["buckets"]))
print(" objects: " + str(res.json()["objects"]))
dictt = res.json()["servers"]
for k in dictt:
print(" +server: " + str(k["network"]))
print(" state: " + k["state"])
print(" uptime: " + str(k["uptime"]))
print(" version: " + k["version"])
print(" endpoint:" + k["endpoint"])
print(" drives : " + str(k["drives"]))
else:
print('[-] Login error')
print(res.status_code)
print(res.text)
except Exception as e:
print("[!]")
print(e)
sys.exit(0)
if __name__ == "__main__":
if len(sys.argv)!=5:
print('')
print('MinIO_GetVersion')
print('Usage:')
print(' %s <host> <username> <password> <mode>'%(sys.argv[0]))
print('Mode:')
print('getversion')
print('getinfo')
print('Eg.')
print(' %s http://192.168.1.1:9000 minioadmin minioadmin getinfo'%(sys.argv[0]))
sys.exit(0)
else:
if sys.argv[1][-1] == "/":
sys.argv[1] = sys.argv[1][:-1]
if sys.argv[4] =="getversion":
url = loginMinIO(sys.argv[1], sys.argv[2], sys.argv[3])
getversion(url)
elif sys.argv[4] =="getinfo":
url = loginMinIO(sys.argv[1], sys.argv[2], sys.argv[3])
getinfo(url)
else:
print("[!] Wrong parameter")