如何针对Glibc GHOST漏洞修补和保护Linux服务器#CVE-2015-0235
在名为GHOST的GNU C库(Glibc)中发现了一个非常严重的安全问题。
如何修复GHOST漏洞并保护Linux服务器免受攻击?
如何验证我的服务器已针对Glibc GHOST漏洞进行了修复?
在一个名为Glibc的GNU C库中发现并修补了一个非常严重的安全问题。
什么是GHOST安全错误?
在__nss_hostname_digits_dots()中发现了基于堆的缓冲区溢出,gethostbyname()和gethostbyname2()glibc函数调用使用了该溢出。
远程攻击者可以利用此漏洞在运行应用程序的用户许可下执行任意代码。
查看Linux系统使用哪个C库(Glibc)版本?
检查版本号的最简单方法是运行以下命令:
ldd --version
RHEL/CentOS Linux v6.6的示例输出:
ldd (GNU libc) 2.12 Copyright (C) 2010 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Roland McGrath and Ulrich Drepper.
Ubuntu Linux 12.04.5 LTS的示例输出:
ldd (Ubuntu EGLIBC 2.15-0ubuntu10.9) 2.15 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Roland McGrath and Ulrich Drepper.
Debian Linux v7.8的示例输出:
ldd (Debian EGLIBC 2.13-38+deb7u6) 2.13 Copyright (C) 2011 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Roland McGrath and Ulrich Drepper.
受影响的Linux发行版列表
- RHEL(Red Hat Enterprise Linux)版本5.x,6.x和7.x
- CentOS Linux版本5.x,6.x和7.x
- Ubuntu Linux版本10.04、12.04 LTS
- Debian Linux版本7.x
- Linux Mint版本13.0
- Fedora Linux版本19或更低版本
- SUSE Linux Enterprise 11和更早版本(还包括OpenSuse Linux 11或更早版本)。
- SUSE Linux Enterprise软件开发套件11 SP3
- 适用于VMware的SUSE Linux Enterprise Server 11 SP3
- SUSE Linux Enterprise Server 11 SP3
- SUSE Linux Enterprise Server 11 SP2 LTSS
- SUSE Linux Enterprise Server 11 SP1 LTSS
- SUSE Linux Enterprise Server 10 SP4 LTSS
- SUSE Linux Enterprise Desktop 11 SP3
- Arch Linux glibc版本
GHOST漏洞检查
您可以使用以下C代码测试或重现该错误:
/* ghosttest.c: GHOST vulnerability tester */
/* Credit: http://www.openwall.com/lists/oss-security/2015/01/27/9 */
#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] = '$ gcc ghosttest.c -o ghosttest
$ ./ghosttest
';
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);
}
编译并运行如下:
not vulnerable
修补的Debian v7.8服务器的示例输出:
vulnerable
未打补丁的Ubuntu 12.04 LTS服务器的示例输出:
lsof | grep libc | awk '{print }' | sort | uniq
列出程序包/应用程序如何取决于易受攻击的Glibc?
执行以下lsof命令:
sudo yum clean all sudo yum update
我的Debian Linux v7.x nas的输出示例:
Linux查找依赖于GNU C库(Glibc)命令的所有服务/应用程序
修复CentOS/RHEL/Fedora/Scientific Linux上的GHOST漏洞
以root用户身份执行以下yum命令:
### Sysadmin should plan on updating as soon as possible or use maintenance reboot window ## sudo reboot
最后,通过执行以下命令来重新启动RHEL/SL/Fedora/CentOS Linux服务器:
sudo apt-get clean sudo apt-get update sudo apt-get upgrade ## only run dist-upgrade on a Ubuntu if you want to upgrade kernel too ##sudo apt-get dist-upgrade
输出示例:
在CentOS/RHEL/Fedora/Scientific Linux上修复了GHOST漏洞
修复Ubuntu Linux上的GHOST漏洞
以root用户身份执行以下apt-get命令:
sudo reboot
最后,通过执行以下命令来重启Ubuntu Linux服务器:
sudo apt-get clean sudo apt-get update sudo apt-get upgrade ##No need to do dist-upgrade (see man page: man apt-get) ##sudo apt-get dist-upgrade
输出示例:
修复Ubuntu Linux LTS上的GHOST漏洞
修复Debian Linux上的GHOST漏洞
以root用户身份执行以下apt-get命令:
sudo reboot
最后,通过执行以下命令来重启Debian Linux服务器:
zypper in -t patch sdksp3-glibc-10206
会话示例:Gif 01:修复了Debian Linux服务器上的GHOST漏洞
修复SUSE Linux Enterprise上的GHOST漏洞
要安装此SUSE安全更新,请使用YaST online_update。
或根据您的版本使用以下命令:
SUSE Linux企业软件开发套件11 SP3
zypper in -t patch slessp3-glibc-10206
适用于VMware的SUSE Linux Enterprise Server 11 SP3
zypper in -t patch slessp3-glibc-10206
SUSE Linux Enterprise Server 11 SP3
zypper in -t patch slessp2-glibc-10204
SUSE Linux Enterprise Server 11 SP2 LTSS
zypper in -t patch slessp1-glibc-10202
SUSE Linux Enterprise Server 11 SP1 LTSS
zypper in -t patch sledsp3-glibc-10206
SUSE Linux Enterprise Desktop 11 SP3
zypper patch
最后,针对所有SUSE linux版本运行,以使您的系统最新:
# zypper lu
修复OpenSUSE Linux上的GHOST漏洞
要查看可用更新的列表,包括OpenSUSE Linux上的glibc,请输入:
# zypper up
要使用更新的可用版本简单地更新已安装的glibc软件包,请运行:
$ ldd --version
重新启动后如何验证我的Linux系统不再脆弱?
方法1:检查漏洞和/或确认补救的最简单方法是运行以下命令,以验证您正在运行Glibc的更新版本:
#!/bin/bash
# rhel-GHOST-test.sh - GHOST vulnerability tester. Only for CentOS/RHEL based servers. #
# Version 3
# Credit : Red Hat, Inc - https://access.redhat.com/labs/ghost/ #
echo "Installed glibc version(s)"
rv=0
for glibc_nvr in $( rpm -q --qf '%{name}-%{version}-%{release}.%{arch}\n' glibc ); do
glibc_ver=$( echo "$glibc_nvr" | awk -F- '{ print }' )
glibc_maj=$( echo "$glibc_ver" | awk -F. '{ print }')
glibc_min=$( echo "$glibc_ver" | awk -F. '{ print }')
echo -n "- $glibc_nvr: "
if [ "$glibc_maj" -gt 2 -o \
\( "$glibc_maj" -eq 2 -a "$glibc_min" -ge 18 \) ]; then
# fixed upstream version
echo 'not vulnerable'
else
# all RHEL updates include CVE in rpm %changelog
if rpm -q --changelog "$glibc_nvr" | grep -q 'CVE-2015-0235'; then
echo "not vulnerable"
else
echo "vulnerable"
rv=1
fi
fi
done
if [ $rv -ne 0 ]; then
cat <<EOF
This system is vulnerable to CVE-2015-0235. <https://access.redhat.com/security/cve/CVE-2015-0235>
Please refer to <https://access.redhat.com/articles/1332213> for remediation steps
EOF
fi
exit $rv
方法2:执行上一节GHOST漏洞检查(所有基于Linux的系统的通用方法)中给出的说明。
方法3:如果您是RHN订户,请参阅Red Hat Access Lab:GHOST工具(仅适用于RHEL/CentOS/SL系统下载链接):
bash rhel-GHOST-test.sh Installed glibc version(s) - glibc-2.12-1.149.el6_6.5.x86_64: not vulnerable - glibc-2.12-1.149.el6_6.5.i686: not vulnerable
修补的RHEL v6.8服务器的示例输出:
##代码##
