Linux [转] Linux 云主机幽灵漏洞修复建议 (glibc gethostbyname 缓冲区溢出漏洞)

vincent · January 29, 2015 · Last by vincent replied at January 30, 2015 · 11442 hits
Topic has been selected as the excellent topic by the admin.

今天收到云提供商的安全告示,问题还比较严重,转发一下,提醒大家注意。 转自:http://www.ksyun.com/indexNotice/info/2015/2185.html#80b8ba67-599d-4f7d-a0e3-196dcc238f03

一、漏洞背景

代码审计公司 Qualys 的研究人员在 glibc 库中的__nss_hostname_digits_dots() 函数中发现了一个缓冲区溢出的漏洞,这个 bug 可以经过 gethostbyname*() 函数被本地或者远程的触发。

1)通过 gethostbyname() 函数或 gethostbyname2() 函数,将可能产生一个堆上的缓冲区溢出。经由 gethostbyname_r() 或 gethostbyname2_r(),则会触发调用者提供的缓冲区溢出 (理论上说,调用者提供的缓冲区可位于堆,栈,.data 节和.bss 节等。但是,我们实际操作时还没有看到这样的情况)。

2)漏洞产生时至多 sizeof(char* ) 个字节可被覆盖 (注意是 char*指针的大小,即 32 位系统上为 4 个字节,64 位系统为 8 个字节)。但是 payload 中只有数字 ( '0 '...' 9') ,点 ( “.”) ,和一个终止空字符 ('\0' ) 可用。

3)尽管有这些限制,我们依然可以执行任意的代码。

二、影响范围

该漏洞影响 glibc 库版本 2.2-2.17 的 Linux 操作系统

操作系统类型包括

CentOS 6 & 7

Debian 7

Red Hat Enterprise Linux 6 & 7

Ubuntu 10.04 & 12.04

各 Linux 发行版

三、漏洞测试

1、编译以下测试代码

#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <gnu/libc-version.h>
#define CANARY "in_the_coal_mine"
struct {
char buffer[1024];
char canary[sizeof(CANARY)];
} temp = { "buffer", CANARY };
int main(void) {
struct hostent resbuf;
struct hostent *result;
int herrno;
int retval;
/*** strlen (name) = size_needed - sizeof (*host_addr) - sizeof (*h_addr_ptrs) - 1; ***/
size_t len = sizeof(temp.buffer) - 16*sizeof(unsigned char) - 2*sizeof(char *) - 1;
char name[sizeof(temp.buffer)];
memset(name, '0', len);
name[len] = '\0';
retval = gethostbyname_r(name, &resbuf, temp.buffer, sizeof(temp.buffer), &result, &herrno);
if (strcmp(temp.canary, CANARY) != 0) {
puts("vulnerable");
exit(EXIT_SUCCESS);
}
if (retval == ERANGE) {
puts("not vulnerable");
exit(EXIT_SUCCESS);
}
puts("should not happen");
exit(EXIT_FAILURE);
}

测试结果:

四、漏洞修复

更新是在 glibc 包中,但是这个库会被很多运行中的服务使用。在更新之后,每个服务都要重启一下。要找到所有依赖 glibc 的服务,请使用如下命令,它会显示所有打开的文件 (lsof),然后找到引用 glibc 库的文件。 $ lsof | grep libc | awk '{print $1}' | sort | uniq 最安全的办法是重启所有你上面用 lsof 找到的服务。当然也可以重启服务器。建议如果机器或服务不是对外开放访问的,还是别升 glibc 了。优先升级重启对外开放的服务器,如 Web 和 Mail 等等。

RHEL/CentOS目前没有补丁,红帽发布了CVE信息(https://access.redhat.com/security/cve/CVE-2015-0235),你可以在这个页面跟踪一下修复进度。

CentOS 也正在处理这个事情,处理完之后会发布到它的镜像上。

Debian 和 Ubuntu 已经有更新了,你可以直接更新它们。

apt­-get update

apt-get install libc6

使用 ldd --version 看一下版本即可,大于 2.15 的都不受影响。2.15 版本的需要更新到最新版。 以 ubuntu 为例,2.15 的最新版目前是 Ubuntu EGLIBC 2.15-0ubuntu10.10,修复了这个漏洞。

受影响的系统和不受影响的

Patches are currently available for:

Debian 7
CentOS 6 & 7
Ubuntu 12.04.
Distributions that are unaffected are as follows:

Fedora 20 & 21
Ubuntu 14.04 and 14.10
Arch
OpenSuse 13.2

受影响的系统 不重启安全问题还在哦 reboot 是必须的 因为 init bash 等基础软件都依赖了 libc

lsof  | grep libc | awk '{print $1}' | uniq 

能看到

CentOS 5 & 6 & 7 也有修复了 https://twitter.com/CentOS/status/560236518057709569

如果是读官方镜像的话,可以 yum update glibc 一下来修复了。

You need to Sign in before reply, if you don't have an account, please Sign up first.