Apace Commons Text RCE(CVE-2022-42889)

很好奇这种漏洞情报怎么在公布之前就能找到

首先到https://mvnrepository.com/下载更新之前的1.9.x版本

Maven 导入

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-text -->
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-text</artifactId>
    <version>1.9</version>
</dependency>

构造javascript语句,成功执行命令,这其实是官方文档中提供的例子。

果然找组件漏洞还是得多看文档

进入StringSubstitutor看看程序执行流程吧

其中substitute函数会对传入的字符串进行转换

Recursive handler for multiple levels of interpolation. This is the main interpolation method, which resolves the values of all variable references contained in the passed in text.

经过解析,然后处理数值

跟进resolveVariable方法

继续跟进lookup方法,发现这是一个接口,他有19个实现方法

漏洞点使用的是javascript:也就是InterpolatorStringLookup

Proxies other StringLookups using a keys within markersusingtheformat"{} markers using the format "{StringLookup:Key}".

先获取:前面的字符作为前缀,然后通过键值对获取lookup方法,最后执行lookup,跟进lookup.lookup方法

可以看到调用了scriptEngine.eval执行了:后面的语句,scriptEngine:前的字符串决定,也就是javascript,最终成功执行任意语句。

至于InterpolatorStringLookup中的默认lookup,可以看InterpolatorStringLookup的构造函数,默认情况下addDefaultLookupstrue,进而调用了

if (addDefaultLookups) {
    StringLookupFactory.INSTANCE.addDefaultStringLookups(this.stringLookupMap);
}

跟进addDefaultStringLookups可以找到所有支持的默认lookup

以上