Apache ActiveMQ RCE

admin 2024年2月9日14:41:11评论18 views字数 2088阅读6分57秒阅读模式

扫码领资料

获网安教程

免费&进群

Apache ActiveMQ RCE
Apache ActiveMQ RCE

影响版本

Apache ActiveMQ < 5.18.3

利用条件

需要访问到61616端口(默认)。

漏洞分析

这里需要的是Apache ActiveMQ < 5.18.3,我这里直接下的5.18.2

https://github.com/apache/activemq/commit/958330df26cf3d5cdb63905dc2c6882e98781d8f

Apache ActiveMQ RCE

在新版本中添加了一个OpenWireUtil.validateIsThrowable(clazz);在5.18.2中的代码如下

Apache ActiveMQ RCE

把5.18.3的代码下下来,看看validateIsThrowable方法,代码如下

package org.apache.activemq.openwire;

public class OpenWireUtil {

/**
* Verify that the provided class extends {@link Throwable} and throw an
* {@link IllegalArgumentException} if it does not.
*
* @param clazz
*/

public static void validateIsThrowable(Class<?> clazz) {
if (!Throwable.class.isAssignableFrom(clazz)) {
throw new IllegalArgumentException("Class " + clazz + " is not assignable to Throwable");
}
}
}

这里如果传进来的clazz不是继承自Throwable类,就会抛出异常。在上面是通过反射获取一个类,然后调用对应的构造方法。在5.18.3在中对这个反射获取到的类进行了过滤。 现在就需要找到一个可以命令执行的类去反射获取。这里是用的BaseDataStreamMarshaller的classloader。

找到BaseDataStreamMarshaller的子类ExceptionResponseMarshaller,在其中的tightUnmarshal方法中调用了tightUnmarsalThrowable,具体代码如下

public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn, BooleanStream bs) throws IOException {
super.tightUnmarshal(wireFormat, o, dataIn, bs);
ExceptionResponse info = (ExceptionResponse)o;
info.setException((java.lang.Throwable) tightUnmarsalThrowable(wireFormat, dataIn, bs));
}

tightUnmarsalThrowable具体代码如下

Apache ActiveMQ RCE

在其中说到了上文当中的createThrowable,可以反射获取一个类并且调用对应的含一个string参数的构造方法,其中ExceptionResponseMarshaller类是对ExceptionResponse进行序列化操作的类

来看tightUnmarsalThrowable的主要逻辑

Apache ActiveMQ RCE

从BooleanStream读入一个Boolean的数据,分别调用tightUnmarshalString去获取clazz和message,应该是把类名和message从clazz从二进制流中读取出来,然后作为参数调用createThrowable方法,tightUnmarsalThrowable方法最后返回了一个o,根据如下代码,这个o应该是ExceptionResponse的Exception属性

public void tightUnmarshal(OpenWireFormat wireFormat, Object o, DataInput dataIn, BooleanStream bs) throws IOException {
super.tightUnmarshal(wireFormat, o, dataIn, bs);

ExceptionResponse info = (ExceptionResponse)o;
info.setException((java.lang.Throwable) tightUnmarsalThrowable(wireFormat, dataIn, bs));

}

我们这只要构造一个ExceptionResponse包含恶意的类名和message发送给服务器,服务器接受到并且反序列化就可以调用createThrowable

来源:https://ch1e.cn/post/apache-activemq-rce/

声明:⽂中所涉及的技术、思路和⼯具仅供以安全为⽬的的学习交流使⽤,任何⼈不得将其⽤于⾮法⽤途以及盈利等⽬的,否则后果⾃⾏承担。所有渗透都需获取授权

@

原文始发于微信公众号(白帽子左一):Apache ActiveMQ RCE

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年2月9日14:41:11
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Apache ActiveMQ RCEhttps://cn-sec.com/archives/2210799.html

发表评论

匿名网友 填写信息