tweet:2015:1218_01
Apache mod_security + OWASP CRS
NGiNXでうまくいかなかったので、とりあえず動く例が欲しくなって試す。 環境は、基本、NGiNXの時と同じ
環境
XenServer 6.5SP1 | |
CPU | 2 |
Memory | 2048M |
Disk | 20G |
NIC | 2 |
OS | FreeBSD 10.2 |
準備
- ApacheにModSecurityを入れるなら、pkgでよい。
- pkg install ap24-mod_security
- NGiNXの時よりも入れるものが少ない。自前でCompileしないからかな。
httpdの設定
Apacheなんて15年ぶりなので、正直、グッとくるhttpd.confのサンプルがない。 なので、とりあえずの設定。
FreeBSDの場合、ports/pkgからInstallすると、Apache関連の設定ファイルは/usr/local/etc/apache24
に格納される。
- httpd.confの設定
- mod_securityでWAFをさせるだけなので、CGIは使わない。
LoadModule alias_module libexec/apache24/mod_alias.so
をコメントアウト - ServerAdminを設定する
- ServerNameを設定する
- DocumentRoot下の<Directory “/usr/local/www/apache24/data”>内にある
Options Indexes FollowSymLinks
をOptions -Indexes +FollowSymLinks
に変更
- Includes下に
security.conf
を作成- security.conf
# # Apache Security Conf. # # Prevent CrossSite Tracing TraceEnable Off # Hide Apache Version ServerTokens ProductOnly ServerSignature off <IfModule headers_module> # Hide Header X-Powered-By Header always unset X-Powered-By # Prepend Click-Jacking Header append X-FRAME-OPTIONS "SAMEORIGIN" # for IR^?E Header set X-Content-Type-Options: "nosniff" </IfModule> # Anti POODLE <IfModule ssl_module> SSLProtocol All -SSLv2 -SSLv3 </IfModule> # Prevent to access to SCM Dir. <DirectoryMatch "/\.svn"> Require all denied </DirectoryMatch> <DirectoryMatch "/\.git"> Require all denied </DirectoryMatch> <DirectoryMatch "/\.hq"> Require all denied </DirectoryMatch> <DirectoryMatch "/\.bzr"> Require all denied </DirectoryMatch>
- extra/httpd-autoindex.confを編集
- 単純に全部をコメントアウト
- extra/httpd-userdir.confを編集
- 単純に全部をコメントアウト
Apache用mod_securityの設定
Includes/mod_security.confに以下を記載
# Include mod_security module LoadModule security2_module libexec/apache24/mod_security2.so <IfModule security2_module> Include etc/modsecurity/*.conf </IfModule>
mod_securityの設定
素人のメモ
Apacheなんて正直15年位真面目に使ってなかった(LighttpdとかNGiNXに転んだから)のでとてつもなく恥ずかしいが、幾つかのメモ
- 実行中のApacheが読み込んでいるModuleを見る
- Compile時に組み込まれているModuleを見る
apachectl -l
- 実行時に読み込まれているModuleを見る
apachectl -M
参考
- ModSecurityをソースからビルドしてhashdos対策に活用する CentOSでmod_security等を利用する場合に参照しておくこと
tweet/2015/1218_01.txt · 最終更新: 2015/12/25 14:34 by 127.0.0.1