如何修复并保护 Linux 服务器免受 CentOS 5/6/7 或 RHEL 5/6/7 上的 Dirty Cow 漏洞的影响
本文将介绍如何修复 CentOS/Red Hat 上的 Dirty Cow Linux 漏洞。Dirty Cow Linux 漏洞于 2016 年 10 月 19 日被升级,它是一个 Linux 操作系统内核级别的权限提升漏洞,最初以 Dirty COW 的名称披露,因为 Dirty Cow 会导致内核处理 COW(写时复制)漏洞,而 COW 漏洞由来已久,大多数服务器都面临风险。实际上,在 Redhat 上,该漏洞的编号为 CVE-2016-5195。这可能会影响 Red Hat Enterprises Linux 5、6、7 附带的内核。
"脏牛"漏洞意味着服务器上的普通用户或非特权用户将获得对所有文件的写入权限,并允许读取这些文件,从而增加他们在系统中的访问权限。
由于大多数 Linux 发行版已经发布了针对该漏洞的修复程序,因此无需担心,我们可以参考本文来修复此漏洞。
检查 CentOS/RHEL 机器中的漏洞
为了在 CentOS/RHEL 机器上检查漏洞,我们需要在包含大量 RHEL 和 CentOS 内核的机器上运行以下脚本。
我们可以使用以下链接从 Redhat 代码库下载该脚本
# wget https://access.redhat.com/sites/default/files/rh-cve-2016-5195_1.sh Output: --2016-11-21 11:41:19-- https://access.redhat.com/sites/default/files/rh-cve-2016-5195_1.shResolving access.redhat.com... 104.120.145.18 Connecting to access.redhat.com|104.120.145.18|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 16478 (16K) [application/x-sh] Saving to: “rh-cve-2016-5195_1.sh” 100%[======================================>] 16,478 72.4K/s in 0.2s 2016-11-21 11:41:19 (72.4 KB/s) - “rh-cve-2016-5195_1.sh” saved [16478/16478]
下载文件后,我们需要为脚本添加可执行权限。
# chmod +x rh-cve-2016-5195_1.sh
现在我们将运行脚本,使用刚刚下载的脚本来检测机器是否存在漏洞。
# ./rh-cve-2016-5195_1.sh Output: Your kernel is 2.6.32-642.6.1.el6.x86_64 which IS vulnerable. Red Hat recommends that you update your kernel. Alternatively, you can apply partial mitigation described at https://access.redhat.com/security/vulnerabilities/2706661 .
修复 CentOS/RHEL 上的 Dirty Cow 漏洞
我们可以直接从 RHEL/CentOS 仓库应用修复程序,只需更新内核并重启服务器即可。
以下是更新 CentOS/RHEL 计算机上所有软件包的命令。
# sudo yum update Output: yum update Loaded plugins: fastestmirror, security Setting up Update Process Determining fastest mirrors epel/metalink | 4.9 kB 00:00 * base: mirror.fibergrid.in * epel: epel.scopesky.iq * extras: mirror.fibergrid.in * updates: mirror.fibergrid.in … … Resolving Dependencies --> Running transaction check ---> Package bind-libs.x86_64 32:9.8.2-0.47.rc1.el6_8.1 will be updated ---> Package bind-libs.x86_64 32:9.8.2-0.47.rc1.el6_8.3 will be an update ---> Package bind-utils.x86_64 32:9.8.2-0.47.rc1.el6_8.1 will be updated ---> Package bind-utils.x86_64 32:9.8.2-0.47.rc1.el6_8.3 will be an update ---> Package httpd.x86_64 0:2.2.15-54.el6.centos will be updated ---> Package httpd.x86_64 0:2.2.15-55.el6.centos.2 will be an update ---> Package httpd-tools.x86_64 0:2.2.15-54.el6.centos will be updated ---> Package httpd-tools.x86_64 0:2.2.15-55.el6.centos.2 will be an update ---> Package java-1.7.0-openjdk.x86_64 1:1.7.0.111-2.6.7.2.el6_8 will be updated ---> Package java-1.7.0-openjdk.x86_64 1:1.7.0.121-2.6.8.1.el6_8 will be an upda te … kamailio-debuginfo.x86_64 0:4.4.4-1.1 kamailio-mysql.x86_64 0:4.4.4-1.1 kamailio-unixodbc.x86_64 0:4.4.4-1.1 kernel-firmware.noarch 0:2.6.32-642.11.1.el6 kernel-headers.x86_64 0:2.6.32-642.11.1.el6 kexec-tools.x86_64 0:2.0.0-300.el6_8.1 libblkid.x86_64 0:2.17.2-12.24.el6_8.1 libgcrypt.x86_64 0:1.4.5-12.el6_8 libuuid.x86_64 0:2.17.2-12.24.el6_8.1 nss.x86_64 0:3.21.3-2.el6_8 nss-sysinit.x86_64 0:3.21.3-2.el6_8 nss-tools.x86_64 0:3.21.3-2.el6_8 nss-util.x86_64 0:3.21.3-1.el6_8 perf.x86_64 0:2.6.32-642.11.1.el6 policycoreutils.x86_64 0:2.0.83-30.1.el6_8 selinux-policy.noarch 0:3.7.19-292.el6_8.2 selinux-policy-targeted.noarch 0:3.7.19-292.el6_8.2 tzdata.noarch 0:2016i-1.el6 tzdata-java.noarch 0:2016i-1.el6 util-linux-ng.x86_64 0:2.17.2-12.24.el6_8.1 Complete!
更新完成后,我们需要重启机器以使更新生效,以下是重启机器的命令。
# sudo reboot
更新后验证系统内核更新
由于我们已经升级了软件包并针对 DirtyCow 漏洞更新了机器,因此我们需要检查内核是否已升级,以下是验证命令。
我们可以运行前面步骤中下载的脚本来检查漏洞,或者您可以运行以下命令 –
./rh-cve-2016-5195_1.sh 输出: Your kernel is 2.6.32-642.11.1.el6.x86_64 which is NOT vulnerable.
我们可以看到,脚本显示该机器不存在漏洞。
# uname -r 输出: 2.6.32-642.11.1.el6.x86_64
我们可以看到,内核已从 2.6.32-642.6.1.el6.x86_64 更新至 2.6.32-642.11.1.el6.x86_64,因此该 Linux 机器不会受到 Dirty Cow 漏洞的影响。
在上文中,我们学习了如何使用 RHEL 中的脚本检查 CentOS / RHEL Linux 机器上的 Dirty Cow 漏洞,以及如何修复 Dirty Cow 漏洞并在修复后进行验证。更新。

