Apache Commons Text RCE 分析

admin 2025年1月2日23:25:55评论3 views字数 1381阅读4分36秒阅读模式

漏洞描述

Apache Commons Text < 1.10.0 RCE

影响版本

Version<1.10.0

漏洞复现

Apache Commons Text RCE 分析

依赖

<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()}");

漏洞分析

首先在这行产生命令执行的代码打上断点,然后调试分析

Apache Commons Text RCE 分析

单步步入分析,在 org.apache.commons.text.StringSubstitutor#replace(java.lang.String) 方法中首先调用 TextStringBuilder 构造字符串然后传入 org.apache.commons.text.StringSubstitutor#substitute(org.apache.commons.text.TextStringBuilder, int, int) 方法

Apache Commons Text RCE 分析

继续跟入 org.apache.commons.text.StringSubstitutor#substitute(org.apache.commons.text.TextStringBuilder, int, int) 方法进行分析

Apache Commons Text RCE 分析

接着继续流来到了 org.apache.commons.text.StringSubstitutor#substitute(org.apache.commons.text.TextStringBuilder, int, int, java.util.List)方法,在这个方法中,首先获取各种特殊字符(分割符)以及相关配置

Apache Commons Text RCE 分析

接着进入一个大循环,以这些特殊字符作为分割符,提取关键信息,这步操作类似于很多提取器,如 log4j fastjson 等很多都存在类似操作,其实就是 idnexOf 这些特殊字符,然后做字符串截取。

Apache Commons Text RCE 分析

这里面做了一堆字符串判断提取操作,我们直接定位重点,慢慢单步的话就会发现这里实际上做的就是根据这些特殊字符做相关解析,这里我就不再详细跟踪

Apache Commons Text RCE 分析

跟入 org.apache.commons.text.StringSubstitutor#resolveVariable 方法继续分析

Apache Commons Text RCE 分析

org.apache.commons.text.StringSubstitutor#resolveVariable 方法中从 StringLookupMap 数组中获取解析器进行字符串解析,可以看到这里存在很多处理器。

继续跟踪程序流,来到 org.apache.commons.text.lookup.InterpolatorStringLookup#lookup 方法中

Apache Commons Text RCE 分析

在这个方法中对字符串进行了分割,主要关注这里的 org.apache.commons.text.lookup.ScriptStringLookup#lookup 方法调用

Apache Commons Text RCE 分析

这里调用 NashornScriptEngine#eval 导致命令执行。

Apache Commons Text RCE 分析

至此,整个漏洞流程就完毕了。

原文始发于微信公众号(安全之道):Apache Commons Text RCE 分析

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2025年1月2日23:25:55
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Apache Commons Text RCE 分析http://cn-sec.com/archives/2496624.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息