IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    Linux glibc幽灵漏洞测试与修复方法

    Vlix_Liu发表于 2015-01-29 09:34:24
    love 0

    一、Linux glibc幽灵漏洞简介

    2015年1月28日互联网上爆出Linux glibc幽灵漏洞(glibc gethostbyname buffer overflow,http://seclists.org/oss-sec/2015/q1/274),也有人将其称之为“20150127GHOST gethostbyname() heap overflow in glibc”,在CVE上的漏洞编号是CVE-2015-0235。攻击者可利用此漏洞实施远程攻击,并完全控制目标系统。

    glibc是GNU发布的libc库,即c运行库。glibc是linux系统中最底层的api,几乎其它任何运行库都会依赖于glibc。glibc除了封装linux操作系统所提供的系统服务外,它本身也提供了许多其它一些必要功能服务的实现。glibc 囊括了几乎所有的 UNIX 通行的标准。

    国外安全研究人员发现,glibc的__nss_hostname_digits_dots()函数有缓冲区溢出漏洞。这一漏洞既可以本地利用,也可以远程利用。研究人员对漏洞进行了测试验证:向目标邮件服务器发送特别构造的邮件,从而获得了远程登录Linxu系统的shell脚本。通过这种方式可以绕过32位和64位系统上的所有现存保护机制(比如SSLR、PIE和NX)。

    受glibc-2.2影响的GNU C函数最早版本是在2000年11月发布的。这一漏洞曾在2013年5月被修补(在glibc-2.17和glibc-2.18版本之间)。但由于当时并没有被认定为安全威胁,包括Debian 7、Red Hat Enterprise Linux 6 & 7、 CentOS 5&6& 7和Ubuntu 12.04在内的多数知名Linux版本在长达一年半的时间都没有修补幽灵漏洞,经测试以下版本均存在漏洞:

    • RHEL (Red Hat Enterprise Linux) version 5.x, 6.x, 7.x
    • CentOS Linux 5.x, 6.x & 7.x
    • Ubuntu Linux version 10.04, 12.04 LTS
    • Debian Linux version 7.x
    • Linux Mint version 13.0
    • Fedora Linux version 19 y anteriores
    • SUSE Linux Enterprise 11 y anteriores
    • Arch Linux glibc version <= 2.18-1

    据安全公司研究人员分析Linux glibc幽灵漏洞最容易的攻击入口是邮件服务器,和存在SSRF(Server-side Request Forgery)漏洞的WEB接口。值得庆幸的是,此漏洞目前还没有公开通用的攻击代码,这也给了服务器管理员们及时安装补丁的宝贵时间。
    二、Linux glibc幽灵漏洞测试方法
    1. Ubuntu & Debian检查
    ldd –version
    (1)Ubuntu受影响版本(https://launchpad.net/ubuntu/+source/eglibc):
    Ubuntu 12.04 LTS: 2.15-0ubuntu10.10
    Ubuntu 10.04 LTS: 2.11.1-0ubuntu7.20
    (2)Debian gibc受影响版本(https://security-tracker.debian.org/tracker/CVE-2015-0235),Debian 7LTS: 2.13-38+deb7u7等
    eglibc (PTS)      squeeze  2.11.3-4  vulnerable
    eglibc wheezy  2.13-38+deb7u6      vulnerable
    Debian gibc已经修复版本:
    squeeze (lts)    2.11.3-4+deb6u4
    wheezy (security)    2.13-38+deb7u7
    2. CentOS & RHEL检查
    在centos上执行“rpm -qglibc”命令,如图1所示,显示glibc的版本信息为glibc-2.5-118.el5_10.2。

    受影响版本:

    CentOS 5:glibc-2.5-118.el5_10.2
    CentOS 6: glibc-2.12-1.149.el6_6.5
    CentOS 7: glibc-2.17-55.el7_0.5
    RHEL 5: glibc-2.5-123.el5_11.1
    RHEL 6: glibc-2.12-1.149.el6_6.5
    RHEL 7: glibc-2.17-55.el7_0.5
    查看RHEL 各个版本更多有关该漏洞的信息请访问:

    https://security-tracker.debian.org/tracker/CVE-2015-0235

    3.POC验证测试

    把下面的代码保存为ghost.c

    /*
    * GHOSTvulnerability check
    * http://www.antian365.com/lab/linux0day/ghost.c
    * Usage: gcc ghost.c-o ghost && ./ ghost
    */

    #include
    #include
    #include
    #include
    #include

    #define CANARY "in_the_coal_mine"

    struct {
    charbuffer[1024];
    charcanary[sizeof(CANARY)];
    } temp = { "buffer", CANARY };

    int main(void) {
    struct hostentresbuf;
    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;
    charname[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);
    }

    直接编译并执行: gcc ghost.c-o ghost && ./ghost 如果存在漏洞则会显示“vulnerable”,如图2所示。

    也可以执行下面的命令,以检测是否存在漏洞

    方法一:
    rpm -qglibc
    cat/etc/issue
    wget http://www.antian365.com/lab/linux0day/ghost.c
    gcc ghost.c-o ghost && ./ghost
    方法二直接显示glibc的版本信息:
    wget -OGHOST-test.sh http://www.antian365.com/lab/linux0day/GHOST-test.sh.txt
    bashGHOST-test.sh
    显示结果如下:
    Vulnerableglibc version <= 2.17-54
    Vulnerableglibc version <= 2.5-122
    Vulnerableglibc version <= 2.12-1.148
    Detectedglibc version 2.5 revision 118
    Thissystem is vulnerable to CVE-2015-0235.RedHat.com/security/cve/CVE-2015-0235>
    Pleaserefer to
    for remediationsteps

    三、修复方法:
    1. Ubuntu/Debian
    在Ubuntu/Debian上执行以下命令进行修复,修复后需要重启。
    apt-get update && apt-get -y install libc6
    2.Centos
    在Centos上执行“yumupdate glibc”后会有一个确认,输入“y”,大概会下载6个安装包,安装完成后需要重启计算机。



沪ICP备19023445号-2号
友情链接