如何修复Linux CVE-2015-0235 Glibc GHOST漏洞
时间:2019-11-20 08:53:54 来源:igfitidea点击:
如何修复GHOST漏洞?
GNU C库(Glibc)CVE-2015-0235漏洞如何修复?
什么是GHOST安全错误?
在__nss_hostname_digits_dots()中发现了基于堆的缓冲区溢出,gethostbyname()和gethostbyname2()glibc函数调用使用了该溢出。远程攻击者可以利用此漏洞在运行应用程序的用户许可下执行任意代码。
如何查看Linux使用哪个版本的Glibc?
查看Glibc版本号
ldd --version
RHEL/CentOS Linux v6.6的示例输出:
ldd (GNU libc) 2.17 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.
受影响的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
如果没有漏洞,输出:
vulnerable
如果有漏洞,还没有打补丁:
#!/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
CentOS/RHEL系统脚本
如果是CentOS/RHEL系统,还可以使用下面的脚本进行测试:
lsof | grep libc | awk '{print }' | sort | uniq
查看受Glibc漏洞影响的程序?
执行以下lsof命令:
awk bash grep lsof sort uniq
输出示例:
sudo yum clean all sudo yum update
在CentOS/RHEL/Fedora/Scientific Linux上修复GHOST漏洞
以root用户身份执行以下yum命令:
sudo reboot
然后,重启RHEL/SL/Fedora/CentOS Linux服务器:
sudo apt-get clean sudo apt-get update sudo apt-get upgrade ## 如果也想升级内核才允许下面的 dist-upgrade 命令 ##sudo apt-get dist-upgrade
在Ubuntu Linux上修复GHOST漏洞
以root用户身份执行以下apt-get命令:
sudo reboot
重启Ubuntu Linux服务器:
sudo apt-get clean sudo apt-get update sudo apt-get upgrade
在Debian Linux上修复GHOST漏洞
以root用户身份执行以下apt-get命令:
sudo reboot
重启Debian Linux服务器:
zypper in -t patch sdksp3-glibc-10206
修复SUSE Linux Enterprise上的GHOST漏洞
使用YaST online_update安装SUSE安全更新。
或者根据不同版本执行以下不同命令:
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漏洞
查看可用更新的列表:
# zypper up
进行更新:
##代码##
