• Linux幽灵漏洞修复


    1. 漏洞说明

    1.1 漏洞原理

    glibc是GNU发布的libc库,即c运行库,在glibc库中的__nss_hostname_digits_dots()函数存在一个缓冲区溢出的漏洞,这个漏洞可以经过gethostbyname*()函数被本地或者远程触发。

    1.2 漏洞危害

    攻击者可以利用该漏洞执行指令,控制存在漏洞的系统。

    1.3 漏洞利用条件(攻击者成功利用漏洞必要条件)

    1)、存在漏洞系统中存在使用gethostbyname() 函数的程序
    2)、程序必须能接收攻击者发送的数据,并且将数据作为gethostbyname
    ()的参数
    3)、攻击者发送的攻击数据(亦作:payload,载荷)必须符合特定条件,如下:
    a) Payload 首字符必须为数字
    b) Payload 最后字符不能为点号
    c) Payload 中只能包含数字和点号
    d) Payload 必须符合ipv4或者ipv6的地址格式
    e) Payload 必须足够长,具体长度需要攻击者不断尝试来确定影响范围

    1、该漏洞影响使用GNU libc库版本2.2-2.17的Linux操作系统
    2、影响的操作系统类型包括:
      CentOS 6 & 7
      Debian 7
      Red Hat Enterprise Linux 6 & 7
      Ubuntu 10.04 & 12.04
      各Linux发行版

    2. 验证方法

    第一、 将漏洞验证代码代码保存成 ghost.c 文件并且上传到要验证的linux主机中
    第二、 使用 gcc ghost.c –o testghost指令编译,会生成testghost
    第三、 使用 ./testghost 执行漏洞测试程序,如果程序输出vulnerable 则说明存在漏洞

    2.1 漏洞验证代码

    #include <netdb.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <errno.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);
    }
    

    3. 修复方法

    将linux中的libc升级到最新版本

    #最新的libc包
    [root@SHQZ-PS-IOT-SV2-WEB06 ghost]# ll
    total 20576
    -rw-r----- 1 root root      944 Apr 18 14:11 ghost.c
    -rw-r----- 1 root root  4007948 Apr 18 14:11 glibc-2.12-1.209.el6_9.2.x86_64.rpm
    -rw-r----- 1 root root 14924228 Apr 18 14:11 glibc-common-2.12-1.209.el6_9.2.x86_64.rpm
    -rw-r----- 1 root root  1014476 Apr 18 14:11 glibc-devel-2.12-1.209.el6_9.2.x86_64.rpm
    -rw-r----- 1 root root   634508 Apr 18 14:11 glibc-headers-2.12-1.209.el6_9.2.x86_64.rpm
    -rwxr-x--- 1 root root     8309 May 22 10:39 testghost
    -rw-r----- 1 root root   464672 Apr 18 14:11 tzdata-2016j-1.el6.noarch.rpm
    #当前libc版本
    [root@SHQZ-PS-IOT-SV2-WEB06 ~]# rpm -qa|grep glibc
    glibc-common-2.12-1.107.el6.x86_64
    glibc-devel-2.12-1.107.el6.x86_64
    glibc-2.12-1.107.el6.x86_64
    glibc-headers-2.12-1.107.el6.x86_64
    #升级libc到最新版本
    [root@SHQZ-PS-IOT-SV2-WEB06 ghost]# rpm -U *.rpm
    #升级后libc版本
    [root@SHQZ-PS-IOT-SV2-WEB06 ghost]#  rpm -qa|grep glibc
    glibc-2.12-1.209.el6_9.2.x86_64
    glibc-common-2.12-1.209.el6_9.2.x86_64
    glibc-devel-2.12-1.209.el6_9.2.x86_64
    glibc-headers-2.12-1.209.el6_9.2.x86_64
    #验证幽灵漏洞是否修复
    [root@SHQZ-PS-IOT-SV2-WEB06 ghost]# ./testghost 
    not vulnerable
    

    OK,libc升级成功,幽灵漏洞已修复

  • 相关阅读:
    网页Tab控件
    ivy在eclipse中的重新加载
    es删除文档或者删除索引
    es修改数据
    es中插入数据
    创建es索引-格式化和非格式化
    MySQL常用字符串函数
    python各种类型转换
    python 3.4读取输入参数
    python异常捕获异常堆栈输出
  • 原文地址:https://www.cnblogs.com/leekeggs/p/9347370.html
Copyright © 2020-2023  润新知