OS X bashの「shellshock」に対応するパッチ適用作業手順

先日、Appleから OS Xbash アップデートがリリースされましたが、バージョンを見ると3.2.53となっており、その後の脅威への対応が充分とは言えません。

https://github.com/hannob/bashcheck
上記のテストにおいて、

CVE-2014-6271
CVE-2014-7169
CVE-2014-7186
CVE-2014-7187
CVE-2014-6277
CVE-2014-6278

それぞれに対する結果は
http://qiita.com/kkdd/items/f3f94f129ae9210c810d
と不完全なものです。

そこで、自分でパッチを当てたのですが、その際の作業手順を掲載します。


前提条件: Xcodeがインストールされていること。


1. 現在のバージョン確認
$ bash --version
$ sh --version

2. bashの入手とパッチ当て、build
$ mkdir bash-fix
$ cd bash-fix/
$ curl https://opensource.apple.com/tarballs/bash/bash-92.tar.gz | tar zxf -
$ cd bash-92/bash-3.2/
$ curl https://ftp.gnu.org/pub/gnu/bash/bash-3.2-patches/bash32-052 | patch -p0
$ curl https://ftp.gnu.org/pub/gnu/bash/bash-3.2-patches/bash32-053 | patch -p0
$ curl https://ftp.gnu.org/pub/gnu/bash/bash-3.2-patches/bash32-054 | patch -p0
$ curl https://ftp.gnu.org/pub/gnu/bash/bash-3.2-patches/bash32-055 | patch -p0
$ curl https://ftp.gnu.org/pub/gnu/bash/bash-3.2-patches/bash32-056 | patch -p0
$ curl https://ftp.gnu.org/pub/gnu/bash/bash-3.2-patches/bash32-057 | patch -p0
$ cd ..
$ xcodebuild

3. buildしたbashのバージョン確認
$ ./build/Release/bash --version
$ ./build/Release/sh --version

4. 既存のbashをバックアップし、buildしたbashを/bin にコピー。バックアップファイルのファイルモードを変更
$ sudo cp /bin/bash /bin/bash.old
$ sudo cp /bin/sh /bin/sh.old
$ sudo cp build/Release/bash /bin
$ sudo cp build/Release/sh /bin
$ sudo chmod a-x /bin/bash.old /bin/sh.old

5. バージョン確認
$ bash --version
$ sh --version

3.2.57
となっていれば完了

6. 作業ディレクトリの削除
$ cd ../../
$ rm -rf bash-fix



####
#$ curl https://opensource.apple.com/tarballs/bash/bash-92.1.2.tar.gz | tar zxf -
#で行わないのは、92.1.2に54パッチを当てると以下の結果が出力がされる為。
#patching file variables.c
#Hunk #1 succeeded at 83 with fuzz 1 (offset 8 lines).
#Hunk #2 FAILED at 255.
#Hunk #3 FAILED at 323.
#Hunk #4 FAILED at 354.
#Hunk #5 FAILED at 2235.
#Hunk #6 FAILED at 3026.
#Hunk #7 FAILED at 3136.
#6 out of 7 hunks FAILED -- saving rejects to file variables.c.rej
#patching file patchlevel.h
####

Linuxなどならyumで一発だろうけれど、Mac
面倒ですね。
瞬殺で出来る方法があれば是非教えてくださいm(_ _)m