漏洞描述
Apache Commons Text < 1.10.0 RCE
影响版本
Version<1.10.0
漏洞复现
依赖
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.9</version>
</dependency>
POC
StringSubstitutor.createInterpolator().replace("${script:js:new java.lang.ProcessBuilder("calc").start()}");
漏洞分析
首先在这行产生命令执行的代码打上断点,然后调试分析
单步步入分析,在 org.apache.commons.text.StringSubstitutor#replace(java.lang.String) 方法中首先调用 TextStringBuilder 构造字符串然后传入 org.apache.commons.text.StringSubstitutor#substitute(org.apache.commons.text.TextStringBuilder, int, int) 方法
继续跟入 org.apache.commons.text.StringSubstitutor#substitute(org.apache.commons.text.TextStringBuilder, int, int) 方法进行分析
接着继续流来到了 org.apache.commons.text.StringSubstitutor#substitute(org.apache.commons.text.TextStringBuilder, int, int, java.util.List
接着进入一个大循环,以这些特殊字符作为分割符,提取关键信息,这步操作类似于很多提取器,如 log4j 、 fastjson 等很多都存在类似操作,其实就是 idnexOf 这些特殊字符,然后做字符串截取。
这里面做了一堆字符串判断提取操作,我们直接定位重点,慢慢单步的话就会发现这里实际上做的就是根据这些特殊字符做相关解析,这里我就不再详细跟踪
跟入 org.apache.commons.text.StringSubstitutor#resolveVariable 方法继续分析
在 org.apache.commons.text.StringSubstitutor#resolveVariable 方法中从 StringLookupMap 数组中获取解析器进行字符串解析,可以看到这里存在很多处理器。
继续跟踪程序流,来到 org.apache.commons.text.lookup.InterpolatorStringLookup#lookup 方法中
在这个方法中对字符串进行了分割,主要关注这里的 org.apache.commons.text.lookup.ScriptStringLookup#lookup 方法调用
这里调用 NashornScriptEngine#eval 导致命令执行。
至此,整个漏洞流程就完毕了。
原文始发于微信公众号(安全之道):Apache Commons Text RCE 分析
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论