Division By Zero

ゼロで割る

CVE-2014-6271, CVE-2014-7169, CVE-2014-7186, CVE-2014-7187, CVE-2014-6277, CVE-2014-6278 (bash脆弱性)のCentOS4用パッケージをビルドしてみた

[2014/09/27追記]CVE-2014-7169を加えて修正
[2014/10/09追記]CVE-2014-7186, CVE-2014-7187, CVE-2014-6277, CVE-2014-6278を加えて追記

巷ではbash脆弱性(CVE-2014-6271,CVE-2014-7169,CVE-2014-7186,CVE-2014-7187,CVE-2014-6277,CVE-2014-6278)が問題になっている。内容が内容だけに、外につながっているいないに関わらず、社内にCentOS4の装置が残っている当方としては少し心配。

検索してみると、下記の質問が見つかった。

For reasons too stupid for me to explain in public, I am responsible for a server running RHEL 4 and with no update subscription. I could build a clone to test this, but I hope someone will have a direct answer.
1.Has /bin/bash from Centos 4 been patched, or will it be?
2.Can I just plop a (presumably patched) Centos 4 /bin/bash into my RHEL system as a workaround that will buy me several weeks? (I need until December 10)

http://serverfault.com/questions/631055/mitigating-remote-code-execution-through-bash-envronment-variables-cve-2014-627

で、ごくまっとうな回答。

Your only options are to
" Buy a support contract with RedHat
" Try to build your own package for Bash.
" Or the winning option: Retire this machine and use this security issue as an incentive to do so.

http://serverfault.com/questions/631055/mitigating-remote-code-execution-through-bash-envronment-variables-cve-2014-627

仕方ないのでビルドしてみた。(自己責任でお願いしますね)

まず、テスト環境にソースをダウンロードして、インストール。今は簡単にVMで試せて便利。

# wget ftp://rpmfind.net/linux/redhat/linux/updates/enterprise/4WS/en/os/SRPMS/bash-3.0-27.el4.src.rpm
# rpm -ivh bash-3.0-27.el4.src.rpm

つぎに、パッチをダウンロード。

# cd /usr/src/redhat/SOURCES
# wget http://ftp.gnu.org/gnu/bash/bash-3.0-patches/bash30-017
# wget http://ftp.gnu.org/gnu/bash/bash-3.0-patches/bash30-018
# wget http://ftp.gnu.org/gnu/bash/bash-3.0-patches/bash30-019
# wget http://ftp.gnu.org/gnu/bash/bash-3.0-patches/bash30-020
# wget http://ftp.gnu.org/gnu/bash/bash-3.0-patches/bash30-021
# wget http://ftp.gnu.org/gnu/bash/bash-3.0-patches/bash30-022

/usr/src/redhat/SPECS/bash.specの29行目以降にbash30-017, bash30-018, bash30-019, bash30-020, bash30-021, bash30-022を追加する。

27 Patch15: bash30-015
28 Patch16: bash30-016
29 Patch17: bash30-017
30 Patch18: bash30-018
31 Patch19: bash30-019
32 Patch20: bash30-020
33 Patch21: bash30-021
34 Patch22: bash30-022

117行目以降にも追加。

115 %patch15 -p0 -b .015
116 #%patch16 -p0 -b .016
117 %patch17 -p0 -b .017
118 %patch18 -p0 -b .018
119 %patch19 -p0 -b .019
120 %patch20 -p0 -b .020
121 %patch21 -p0 -b .021
122 %patch22 -p0 -b .022

4行目にモジュール名があるので、それらしく変更。

4 Release: 27.4.el4

/usr/src/redhat/SOURCES/bash30-017を開くと、対象パスが../bash-3.0.16/となっているので、../bash-3.0-patched/と修正。18, 29, 56行目の3つあった。さらに、patch16は適用されていないので、97行目のPATCHLEVELを15に変更。

同様に、/usr/src/redhat/SOURCES/bash30-018の18行目、/usr/src/redhat/SOURCES/bash30-019の20行目、/usr/src/redhat/SOURCES/bash30-020の19行目、/usr/src/redhat/SOURCES/bash30-021の20, 30行目、/usr/src/redhat/SOURCES/bash30-022の19, 81, 100行目、/usr/src/redhat/SOURCES/bash30-020の19行目、


rpmbuildでrpmを生成。

# cd /usr/src/redhat/SPECS
# rpmbuild -ba bash.spec

/usr/src/redhat/RPMS/i386/bash-3.0-27.4.el4.i386.rpmを対象ホストにインストールすれば終了。

# rpm -Uvh bash-3.0-27.4.el4.i386.rpm

テストも忘れずに。

# 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

[2014/10/09追記]テストも複雑になってきました。こちらのスクリプトで。


いちいちこんなことやってられないので、早く新しいサーバーを立てよう、と決意を新たに、今日はこれで終了!(最後に引用)

" Or the winning option: Retire this machine and use this security issue as an incentive to do so.

http://serverfault.com/questions/631055/mitigating-remote-code-execution-through-bash-envronment-variables-cve-2014-627