LoginSignup
11
10

More than 5 years have passed since last update.

PHPセキュリティ強化モジュール Suhosin

Last updated at Posted at 2016-08-14

Suhosin

Suhosin とは PHP Security Response Team の一員だった Stefan Esser が開発した PHP のパッチとエクステンション。韓国語の「수호신」(守護神)から名付けられた。

Suhosin にはエクステンションとパッチがあるが、パッチは PHP 本体の再コンパイルが必要でかつ PHP 5.3.9 までの対応となっているため、現状では利用することはないだろう。

Suhosin エクステンション (php-suhosin)

パッケージ

PHP のインストール元リポジトリとして remicentos-release-scliusatomic のいずれかを利用していれば、リポジトリから手軽にパッケージでインストールできる。

Remi's Repository

yum install php-suhosin

php-suhosin-0.9.38-1.el7.remi.5.4.x86_64
php-suhosin-0.9.38-1.el7.remi.5.5.x86_64
php-suhosin-0.9.38-1.el7.remi.5.6.x86_64
php-suhosin-0.10.0-0.3.20160307git8a5f1a3.el7.remi.7.0.x86_64
php-suhosin-0.9.38-1.el6.remi.5.4.x86_64
php-suhosin-0.9.38-1.el6.remi.5.5.x86_64
php-suhosin-0.9.38-1.el6.remi.5.6.x86_64
php-suhosin-0.10.0-0.3.20160307git8a5f1a3.el6.remi.7.0.x86_64

Software Collections

yum install https://www.softwarecollections.org/en/scls/remi/php56more/epel-7-x86_64/download/remi-php56more-epel-7-x86_64.noarch.rpm
yum install more-php56-php-suhosin

php54-php-suhosin-0.9.38-2.el7.centos.5.4.x86_64.rpm
php55-php-suhosin-0.9.38-2.el7.centos.5.5.x86_64.rpm
more-php56-php-suhosin-0.9.38-3.el7.centos.5.6.x86_64.rpm
php54-php-suhosin-0.9.38-2.el6.5.4.x86_64.rpm
php55-php-suhosin-0.9.38-2.el6.5.5.x86_64.rpm
more-php56-php-suhosin-0.9.38-3.el6.5.6.x86_64.rpm

Copr repo for php5Xmore owned by remi

curl -s https://copr.fedorainfracloud.org/coprs/remi/php56more/repo/epel-7/{remi-php56more-epel-7.repo} -o /etc/yum.repos.d/#1
yum install more-php56-php-suhosin

remi/php54more/php-suhosin-0.9.38-2.remi
remi/php55more/php-suhosin-0.9.38-2.remi
remi/php56more/php-suhosin-0.9.38-3.remi

IUS Repository

php55u-suhosin-0.9.38-2.ius.el7.x86_64
php56u-suhosin-0.9.38-2.ius.el7.x86_64
php55u-suhosin-0.9.38-2.ius.el6.x86_64
php56u-suhosin-0.9.38-2.ius.el6.x86_64

手動インストール

https://suhosin.org/stories/install.html#manual-installation

Suhosin パッチ

前述の通り Suhosin パッチは PHP 5.3.9 までしか対応していない。
https://suhosin.org/stories/install.html#suhosin-patch

Suhosin の機能

Suhosin Feature List | SUHOSIN

Suhosin パッチ

  • Protects the internal memory manager against bufferoverflows with Canary and SafeUnlink Protection
  • Protects Destructors of Zend Hashtables
  • Protects Destructors of Zend Linked-Lists
  • Protects the PHP core and extensions against format string vulnerabilities
  • Protects against errors in certain libc realpath() implementations

Suhosin エクステンション

各種機能

  • 保護シミュレーションモード :!:
  • PHP コアに sha256()sha256_file() の関数を追加
  • 全プラットフォームの crypt()CRYPT_BLOWFISH のサポートを追加
  • phpinfo() ページのオープンの透過的な保護
  • EXPERIMENTAL SQL データベースユーザー保護

ランタイム保護

  • 透過的なクッキーの暗号化 :!:
  • (リモート)インクルードの脆弱性の異なる種類に対する保護
    • リモートURLのインクルードの禁止 (オプション: ブラックリスト/ホワイトリスト)
    • アップロードされたファイルのインクルードの禁止
  • 任意のディレクトリトラバーサル攻撃の停止
  • preg_replace()/e 修飾子の無効化設定
  • eval() の無効化設定
  • 設定可能な最大実行深度を通した無限再帰に対する保護
  • VirtualHost またはディレクトリごとの設定が可能な関数のブラックリストとホワイトリストをサポート
  • 評価されたコードのセパレートされた関数のブラックリストとホワイトリストをサポート
  • HTTP レスポンススプリッティング攻撃に対する保護
  • memory_limit を操作するスクリプトに対する保護
  • extract()import_request_vars() に対する PHP のスーパーグローバルの保護
  • mail() へのニューライン攻撃に対する保護を追加
  • preg_replace() の 0 アタックに対する保護を追加

セッション保護

  • セッションデータの透過的な暗号化 :!:
  • 透過的なセッションハイジャック保護 :!:
  • 長すぎるセッション識別子に対する保護
  • セッション ID における悪意のある文字に対する保護

フィルタリング機能

  • ユーザーの入力から ASCIIZ 文字をフィルター
  • 次の名前の GET 、 POST 、 COOKIE 変数を無視: GLOBALS, _COOKIE, _ENV, _FILES, _GET, _POST, _REQUEST, _SERVER, _SESSION, HTTP_COOKIE_VARS, HTTP_ENV_VARS, HTTP_GET_VARS, HTTP_POST_VARS, HTTP_POST_FILES, HTTP_RAW_POST_DATA, HTTP_SERVER_VARS, HTTP_SESSION_VARS
  • REQUEST 変数に制限を強制可能。またはタイプ(GET、POST、COOKIE)により分類可能。
    • リクエスト制限あたりの変数の数をサポート
    • 変数名の最大長をサポート(インデックスありとインデックスなし)
    • 配列インデックスの最大長をサポート
    • 変数値の最大長をサポート
    • 配列の最大深度をサポート
  • アップロードされたファイルの設定可能な数だけ許可
  • 外部スクリプトを使用してアップロードされたファイルの検証をサポート
  • アップロードされたELF実行可能ファイルの自動禁止をサポート
  • アップロードされたバイナリファイルの自動禁止をサポート
  • アップロードされたファイル内のバイナリコンテンツの自動stripをサポート
  • 違反に関する設定可能なアクション
    • 単に違反変数をブロック
    • HTTP レスポンスコードの送信
    • ブラウザのリダイレクト
    • 別の PHP スクリプトの実行

ロギング機能

  • 複数のログデバイスをサポート (syslog, SAPI module error log, external logging script)
  • Supports freely configureable syslog facility and priority
  • Supports log device separated selection of alert types to log
  • アラートにそれを引き起こしたファイル名と行番号を含める
  • アラートにそれを引き起こしたユーザーの IP アドレスを含める
  • IP アドレスを X-Forwarded-For の HTTP ヘッダーから抽出可能 (f.e. for reverse proxy setups)

Suhosin の設定

Configuration | SUHOSIN

ロギング設定

suhosin.log.syslog
suhosin.log.syslog.facility
suhosin.log.syslog.priority
suhosin.log.sapi
suhosin.log.stdout
suhosin.log.file
suhosin.log.file.name
suhosin.log.file.time
suhosin.log.script
suhosin.log.script.name
suhosin.log.phpscript
suhosin.log.phpscript.name
suhosin.log.phpscript.is_safe
suhosin.log.use-x-forwarded-for

Executor Options

suhosin.executor.max_depth
suhosin.executor.include.max_traversal
suhosin.executor.include.whitelist
suhosin.executor.include.blacklist
suhosin.executor.include.allow_writable_files
suhosin.executor.func.whitelist
suhosin.executor.func.blacklist
suhosin.executor.eval.whitelist
suhosin.executor.eval.blacklist
suhosin.executor.disable_eval
suhosin.executor.disable_emodifier preg_replace()/e 修飾子のコード実行許可 On/[Off]
suhosin.executor.allow_symlink open_basedir 使用時の symlink() の再有効化 On/[Off]

各種オプション

suhosin.simulation シミュレーションモードによる非制限とロギング On/[Off]
suhosin.perdir
suhosin.protectkey
suhosin.coredump
suhosin.stealth
suhosin.apc_bug_workaround
suhosin.disable.display_errors
suhosin.multiheader
suhosin.mail.protect
suhosin.memory_limit

SQLインジェクション保護

suhosin.sql.bailout_on_error
suhosin.sql.user_match
suhosin.sql.user_prefix
suhosin.sql.user_postfix
suhosin.sql.comment
suhosin.sql.opencomment
suhosin.sql.multiselect
suhosin.sql.union

透過的暗号化オプション

suhosin.session.encrypt 透過的なセッションの暗号化 [On]/Off
suhosin.session.cryptkey
suhosin.session.cryptua 透過的セッション暗号化の鍵にUser-Agentを使う On/[Off]
suhosin.session.cryptdocroot 透過的セッション暗号化の鍵にDocumentRootを使う [On]/Off
suhosin.session.cryptraddr 透明セッション暗号化の鍵に使うREMOTE_ADDRからのオクテット数(0-4) [0]
suhosin.session.checkraddr セッション復号化に一致するREMOTE_ADDRからのオクテット数(0-4) [0]
suhosin.cookie.encrypt 透過的なクッキーの暗号化 On/[Off]
suhosin.cookie.cryptkey
suhosin.cookie.cryptua
suhosin.cookie.cryptdocroot
suhosin.cookie.cryptraddr
suhosin.cookie.checkraddr
suhosin.cookie.cryptlist
suhosin.cookie.plainlist

フィルタリングオプション

suhosin.filter.action
suhosin.cookie.max_array_depth
suhosin.cookie.max_array_index_length
suhosin.cookie.max_name_length
suhosin.cookie.max_totalname_length
suhosin.cookie.max_value_length
suhosin.cookie.max_vars
suhosin.cookie.disallow_nul
suhosin.cookie.disallow_ws
suhosin.get.max_array_depth
suhosin.get.max_array_index_length
suhosin.get.max_name_length
suhosin.get.max_totalname_length
suhosin.get.max_value_length
suhosin.get.max_vars
suhosin.get.disallow_nul
suhosin.get.disallow_ws
suhosin.post.max_array_depth
suhosin.post.max_array_index_length
suhosin.post.max_name_length
suhosin.post.max_totalname_length
suhosin.post.max_value_length
suhosin.post.max_vars
suhosin.post.disallow_nul
suhosin.post.disallow_ws
suhosin.request.array_index_blacklist
suhosin.request.array_index_whitelist
suhosin.request.max_array_depth
suhosin.request.max_array_index_length
suhosin.request.max_totalname_length
suhosin.request.max_value_length
suhosin.request.max_vars
suhosin.request.max_varname_length
suhosin.request.disallow_nul
suhosin.request.disallow_ws
suhosin.upload.max_uploads
suhosin.upload.max_newlines
suhosin.upload.disallow_elf
suhosin.upload.disallow_binary
suhosin.upload.remove_binary
suhosin.upload.allow_utf8
suhosin.upload.verification_script
suhosin.session.max_id_length
suhosin.server.encode
suhosin.server.strip
suhosin.rand.seedingkey
suhosin.rand.reseed_every_request
suhosin.srand.ignore
suhosin.mt_srand.ignore

開発状況

Suhosin 0.9.37 以降はすべて bef アカウントによる更新で、また PHP 7.x への対応はドイツの SektionEins GmbH 社のリポジトリで進められている。
https://github.com/stefanesser/suhosin
https://raw.githubusercontent.com/stefanesser/suhosin/master/Changelog
https://github.com/sektioneins/suhosin7

セキュリティ関連記事

11
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
10