CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

admin 2022年11月26日21:02:31评论144 views字数 1361阅读4分32秒阅读模式
01


漏洞简介

Apache Commons Text是一个专注于处理字符串的算法库,Apache Commons Text的某些版本存在任意代码执行漏洞。
02


影响版本

1.5 <= Apache Commons Text <= 1.9

03


环境搭建

如图所示,在IDEA中新建一个Maven项目,项目配置如下

CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

创建Maven项目后,在pom.xml文件加入如下内容

<dependency>      <groupId>org.apache.commons</groupId>      <artifactId>commons-text</artifactId>      <version>1.8</version></dependency>
CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

如图所示,在src/main/java目录中创建一个JavaTest类

CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

将JavaTest类内容修改为如下所示

import org.apache.commons.text.StringSubstitutor;
public class JavaTest { public static void main(String[] args) { StringSubstitutor interpolator = StringSubstitutor.createInterpolator(); String poc = interpolator.replace("${script:js:java.lang.Runtime.getRuntime().exec("calc")}"); }}

CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

04


漏洞分析

如图所示,在Runtime.java文件的第346行exec函数设置断点

CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

点击Debug ‘JavaTest’开始调试应用

CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

如图所示,在StringSubstiutor#replace中,调用substitute函数处理source值

CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

跟进到StringSubstiutor#substitute,如图所示,在StringSubstiutor#substitute中,将source值去除${、}后通过resolveVariable函数进行处理。

CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

跟进resolveVariable函数,如图所示,在StringSubstiutor#resolveVariable中调用resolver.lookup函数处理variableName值

CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

跟进resolver.lookup函数,如图所示,在resolver.lookup函数中,首先将variableName值script:js:java.lang.Runtime.getRuntime().exec("calc")去除了script:

CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

再根据variableName值前缀为script调用ScriptStringLookup.lookup解析name值

CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

跟进ScriptStringLookup.lookup函数,在ScriptStringLookup.lookup函数中,根据传入的参数值前缀为js实例化js渲染引擎对象,并调用该对象的eval函数处理去除js:的传入参数值java.lang.Runtime.getRuntime().exec("calc")

CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

最终触发命令执行

CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

05


漏洞修复

将Apache Commons Text版本升级至1.10

CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

原文始发于微信公众号(第59号):CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年11月26日21:02:31
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   CVE-2022-42889 Apache Commons Text远程代码执行漏洞分析http://cn-sec.com/archives/1426246.html

发表评论

匿名网友 填写信息