Linuxglibc幽靈漏洞測試與修複方法
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-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
據360安全公司研究人員分析Linuxglibc幽靈漏洞最容易的攻擊入口是郵件伺服器,和存在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,或者wget http://www.antian365.com/lab/linux0day/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");
puts("should not happen");
exit(EXIT_FAILURE);
}
直接編譯并執行: gcc ghost.c-o ghost && ./ghost 如果存在漏洞則會顯示“vulnerable”,如圖2所示。
也可以執行下面的指令,以檢測是否存在漏洞
方法一:
rpm -qglibc
cat/etc/issue
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個安裝包,安裝完成後需要重新開機計算機。
參考資料
-against-the-ghost-vulnerability
本文轉自 simeon2005 51CTO部落格,原文連結:http://blog.51cto.com/simeon/1609466