幽灵漏洞

幽灵漏洞(CVE-2015-0235)

1.    漏洞说明

1.1.           漏洞原理

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

1.2.           漏洞危害

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

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

1、  存在漏洞系统中存在使用gethostbyname*() 函数的程序

2、  程序必须能接收攻击者发送的数据,并且将数据作为gethostbyname*()的参数

3、  攻击者发送的攻击数据(亦作:payload,载荷)必须符合特定条件,如下:

  1. Payload 首字符必须为数字

  2. Payload 最后字符不能为点号

  3. Payload 中只能包含数字和点号

  4. Payload 必须符合ipv4或者ipv6的地址格式

  5. Payload 必须足够长,具体长度需要攻击者不断尝试来确定影响范围

1、该漏洞影响使用GNU libc库版本2.2-2.17Linux操作系统

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 �Co testghost指令编译,会生成testghost

第三、   使用 ./testghost 执行漏洞测试程序,如果程序输出vulnerable 则说明存在漏洞

                            spacer.gif

2.1.           漏洞验证代码spacer.gif

#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;

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

}

3.    修复方法

   执行GNU libc升级命令,将linux中的libc 升级到最新版本,另外在升级完libc后需要重启系统。

1、针对 RHFedoraCentOS系统

执行 yum install glibc &&reboot 更新GNU  libc

2、针对 DebianUbuntu系统

执行 apt-get clean && apt-getupdate && apt-get upgrade 更新GNU  libc

 


本文出自 “10656918” 博客,谢绝转载!

你可能感兴趣的:(幽灵漏洞)