環境
MacOSX Mavericks 10.9.5
例のやつ
http://qiita.com/DQNEO/items/c9f1dc08f93dd6c28740
$ env x='() { :;}; echo this bash is vulnerable' bash -c :
出力
this bash is vulnerable
情報
パス
$ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
バージョン
$ /bin/bash --version
GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
Copyright (C) 2007 Free Software Foundation, Inc.
場所
$ which bash
/bin/bash
$ ls -l /bin/bash
-r-xr-xr-x 1 root wheel 1228240 11 1 2013 /bin/bash
$ which sh
/bin/sh
$ ls -l /bin/sh
-r-xr-xr-x 1 root wheel 1228304 11 1 2013 /bin/s
セットアップ
xcode
$ xcode-select --install
brewからbashインストール
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew doctor
$ brew update
$ brew install bash
or
$ brew upgrade bash
インストール先を確認
$ brew info bash
bash: stable 4.3.27 (bottled), HEAD
http://www.gnu.org/software/bash/
/usr/local/Cellar/bash/4.3.27 (59 files, 7.4M) *
...
必ずbrew info bashして場所を確認すること。(注:コピペで作業する人向け)
2014/09/29現在のバージョンは4.3.27だが、今後バージョンが上がった場合、以下の手順に記したパスの情報が変わってくるため。
バックアップ
$ sudo mv /bin/bash /bin/bash_old
$ sudo mv /bin/sh /bin/sh_old
$ sudo chmod a-x /bin/bash_old /bin/sh_old
ここでバックアップをとっておくと、最悪の事態を回避できるので騙されたと思ってバックアップ。
次のリンクでパスをミスったりして、ターミナルが動作おかしい→ターミナル再起動しても作業できない→慌ててOSを再起動→ログインさえできないorzになってもコマンド+Rを押さえて再起動してターミナル起動させて上記の逆をやると救われる。(注:コピペで作業する人がいるだろうから)
リンク
$ sudo ln -s /usr/local/Cellar/bash/4.3.27/bin/bash /bin/bash
$ sudo ln -s /usr/local/Cellar/bash/4.3.27/bin/bash /bin/sh
4.3.27は2014/09/29現在のバージョンなので、バージョンが上がったら変更する箇所。
ターミナルを再起動
バージョンの確認
$ bash --version
GNU bash, バージョン 4.3.27(1)-release (x86_64-apple-darwin13.4.0)
...
追試
$ env x='() { :;}; echo this bash is vulnerable' bash -c :
何も表示されなければOK
参考
macosx - How to patch Bash on OSX in wake of "shellshock"? - Information Security Stack Exchange
更新
公式版ようやくきました。
OS X bash Update 1.0 – OS X Mavericks
更新_2014/10/02
GNU Project Archivesに2014/10/01付けで4.3.28が来てました。
ただ、bashcheck(hannob/bashcheck · GitHub)するとチョット残っているようです。
$ ./bashcheck
Testing /bin/bash ...
GNU bash, バージョン 4.3.28(1)-release (x86_64-apple-darwin13.4.0)
Not vulnerable to CVE-2014-6271 (original shellshock)
Not vulnerable to CVE-2014-7169 (taviso bug)
Not vulnerable to CVE-2014-7186 (redir_stack bug)
Test for CVE-2014-7187 not reliable without address sanitizer
Vulnerable to CVE-2014-6277 (lcamtuf bug #1) [no patch]
Vulnerable to CVE-2014-6278 (lcamtuf bug #2) [prefix/%%-suffix]
Variable function parser inactive, likely safe from unknown parser bugs
CVE-2014-6277 と CVE-2014-6278
lcamtuf's blog: Bash bug: apply Florian's patch now (CVE-2014-6277 and CVE-2014-6278)
$ foo='() { echo not patched; }' bash -c foo
上記を入力することで大丈夫かどうかチェックできるようです。
If the command shows "not patched", you don't have the patch and you are still vulnerable to a (currently non-public) RCE, even if you applied the original one (or the subsequent upstream patch that addressed the issue found by Tavis).
Oh, and if it shows "command not found", you're good.
4.3.28でやってみたところ、
$ foo='() { echo not patched; }' bash -c foo
bash: foo: コマンドが見つかりません
問題なさそうです・・・かな?
追記(CVE-2014-6277/6278について)
hannob/bashcheck · GitHubに更新があり、それだとnon-exploitableが表示されるようになりました。(表示はexplitableと出るけどexploitableだと思うので、書き換えています。)
$ ./bashcheck
Testing /bin/bash ...
GNU bash, バージョン 4.3.28(1)-release (x86_64-apple-darwin13.4.0)
Variable function parser pre/suffixed [%%, upstream], bugs not explitable
Not vulnerable to CVE-2014-6271 (original shellshock)
Not vulnerable to CVE-2014-7169 (taviso bug)
Not vulnerable to CVE-2014-7186 (redir_stack bug)
Test for CVE-2014-7187 not reliable without address sanitizer
Found non-exploitable CVE-2014-6277 (lcamtuf bug #1)
Found non-exploitable CVE-2014-6278 (lcamtuf bug #2)
追記_2014/10/05
『GNU bash の脆弱性に関する注意喚起』より
https://www.jpcert.or.jp/at/2014/at140037.html
表1 脆弱性の検証結果
CVE番号|想定される影響|4.3.24|4.3.25|4.3.26|4.3.27|4.3.28|4.3.29|(参考)ディストリビュータにより配布されているバージョン(CentOS 6.4)
:----:|----|:-----:|:-:|:-:|:-:|:-:|:-:|:-:|:-:
CVE-2014-6271|任意のコードの実行|×|○|○|○|○|○|○|
CVE-2014-7169|任意のコードの実行|×|×|○|○|○|○|○|
CVE-2014-7186|サービス運用妨害(DoS)|×|×|×|×|○|○|○|
CVE-2014-7187|サービス運用妨害(DoS)|×|×|×|×|○|○|○|
CVE-2014-6277|サービス運用妨害(DoS)|×|×|×|○|○|○(*1)|○|
CVE-2014-6278|任意のコードの実行|×|×|×|○|○|○|○|
○脆弱性の影響を受けないことを確認
×脆弱性の影響を受けることを確認
(*1) CVE-2014-6277の脆弱性の一部について根本対処を実施
追記
4.3.29が来てました。
$ ./bashcheck
Testing /bin/bash ...
GNU bash, バージョン 4.3.29(1)-release (x86_64-apple-darwin13.4.0)
Variable function parser pre/suffixed [%%, upstream], bugs not exploitable
Not vulnerable to CVE-2014-6271 (original shellshock)
Not vulnerable to CVE-2014-7169 (taviso bug)
Not vulnerable to CVE-2014-7186 (redir_stack bug)
Test for CVE-2014-7187 not reliable without address sanitizer
Not vulnerable to CVE-2014-6277 (lcamtuf bug #1)
Found non-exploitable CVE-2014-6278 (lcamtuf bug #2)
追記_2014/10/07
4.3.30が来てました。
CVE-2014-6277とCVE-2014-6278にNot vulnerableが付きました。
$ ./bashcheck
Testing /usr/local/bin/bash ...
GNU bash, バージョン 4.3.30(1)-release (x86_64-apple-darwin13.4.0)
Variable function parser pre/suffixed [%%, upstream], bugs not exploitable
Not vulnerable to CVE-2014-6271 (original shellshock)
Not vulnerable to CVE-2014-7169 (taviso bug)
Not vulnerable to CVE-2014-7186 (redir_stack bug)
Test for CVE-2014-7187 not reliable without address sanitizer
Not vulnerable to CVE-2014-6277 (lcamtuf bug #1)
Not vulnerable to CVE-2014-6278 (lcamtuf bug #2)
今回のbashcheckはこちらを使用しています。
bashcheckの手順
- hannob/bashcheck · GitHub にアクセス
- https://github.com/hannob/bashcheck/blob/master/bashcheck からコードをコピー
- ターミナル起動
- 適当な場所(例:
cd Desktop)に移動してvi bashcheckで2のコードをペーストして保存 - 続いて
chmod +x bashcheck -
./bashcheckを入力してEnter