看我如何在Weblogic裡撿一個XXE(CVE-2018-3246)
*本文作者:黑客小平哥,本文屬 FreeBuf 原創獎勵計劃,未經許可禁止轉載。
前言
前幾天空間被CVE-2018-2894刷屏,大家也都在研究和復現這個漏洞,正好我們安全團隊也在玩這個漏洞,那大家就一起來玩咯。 本次的重點是復現,上傳webshell,環境是內部一個測試環境,當我使用其中一個上傳頁面的時候,腦子突然熱了一下,把檔案字尾改成了.xml,結果就很6了。
地址如下: ofollow" rel="nofollow,noindex" target="_blank">http://127.0.0.1:8338/ws_utc/begin.do 。
分析
突然看到了什麼,報錯了,但是錯誤程式碼裡有個“Internal Exception: org.xml.sax.SAXParseException”,這裡竟然解析xml檔案,這裡說明一下,雖然這裡是上傳webshell的地方,xml檔案貌似沒什麼用,但是當漏洞任意檔案上傳漏洞修復之後,這個xml檔案是不會禁止的,這裡既然解析了xml檔案,說明這xml檔案屬於正常檔案。
此處當然要傳個payload試下了讀下etc/passwd,發現還是報錯,無法讀取:
這就完了?當然不是,既然無法讀取回顯,那就換個payload反彈下shell試試:
設定本地監聽:
返回包發現執行了payload程式碼,並且讀取到伺服器etc/passwd檔案:
至此,該漏洞已經確定存在,並將及時報告給官方了,2018年10月16日,該漏洞已經在oracle釋出。
漏洞簡要分析:
根據路徑,漏洞定位到ws-testpage-impl.jar檔案裡的“importWsTestConfig”方法:
程式碼如下:
@Path("/config/import") @POST @Produces({"application/xml", "application/json"}) @Consumes({"multipart/form-data"}) public Response importWsTestConfig(FormDataMultiPart formPartParams) {if (RequestUtil.isProductionMode()) { return Response.status(Response.Status.SERVICE_UNAVAILABLE).build(); } if (TestClientRT.isVerbose()) { Logger.fine("callingWebserviceResource.importWsTestConfig"); } KeyValuesMap formParams = RSDataHelper.getInstance() .convertFormDataMultiPart(formPartParams, true); ActionData ad = new ActionData(); ad.put("request_form_data", formParams); ad = new ImportTestCaseAction().process(ad); if (ad.get("response_data") != null) { return Response.ok(ad.get("response_data")).build(); } returnResponse.ok().build(); }
可以發現,此處使用的方法為“ImportTestCaseAction”,進去看下該方法:
程式碼如下:
publicActionData execute(ActionData actionData) { KeyValuesMap formParams =(KeyValuesMap)actionData .get("request_form_data"); try { String fileName =(String)formParams.getFirstValue("import_file_name"); String importId = "" + newDate().getTime(); if (TestClientRT.isVerbose()) { Logger.debug("Import ID: " +importId); } Unmarshaller Unmarshaller =context.createUnmarshaller(); TTestConfig tconfig =(TTestConfig)Unmarshaller.unmarshal(new File(fileName)); if (importConfigMap.size() >= 10) { importConfigMap.clear(); } importConfigMap.put(importId, tconfig); actionData.put("response_data",new ImportTest(importId, tconfig.getWsdl(), null)); } catch (Throwable e) { Logger.fine("[Error] Can not parsethe imported test config file.", e); WSTestRuntimeException wste = newWSTestRuntimeException(e); wste.setErrorMsgBean(newErrorMsgBean(null, UserMessages.format("error_while_importing_test",new Object[0]))); throw wste; } return actionData; }
Unmarshaller介面是將XML資料轉化為Java物件,此處是Unmarshaller使用不當,造成XXE,值得注意的是,經過和同事的不懈嘗試,發現jdk8預設禁止外部DTD的,jdk6和jdk7是可以的,而weblogic預設的jdk是存在該問題的(詳細版本範圍有待進一步考證)。
Demo介紹:
此處jdk為1.8,無法實現XXE:
此處jdk為1.6,即可執行: