【さくらのVPS】CGIモードの重大な脆弱性に対応したらしいPHP 5.3.13にアップデートした
※すでに1ヶ月ぐらい前(作業ログとかyum.logによると5月10日)に対応したことですが、備忘録ということで記述します。
そう、あれははてブであるページを見たことから始まった。
facebookにPHP CGIの脆弱性を試してみたら面白い対策がされていた!! – cakephperの日記(CakePHP, MongoDB)
つまり、CGIモードで動作するPHPに脆弱性があり、コマンドライン引数がHTTP経由で渡すことができるため、”-s”オプション(Output HTML syntax highlighted source.)を渡すとソースコードが表示されてしまうらしいです。
Facebookはそこを逆手に取って、表示されたコードのURLにアクセスすると、セキュリティエンジニアの求人情報ページへ飛ぶようにしてあったようです。実にカッコイイ!(今はFacebook DEVELOPERSのOpenSourceにリダイレクトしています)
さて、そんなPHPの脆弱性ですが、JPCERTに掲載されていたので見てみると、すでに攻撃手法が公開されているようで、早急な対応が必要な気がしました。
PHP Group より php-cgi のリクエスト処理に関する脆弱性が公開されました。
PHP Group によると、Web サーバ上に PHP を CGI モードで動作させている場合、
遠隔の第三者が PHP スクリプトのソースコードを閲覧したり、Web サーバの権
限で任意のコードを実行したりする可能性があるとのことです。本脆弱性を使用する攻撃手法が公開されています。「III. 確認方法」を参考
に、自身が管理するサーバが本脆弱性の影響を受けるか確認し、影響を受ける
場合は、PHP Group が提供する修正済みバージョンへアップデートすることを
お勧めします。PHP Group
#61910 VU#520827 – PHP-CGI query string parameter vulnerabilityhttps://bugs.php.net/bug.php?id=61910
via : PHP の脆弱性に関する注意喚起
というのが長い前フリで、簡単に言うとyumでPHP 5.3.13にアップデートしたので他のサーバでアップデートをすることがあれば参考にするために書いておくよということです。
手順
- 現在、インストールされているPHPのバージョンの確認。(すでに対策されたバージョンが入っていたら…ってことはないが)
- Webtatic.comをyumレポジトリに追加します。
- では、アップデートをしましょう
- ちゃんとPHP 5.3.13がインストールされてか確認します。
1 2 3 4 5 |
# php -v [eAccelerator] This build of "eAccelerator" was compiled for PHP version 5.3.6. Rebuild it for your PHP version (5.3.8) or download precompiled binaries. PHP 5.3.8 (cli) (built: Aug 23 2011 15:23:25) Copyright (c) 1997-2011 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies |
案の定、現在インストールされているPHPのバージョンは5.3.8なので、アップデートをします。
1 2 3 4 5 |
# rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm http://repo.webtatic.com/yum/centos/5/latest.rpm を取得中 警告: /var/tmp/rpm-xfer.tZxIzy: ヘッダ V3 DSA signature: NOKEY, key ID cf4c4ff9 準備中... ########################################### [100%] 1:webtatic-release ########################################### [100%] |
では、Webtatic.comのyumリポジトリでインストールできるPHPのバージョンは何かな?ということで調べてみると…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# yum --enablerepo=webtatic info php Loaded plugins: downloadonly, fastestmirror, priorities Loading mirror speeds from cached hostfile * base: ftp.nara.wide.ad.jp * extras: ftp.nara.wide.ad.jp * updates: ftp.nara.wide.ad.jp webtatic | 951 B 00:00 webtatic/primary | 72 kB 00:00 webtatic 521/521 242 packages excluded due to repository priority protections Installed Packages Name : php Arch : x86_64 Version : 5.3.8 Release : 1.el5.remi Size : 7.7 M Repo : installed Summary : PHP HTML 埋め込みのスクリプト言語 (PHP: Hypertext Preprocessor) URL : http://www.php.net/ License : PHP Description: PHP is an HTML-embedded scripting language. PHP attempts to make it : easy for developers to write dynamically generated webpages. PHP : also offers built-in database integration for several commercial : and non-commercial database management systems, so writing a : database-enabled webpage with PHP is fairly simple. The most common : use of PHP coding is probably as a replacement for CGI scripts. : : The php package contains the module which adds support for the PHP : language to Apache HTTP Server. |
え、5.3.8!?かと思いきや、remiのyumリポジトリでした。
ということで、一旦すべてのリポジトリをdisableにし、webtaticのみをして再度コマンドを実行
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# yum --disablerepo=* --enablerepo=webtatic info php Loaded plugins: downloadonly, fastestmirror, priorities Loading mirror speeds from cached hostfile Installed Packages Name : php Arch : x86_64 Version : 5.3.13 Release : 1.w5 Size : 3.6 M Repo : installed Summary : PHP HTML 埋め込みのスクリプト言語 (PHP: Hypertext Preprocessor) URL : http://www.php.net/ License : PHP Description: PHP is an HTML-embedded scripting language. PHP attempts to make it : easy for developers to write dynamically generated webpages. PHP : also offers built-in database integration for several commercial : and non-commercial database management systems, so writing a : database-enabled webpage with PHP is fairly simple. The most common : use of PHP coding is probably as a replacement for CGI scripts. : : The php package contains the module which adds support for the PHP : language to Apache HTTP Server. |
今度はちゃんと正しそうなデータが出てきました
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# yum --disablerepo=* --enablerepo=webtatic update php Loaded plugins: downloadonly, fastestmirror, priorities Loading mirror speeds from cached hostfile Setting up Update Process Resolving Dependencies --> Running transaction check ---> Package php.x86_64 0:5.3.13-1.w5 set to be updated --> Processing Dependency: php-common = 5.3.13-1.w5 for package: php --> Processing Dependency: php-cli = 5.3.13-1.w5 for package: php --> Running transaction check ---> Package php-cli.x86_64 0:5.3.13-1.w5 set to be updated ---> Package php-common.x86_64 0:5.3.13-1.w5 set to be updated --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Updating: php x86_64 5.3.13-1.w5 webtatic 1.4 M Updating for dependencies: php-cli x86_64 5.3.13-1.w5 webtatic 2.6 M php-common x86_64 5.3.13-1.w5 webtatic 653 k Transaction Summary ================================================================================ Install 0 Package(s) Upgrade 3 Package(s) Total download size: 4.6 M Is this ok [y/N]: y Downloading Packages: (1/3): php-common-5.3.13-1.w5.x86_64.rpm | 653 kB 00:02 (2/3): php-5.3.13-1.w5.x86_64.rpm | 1.4 MB 00:01 (3/3): php-cli-5.3.13-1.w5.x86_64.rpm | 2.6 MB 00:02 -------------------------------------------------------------------------------- Total 658 kB/s | 4.6 MB 00:07 Running rpm_check_debug Running Transaction Test Finished Transaction Test Transaction Test Succeeded Running Transaction Updating : php-common 1/6 Updating : php-cli 2/6 Updating : php 3/6 Cleanup : php 4/6 Cleanup : php-common 5/6 Cleanup : php-cli 6/6 Updated: php.x86_64 0:5.3.13-1.w5 Dependency Updated: php-cli.x86_64 0:5.3.13-1.w5 php-common.x86_64 0:5.3.13-1.w5 Complete! |
1 2 3 4 5 |
# php -v [eAccelerator] This build of "eAccelerator" was compiled for PHP version 5.3.6. Rebuild it for your PHP version (5.3.13) or download precompiled binaries. PHP 5.3.13 (cli) (built: May 8 2012 20:50:51) Copyright (c) 1997-2012 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies |
PHP 5.3.13になってることが確認できました
以上でPHP 5.3.13のインストールは終了です。
ちなみに、最後バージョン確認で
1 |
[eAccelerator] This build of "eAccelerator" was compiled for PHP version 5.3.6. Rebuild it for your PHP version (5.3.13) or download precompiled binaries. |
と出力されていますが、今インストールされているeAccerarorが古いバージョンでビルドしたものなんだから、今のバージョンでビルドして再インストールしてよと言ってるわけですが、この件はまた別エントリーで。