幽灵漏洞(Ghost gethost)

幽灵漏斗简介:

编号CVE-2015-0235的GHOST(幽灵)漏洞是Qualys研究员发现的一个Linux服务上非常严重的安全漏洞,可以被利用来远程代码执行及本地权限提升。

漏洞简要描述

该漏洞存在于 glic 库中的__nss_hostname_digits_dots() 函数,在nss/getXXbyYY.c这个文件中,gethostbyname()会使用这个功能。另外,这个漏洞本地远程都可以利用,要利用此漏洞,攻击者需要构造一个特定的 hostname 数据条给linux 上开放的服务,如果服务不对数据做安全处理,就会引发一个任意代码执行漏洞。

使用:ls –l /lib/libc.so.*查看本机libc的版本:

image

使用如下代码(来源于网络),测试是否存在漏洞:

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

编译后,执行,发现我们的一台服务器果然存在漏洞:

image

使用如下命令查看有那些进程依赖了libc: lsof | grep libc | awk '{print $1}' | sort | uniq | less

image

使用netstat –lntpu | grep 8080, 发现我们的8080端口依赖了libc,可以看到进程号是:26316

image

这里需要将gcc升级,升级后,漏洞被堵住。

打补丁攻略:

http://www.cyberciti.biz/faq/cve-2015-0235-patch-ghost-on-debian-ubuntu-fedora-centos-rhel-linux/ 

参考:

http://bobao.360.cn/news/detail/1166.html 

http://www.freebuf.com/news/57729.html

https://www.qualys.com/research/security-advisories/GHOST-CVE-2015-0235.txt 

原文地址:https://www.cnblogs.com/justinzhang/p/4267402.html