CVE-2022-33980分析

简单调下

简单调下

组件简介

Commons Configuration 软件库提供了一个通用配置接口,使Java应用程序能够从各种来源读取配置数据,配置文件中配置变量的值可以引用变量,如${env:FACELOG_HOME}就指代环境变量FACELOG_HOME,${sys:user.home}指代java的user.home属性

官方描述

漏洞版本是2.4-2.7,2.8修复了这个漏洞,默认情况下禁用有问题的interpolators

Apache Commons Configuration的功能是变量插值,允许动态加载和扩展配置属性。插值的标准格式是“${prefix:name}”,其中“prefix”用于定位org.apache.commons.configuration2.interpol.lookup的实例来插值。影响的lookup()有三个:

  • “script” - 用JVM脚本执行引擎(javax.script)执行表达式
  • “dns” - 解析dns记录
  • “url” - 从url(包括远程服务器)中加载值

可能会造成RCE或者访问远程服务器

2.8修复后原来的payload会报错,查看官方文档,显示:

All of the lookups present in the returned map are from DefaultLookups. However, not all of the available lookups are included by default. Specifically, lookups that can execute code (e.g., SCRIPT) and those that can result in contact with remote servers (e.g., URL and DNS) are not included. If this behavior must be modified, users can define the “org.apache.commons.configuration2.interpol.ConfigurationInterpolator.defaultPrefixLookups” system property with a comma-separated list of DefaultLookups enum names to be included in the set of defaults.

简单来说就是上述受影响的三个lookup()被默认ban掉了,需要单独设置系统属性来开启,在对比2.8和2.7的jar包后发现功能本身并没有修改,只要配置开启或者是有别的路径进行调用,还是可以RCE或者访问远程服务器的。

调用链

整个利用链还是比较简单的,解析配置的时候调用lookup(),最后执行payload中的script

org.apache.commons.configuration2.interpol.ConfigurationInterpolator.interpolate()
resolveSingleVariable(strValue)
	org.apache.commons.configuration2.interpol.ConfigurationInterpolator.resolveSingleVariable()
	resolve(extractVariableName(strValue))
			org.apache.commons.configuration2.interpol.ConfigurationInterpolator.resolve()
			fetchLookupForPrefix(prefix).lookup(name)
				org.apache.commons.configuration2.interpol.ConfigurationInterpolator.fetchLookupForPrefix().lookup()
					org.apache.commons.configuration2.interpol.StringLookupAdapter.lookup()
          stringLookup.lookup(key)
          	org.apache.commons.text.lookup.ScriptStringLookup.lookup()
          	scriptEngine.eval(script)

最后eval()的描述是:Executes the specified script. The default ScriptContext for the ScriptEngine is used.

小结

还是有点治标不治本的感觉,既然能开启,那总会有人设置开启的。个人认为还是尽量不要出现能执行任意命令的代码比较好,如果一个地方能RCE,那总会被RCE的,需要的功能还是尽可能细化,减少输入对结果的影响。

参考

补丁说明:https://lists.apache.org/thread/tdf5n7j80lfxdhs2764vn0xmpfodm87s

组建文档:https://commons.apache.org/proper/commons-configuration/apidocs/index.html

漏洞环境:https://github.com/tangxiaofeng7/CVE-2022-33980-Apache-Commons-Configuration-RCE