您的位置:首页 > 运维架构 > Shell

Bash bug漏洞目前最新最全的修复方式

2014-09-28 18:31 627 查看
Bash bug漏洞已经爆过2天时间,安全狗安全团队已经第一时间向广大用户进行预警。但由于Bash在Linux系统的广泛应用导致众多Linux系统相关主机和设备受到该漏洞的威胁,目前仍有众多服务器主机和设备还未修复该漏洞问题。

由于Bash被应用到到Linux操作系统各个层面的应用,包括OpenSSH、Web Server、系统命令等,单靠某个点的安全防御方案可能无法解决所有问题。针对以上情况,安全狗研究团队整理了目前最新最全的漏洞修复方案。

1、 目前最新最全的修复方式

(1) 更新Bash Shell补丁(优先推荐)

Linux系统产商官方已经更新了最新补丁,解决之前补丁仍存在绕过的问题。安全狗研究团队会第一时间更新,请继续关注

(注意:请您根据Linux版本选择您需要修复的命令, 为了防止意外情况发生,建议您执行命令前先对Linux服务器系统盘打个快照,如果万一出现升级影响您服务器使用情况,可以通过回滚系统盘快照解决。)

更新资源:

GNU官方补丁所在地址:
http://ftp.gnu.org/pub/gnu/bash/bash-3.0-patches/bash30-018

http://ftp.gnu.org/pub/gnu/bash/bash-3.1-patches/bash31-019

http://ftp.gnu.org/pub/gnu/bash/bash-3.2-patches/bash32-053

http://ftp.gnu.org/pub/gnu/bash/bash-4.0-patches/bash40-040

http://ftp.gnu.org/pub/gnu/bash/bash-4.1-patches/bash41-013

http://ftp.gnu.org/pub/gnu/bash/bash-4.2-patches/bash42-049

http://ftp.gnu.org/pub/gnu/bash/bash-4.3-patches/bash43-026

各大发行版的解决方法:

RedHat/ Fedora
官方修复链接:https://bugzilla.redhat.com/show_bug.cgi?id=CVE-2014-6271
查看:https://rhn.redhat.com/errata/RHSA-2014-1306.html
yum clean all
yum makecache #这两步一般不用

yum -y update bash

centos:
yum clean all
yum makecache #这两步一般不用

yum -y update bash

ubuntu:
官方修复链接:http://www.ubuntu.com/usn/usn-2363-2/
apt-get update
apt-get -y install --only-upgrade bash

debian:
官方修复链接:https://www.debian.org/security/2014/dsa-3035
参考:
http://www.debiantutorials.com/how-to-detect-if-your-server-is-vulnerable-to-the-shellshock-bug-and-fix-it/
sudo apt-get update
sudo apt-get -y install --only-upgrade bash
apt-get -y install --only-upgrade bash

Old version修复方法:
6.0.x 64bit
wget http://mirrors.aliyun.com/debian ... %2bdeb6u1_amd64.deb && dpkg -i bash_4.1-3+deb6u1_amd64.deb
6.0.x 32bit
wget http://mirrors.aliyun.com/debian ... 3%2bdeb6u1_i386.deb && dpkg -i bash_4.1-3+deb6u1_i386.deb

Opensuse
官方修复链接:http://bugzilla.opensuse.org/show_bug.cgi?id=CVE-2014-6271
Other 修复方法:
13.1 64bit
wget http://mirrors.aliyun.com/fix_stuff/bash-4.2-68.4.1.x86_64.rpm && rpm -Uvh
bash-4.2-68.4.1.x86_64.rpm
13.1 32bit
wget http://mirrors.aliyun.com/fix_stuff/bash-4.2-68.4.1.i586.rpm && rpm -Uvh
bash-4.2-68.4.1.i586.rpm

SUSE linux
官方修复链接:https://bugzilla.suse.com/show_bug.cgi?id=CVE-2014-6271
查看 http://support.novell.com/security/cve/CVE-2014-6271.html

Gentoo:
sudo emerge --sync && glsa-check -f affected

aliyun linux:
5.x 64bit
wget http://mirrors.aliyun.com/centos ... .2-33.el5.1.x86_64.
rpm && rpm -Uvh bash-3.2-33.el5.1.x86_64.rpm
5.x 32bit
wget http://mirrors.aliyun.com/centos ... 2-33.el5.1.i386.rpm && rpm -Uvh bash-3.2-33.el5.1.i386.rpm

其他发行版也可以参照上面的方法自行编译,或者通过发行版内置的包管理器来更新bash

(2) 更新安全防护规则

安全狗用户:更新安全狗最新规则即可防御针对Apache WEB服务器、操作系统命令相关的攻击

WEB 防火墙用户:使用各个安全产商WEB防火墙(硬件WEB防火墙、CDN云防火墙)的用户开启防护并更新到最新规则,可防止针对WEB服务器的攻击。(仅使用WEB防火墙的防护无法防止针对Linux系统其他应用的攻击)

硬件IDS防火墙用户:更新防火墙最新的规则,可防止相应的攻击

使用mod_security的用户:

以下mod_security规则可以拒绝使用HTTP请求包含的数据解释的Bash函数定义如果设置在其环境。他们可以用来阻止攻击web服务,如攻击CGI应用程序。

Request Header values:
SecRule REQUEST_HEADERS "^\(\) {" "phase:1,deny,id:1000000,t:urlDecode,status:400,log,msg:'CVE-2014-6271 - Bash Attack'"

SERVER_PROTOCOL values:
SecRule REQUEST_LINE "\(\) {" "phase:1,deny,id:1000001,status:400,log,msg:'CVE-2014-6271 - Bash Attack'"

GET/POST names:
SecRule ARGS_NAMES "^\(\) {"
"phase:2,deny,id:1000002,t:urlDecode,t:urlDecodeUni,status:400,log,msg:'CVE-2014-6271 - Bash Attack'"

GET/POST values:
SecRule ARGS "^\(\) {"
"phase:2,deny,id:1000003,t:urlDecode,t:urlDecodeUni,status:400,log,msg:'CVE-2014-6271 - Bash Attack'"

File names for uploads:
SecRule FILES_NAMES "^\(\) {"
"phase:2,deny,id:1000004,t:urlDecode,t:urlDecodeUni,status:400,log,msg:'CVE-2014-6271 - Bash Attack'"

It
is possible, however unlikely, that these rules may result in false
positives. These false positives, along with actual attempts, could
result in log files of significant size.

修复OpenSSH存在的问题:

1、更新系统的bash
2、加入no-pty选项,防止用户利用漏洞分配tty(详细配置参考http://oreilly.com/catalog/sshtdg/chapter/ch08.html中Forced Commands的安全配置)

采用IPtable进行简单防御:

可以使用IPTables字符串匹配试图减少数据包,可以预防一部分的攻击,规则比较死不灵活
# iptables -A INPUT -m string --algo bm --hex-string '|28 29 20 7B|' -j DROP
# ip6tables -A INPUT -m string --algo bm --hex-string '|28 29 20 7B|' -j DROP

2、Bash Bug漏洞相关细节分析

Red Hat安全团队在 Linux 中广泛使用的Bash shell中发现了一个隐晦而危险的安全漏洞(漏洞参考https://access.redhat.com/security/cve/CVE-2014-6271;https://access.redhat.com/articles/1200223 )。该漏洞被称为“Bash Bug”或“Shellshock”。黑客可以利用该Bash漏洞完全控制目标系统并发起攻击,为了避免您Linux服务器受影响,建议您尽快完成漏洞修补。

虽然该漏洞危害比较大,但利用比较困难,环境有限,但你需要在特殊情况下来酝酿攻击–远程用户有权限设置环境变量,影响不会那么大。由于bug比较古老有漏洞的系统数量特别巨大,全部打上补丁是件不太可能的事。

【已确认被成功利用的软件及系统】
所有安装GNU bash 版本小于或者等于4.3的Linux操作系统。

【漏洞描述】
该漏洞源于你调用的bash shell之前创建的特殊的环境变量,这些变量可以包含代码,同时会被bash执行。
攻击者可以提供特别制造环境变量注入任意命令代码,将在脆弱的系统在一定条件下执行

【漏洞检测方法】
Redhat官方提供检测方式
运行命令:
env x='() { :;};echo vulnerable' bash -c "echo this is a test"

如果返回如下内容,则请尽快升级。
vulnerable
this is a test

file:///C:\Users\ADMINI~1\AppData\Local\Temp\ksohtml\wps20C9.tmp.png

使用修补方案修复后
bash: warning: x: ignoring function definition attempt
bash: error importing function definition for `x'
this is a test

提示:如果您的脚本使用以上方式定义环境变量,正确修复后您的脚本执行会报错。

【bash漏洞原理】

BASH除了可以将shell变量导出为环境变量,还可以将shell函数导出为环境变量,bash通过以函数名作为环境变量名,以“(){”开头的字串作为环境变量的值来将函数定义导出为环境变量。

此次爆出的漏洞是BASH处理这样的“函数环境变量”的时候,并没有以函数结尾“}”作为结束,而是会一直执行其后的shell命令。

开发者可以通过包含特定代码的环境变量来编写 bash shell,当 shell 被调用的时候这些代码也会被执行。例如下面设置环境变量:
VAR=() { ignored; }; /bin/id

将执行/bin/id,当环境变量变量被导入到bash 进程的时候。(进程会再一个未定义的状态。PATH变量可能没有被设置,和执行/bin/id后bash可能崩溃,但危害已经发生在这点)

目前实际的例子说明:

接受HTTP命令的CGI Shell脚本是最主要的被攻击对象。

一个常见的HTTP请求是这样:
GET /path?query-param-name=query-param-value HTTP/1.1
Host: www.example.com
Custom: custom-header-value

根据CGI标准将http请求的所有参数都映射到了环境变量。

例如对于Apache的Httpd,字串“(){”可以出现在以下这些地方:

* Host (“www.example.com”, as REMOTE_HOST)
* Header value (“custom-header-value”, as HTTP_CUSTOM in this example)
* Server protocol (“HTTP/1.1”, as SERVER_PROTOCOL)

通过自定义这些参数的值为“函数环境变量”的形式并注入任意命令代码,就可以远程执行命令,

例如:
curl -H X: () { :;}; echo test http://xxxxx/test.sh
CGI 将X映射到环境变量的时候,就会执行“echo test”

详情可参考:http://seclists.org/oss-sec/2014/q3/650
Bash bug远程利用的方法可参考:http://www.freebuf.com/vuls/44994.html

【影响系统】


个问题影响到所有产品使用Bash
shell和解析环境变量的值。这个问题尤其危险,有很多可能的Bash可以由应用程序调用的方法。通常如果一个应用程序执行另一个二进制,Bash调用
来完成这一任务。由于普遍使用Bash shell,这个问题很严重,应该得到大家的关注。

Rehat官方提供的部分列表,目前还有更多的受影响程序和利用方式正在不断地被发掘出来:
Package
Description
httpd
CGI
scripts are likely affected by this issue: when a CGI script is run by
the web server, it uses environment variables to pass data to the
script. These environment variables can be controlled by the attacker.
If the CGI script calls Bash, the script could execute arbitrary code as
the httpd user. mod_php, mod_perl, and mod_python do not use
environment variables and we believe they are not affected.
Secure Shell (SSH)
It
is not uncommon to restrict remote commands that a user can run via
SSH, such as rsync or git. In these instances, this issue can be used to
execute any command, not just the restricted command.
dhclient
The
Dynamic Host Configuration Protocol Client (dhclient) is used to
automatically obtain network configuration information via DHCP. This
client uses various environment variables and runs Bash to configure the
network interface. Connecting to a malicious DHCP server could allow an
attacker to run arbitrary code on the client machine.
CUPS
It
is believed that CUPS is affected by this issue. Various user supplied
values are stored in environment variables when cups filters are
executed.
sudo
Commands run via sudo are not affected by
this issue. Sudo specifically looks for environment variables that are
also functions. It could still be possible for the running command to
set an environment variable that could cause a Bash child process to
execute arbitrary code.
Firefox
We do not believe Firefox
can be forced to set an environment variable in a manner that would
allow Bash to run arbitrary commands. It is still advisable to upgrade
Bash as it is common to install various plug-ins and extensions that
could allow this behavior.
Postfix
The Postfix server will
replace various characters with a ?. While the Postfix server does call
Bash in a variety of ways, we do not believe an arbitrary environment
variable can be set by the server. It is however possible that a filter
could set environment variables.

在sshd配置中使用了ForceCommand用以限制远程用户执行命令,这个漏洞可以绕过限制去执行任何命令。一些Git和Subversion部署环境的限制Shell也会出现类似情况,OpenSSH通常用法没有问题。

Apache
服务器使用mod_cgi或者mod_cgid,如果CGI脚本在BASH或者运行在子SHELL里都会受影响。子Shell中使用C的
system/popen,Python中使用
os.system/os.popen,PHP中使用system/exec(CGI模式)和Perl中使用,open/system的情况都会受此漏洞
影响。

PHP脚本执行在mod_php不会受影响。

DHCP客户端调用shell脚本接收远程恶意服务器的环境变量参数值的情况会被此漏洞利用。

守护进程和SUID程序在环境变量设置的环境下执行SHELL脚本也可能受到影响。

任何其他程序执行SHELL脚本时用BASH作为解释器都可能受影响。Shell脚本不导出的情况下不会受影响。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息