手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

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

[日期:2015-01-29] 来源:Linux社区  作者:simeon [字体: ]

一、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 <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
 
#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.<https://access.RedHat.com/security/cve/CVE-2015-0235>
Pleaserefer to <https://access.redhat.com/articles/1332213> for remediationsteps

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

相关阅读

危险!GHOST(幽灵)漏洞曝光  http://www.linuxidc.com/Linux/2015-01/112496.htm

GNU glibc 爆 gethostbyname 缓冲区溢出漏洞  http://www.linuxidc.com/Linux/2015-01/112486.htm

glibc gethostbyname缓冲区溢出漏洞(CVE-2015-0235)  http://www.linuxidc.com/Linux/2015-01/112516.htm

本文永久更新链接地址http://www.linuxidc.com/Linux/2015-01/112562tm

linux
相关资讯       glibc  glibc漏洞  幽灵漏洞 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款