Bash安全缺陷验证及修复方法
----UCloud云计算团队
一、漏洞概述
在GNU bash环境变量中定义一个函数之后,如果后续还有其它字符串,bash在解析这些字符串的时候存在一个缺陷,允许远程攻击者执行任意的命令,只要攻击者 构建一个特殊的环境变量即可。攻击者可以利用此缺陷重写或绕过环境变量的限制执行shell命令,从而导致信息泄漏、未授权的恶意修改、服务中断。
下面是验证过程:
[root@10-4-2-230 test]# ls
[root@10-4-2-230 test]# env -i X='() { (a)=>\' bash -c 'echo touch google'
bash: X: line 1: syntax error near unexpected token `='
bash: X: line 1: `'
bash: error importing function definition for `X'
[root@10-4-2-230 test]# ls
echo google
二、受影响版本
目前GNU bash4.3及以下版本存在此问题。
三、利用场景
如下业务场景中都会受此缺陷影响:
1、OpenSSH sshd使用了ForceCommand特性
ForceCommand特性用来给远程用户提供受限的命令执行能力,因此使用了此特性的如git、subversion等都会受影响。
2、Apache HTTP Server使用了modcgi和mod_cgid模块;
在Apache Server启用了modcgi和mod_cgid模块时,只要CGI脚本是由bash编写,或者使用了派生的subshell都会受影响。能够产生这样的subshell的包括:
C语言的system/popen,Python的os.system/os.popen,PHP的system/exec,Perl的open/system。
四、修复方法
yum clean all
yum --enablerepo=updates install bash
五、验证方法
验证是否存在次漏洞的方法:
[root@10-4-2-230 test]# env x='() { :;}; echo vulnerable' bash -c "echo this is a test”
vulnerable
this is a test
漏洞修复之后,再执行该命令:
[root@10-4-2-230 test]# env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
bash: warning: x: ignoring function definition attempt
bash: error importing function definition for `x'
this is a test
六、参考链接
https://www.invisiblethreat.ca/2014/09/cve-2014-6271/