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

Bash bug漏洞已經爆過2天時間,安全狗安全團隊已經第一時間向廣大用戶進行預警。但因爲Bash在Linux系統的普遍應用致使衆多Linux系統相關主機和設備受到該漏洞的威脅,目前仍有衆多服務器主機和設備還未修復該漏洞問題。

因爲Bash被應用到到Linux操做系統各個層面的應用,包括OpenSSH、Web Server、系統命令等,單靠某個點的安全防護方案可能沒法解決全部問題。針對以上狀況,安全狗研究團隊整理了目前最新最全的漏洞修復方案。

一、 目前最新最全的修復方式

(1) 更新Bash Shell補丁(優先推薦)

Linux系統產商官方已經更新了最新補丁,解決以前補丁仍存在繞過的問題。安全狗研究團隊會第一時間更新,請繼續關注

(注意:請您根據Linux版本選擇您須要修復的命令, 爲了防止意外狀況發生,建議您執行命令前先對Linux服務器系統盤打個快照,若是萬一出現升級影響您服務器使用狀況,能夠經過回滾系統盤快照解決。)

更新資源:

GNU官方補丁所在地址:







各大發行版的解決方法:

RedHat/  Fedora
yum clean all
yum makecache   # 這兩步通常不用


yum -y update bash

centos:
yum clean all
yum makecache   # 這兩步通常不用

yum -y update bash

ubuntu:
apt-get update
apt-get -y install --only-upgrade bash


debian:
參考:
  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
Other  修復方法:
13.1 64bit
bash-4.2-68.4.1.x86_64.rpm
13.1 32bit
bash-4.2-68.4.1.i586.rpm

SUSE linux

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


aliyun linux:
5.x 64bit
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存在的問題:

一、更新系統的bash
二、加入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

二、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」

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腳本不導出的狀況下不會受影響。
相關文章
相關標籤/搜索