最近 OSS-SEC 邮件组披露,Linux 基准 Libc 函数库中的 Realpath 函数存在缓冲区下溢漏洞,CVE 编号为 CVE-2018-1000001。漏洞的产生是由于 GNU C 库没有正确处理 getcwd() 系统调用返回的相对路径,并且没有对缓冲区边界进行检查,其他库也很可能受此影响。
该漏洞为高风险漏洞,可直接用于 Linux 本地提权,目前已经有攻击 EXP 公开,相关机器应尽快完成相应更新。
漏洞分析
该漏洞涉及到两个方面:
- kernel 的 getcwd 系统调用
- glibc 的 realpath 函数
虽然官方认为这不是内核的问题,但是内核还是提供了补丁。
linux kernel 补丁地址:
https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=52a713fdd0a30e1bd79818e2e3c4ab44ddca1a94
getcwd() 函数用于返回当前工作目录的绝对路径,如果该目录不属于当前进程的根目录(例如:该进程使用 chroot 设置了一个新的文件系统根目录,但是没有将当前目录的根目录替换成新的),从 linux 2.6.36 开始,getcwd 会返回“(unreachable)”。通过改变当前目录到另一个挂载的用户空间,普通用户可以完成上述的行为。所以当处理不可信来源的路径时,应该检查返回的路径是否以”/”或”(“开头,避免返回一个不可达地址,被认为是相对地址。
漏洞发生处:glibc stdlib/canonicalize.c 的__realpath 函数:
如果解析的是一个相对路径 (不是以’/’开头的路径) 时,就会调用__getcwd()
if (name[0] != '/')
{ if (!__getcwd (rpath, path_max))
{
rpath[0] = '0'; goto error;
}
dest = __rawmemchr (rpath, '0');
} else
{
rpath[0] = '/';
dest = rpath + 1;
}
如果__getcwd() 此时返回的是”(unreachable)”,则接下来在解析路径时,发现路径开头并不包含’/’,会在 while 循环中不断读取 dest 之前的地址,产生缓冲区下溢。
else if (end - start == 2 && start[0] == '.' && start[1] == '.')
{ /* Back up to previous component, ignore if at root already. */
if (dest > rpath + 1) while ((--dest)[-1] != '/');
}
之后操作的 dest 地址就是溢出的地址。
漏洞攻击效果图:
漏洞影响
Red Hat 受影响情况:
Centos 7 的 glibc 版本受影响,centos 5,6 系列均不受影响。
Ubuntu受影响情况:
Package
Source: eglibc (LP Ubuntu Debian)
Upstream: | needed |
Ubuntu 12.04 ESM (Precise Pangolin): | released (2.15-0ubuntu10.21) |
Ubuntu 14.04 LTS (Trusty Tahr): | released (2.19-0ubuntu6.14) |
Ubuntu 16.04 LTS (Xenial Xerus): | DNE |
Ubuntu 17.10 (Artful Aardvark): | DNE |
Ubuntu 18.04 LTS (Bionic Beaver): | DNE |
Package
Source: glibc (LP Ubuntu Debian)
Upstream: | needed |
Ubuntu 12.04 ESM (Precise Pangolin): | DNE |
Ubuntu 14.04 LTS (Trusty Tahr): | DNE |
Ubuntu 16.04 LTS (Xenial Xerus): | released (2.23-0ubuntu10) |
Ubuntu 17.10 (Artful Aardvark): | released (2.26-0ubuntu2.1) |
Ubuntu 18.04 LTS (Bionic Beaver): | needed |
Patches:
Upstream: | https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=52a713fdd0a30e1bd79818e2e3c4ab44ddca1a94 |
Package
Source: dietlibc (LP Ubuntu Debian)
Upstream: | needs-triage |
Ubuntu 12.04 ESM (Precise Pangolin): | DNE |
Ubuntu 14.04 LTS (Trusty Tahr): | needs-triage |
Ubuntu 16.04 LTS (Xenial Xerus): | needs-triage |
Ubuntu 17.10 (Artful Aardvark): | needs-triage |
Ubuntu 18.04 LTS (Bionic Beaver): | needs-triage |
Package
Source: musl (LP Ubuntu Debian)
Upstream: | needs-triage |
Ubuntu 12.04 ESM (Precise Pangolin): | DNE |
Ubuntu 14.04 LTS (Trusty Tahr): | needs-triage |
Ubuntu 16.04 LTS (Xenial Xerus): | needs-triage |
Ubuntu 17.10 (Artful Aardvark): | needs-triage |
Ubuntu 18.04 LTS (Bionic Beaver): | needs-triage |
修复方案
相关受影响产品已经提供了安全更新。centos7 通过 yum update glibc kernel 升级。
参考链接
- http://www.openwall.com/lists/oss-security/2018/01/11/5
- https://access.redhat.com/security/cve/CVE-2018-1000001
- https://www.halfdog.net/Security/2017/LibcRealpathBufferUnderflow/
- https://github.com/5H311-1NJ3C706/local-root-exploits/tree/master/linux/CVE-2018-1000001
转自 http://ift.tt/2nljotM
The post 安全预警 | Linux Libc Realpath 存在缓冲区下溢漏洞 appeared first on Linuxeden开源社区.
http://ift.tt/2BANWMx
没有评论:
发表评论