glibc漏洞监测并修复

【CVE 2015-0235: GNU glibc gethostbyname 缓冲区溢出漏洞 】全面爆发,该漏洞的产生是Qualys公司在进行内部代码审核时,发现了一个在GNU C库(glibc)中存在的__nss_hostname_digits_dots函数导致的缓冲区溢出漏洞。这个bug可以通过gethostbyname *()函数来触发,本地和远程均可行。该漏洞(幽灵漏洞)造成了远程代码执行,攻击者可以利用此漏洞获取系统的完全控制权。

  1,监测漏洞:新建文件夹/root/glibc/  ,在里面新建个cve.c 文件:

      添加如下代码:

      

#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] = '';

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);
}

2,编译运行脚本

  #gcc cve.c -o cve

  #./cve 

 3,如果现实vulnerable 表明存在漏洞

 4,修复步骤:最简单的就是:

  #yum install glibc 

5, 在运行脚本,显示:not vulnerable表明漏洞已修复

 

原文地址:https://www.cnblogs.com/hxyphp/p/4260651.html