INDEX [隠す]
1.ServerTokensをProductOnlyにしてバージョンを隠す
ServerTokensは初期値ではOSになっています。
Apahce、OS、PHPのバージョンを知らせる必要はありません。
httpd.confを編集してProductOnlyにしましょう。
編集後はApacheの再起動が必要です。
1 2 3 | # vi /etc/httpd/conf/httpd.conf #ServerTokens OS ServerTokens ProductOnly |
ServerTokens ProductOnly
⇒Server: Apache
ServerTokens Minimal
⇒Server: Apache/2.2.3
ServerTokens OS
⇒Server: Apache/2.2.3 (CentOS)
ServerTokens Full (もしくは未指定)
⇒Server: Apache/2.2.3 (CentOS) DAV/2 PHP/5.1.6 mod_ssl/2.2.3 OpenSSL/0.9.8e-fips-rhel5
※この設定はサーバ全体に適用され、 バーチャルホスト毎の設定はできません。
修正前はOSのバージョンなどがヘッダーで見えてしまっています。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # wget -S --spider localhost/index.html --15:28:03-- http: //localhost/index .html localhost をDNSに問いあわせています... 127.0.0.1 localhost|127.0.0.1|:80 に接続しています... 接続しました。 HTTP による接続要求を送信しました、応答を待っています... HTTP /1 .1 200 OK Date: Tue, 21 May 2013 06:28:03 GMT Server: Apache /2 .2.3 (CentOS) Last-Modified: Thu, 15 Nov 2012 07:12:30 GMT ETag: "940407-36-5fcab380" Accept-Ranges: bytes Content-Length: 54 Connection: close Content-Type: text /html ; charset=UTF-8 長さ: 54 200 OK |
修正後はApacheの表記のみになります。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # wget -S --spider localhost/index.html --15:28:23-- http: //localhost/index .html localhost をDNSに問いあわせています... 127.0.0.1 localhost|127.0.0.1|:80 に接続しています... 接続しました。 HTTP による接続要求を送信しました、応答を待っています... HTTP /1 .1 200 OK Date: Tue, 21 May 2013 06:28:23 GMT Server: Apache Last-Modified: Thu, 15 Nov 2012 07:12:30 GMT ETag: "940407-36-5fcab380" Accept-Ranges: bytes Content-Length: 54 Connection: close Content-Type: text /html ; charset=UTF-8 長さ: 54 200 OK |
2.ServerSignature
ServerSignature ディレクティブは、サーバが生成するエラーメッセージ等のドキュメントの
最下行に付与するフッターの表記を設定します。
ServerTokens同様バージョンが見えるのでhttpd.confを編集して隠しましょう。
1 2 3 | # vi /etc/httpd/conf/httpd.conf #ServerSignature On ServerSignature Off |
ServerSignature Onの場合のエラーページは以下の通り
The requested URL /a.html was not found on this server.
——————————————————————————–
Apache/2.2.15 (CentOS) Server at 192.168.10.55 Port 80
ServerSignature Offの場合のエラーページは表記が減っているのが確認できます。
The requested URL /a.html was not found on this server.
3.TRACEメソッドの無効
この弊害はここでは追求しませんが、使えないようにしておきます。
Apache 1.3.34 以降か 2.0.55以降であれば下記のように1行加えて修正は完了です。
httpd.confにTraceEnable Offを追記するだけです。
1 2 | # vi /etc/httpd/conf/httpd.conf TraceEnable Off ←任意の場所に追記 |
修正前のヘッダーは以下の通り
1 2 3 4 5 6 7 | HTTP /1 .1 200 OK Date: Thu, 16 May 2013 00:34:55 GMT Server: Apache /2 .2.15 (CentOS) Allow: GET,HEAD,POST,OPTIONS,TRACE Content-Length: 0 Connection: close Content-Type: httpd /unix-directory |
修正後は以下のようにTraceが消えているのが確認できます。
1 2 3 4 5 6 7 | HTTP /1 .1 200 OK Date: Thu, 16 May 2013 00:36:23 GMT Server: Apache /2 .2.15 (CentOS) Allow: GET,HEAD,POST,OPTIONS Content-Length: 0 Connection: close Content-Type: httpd /unix-directory |
【補足】Limitでメソッドを制限する
似たようなことがhttpd.confの中のLimitディレクティブを使用してすることもできます。
<Limit>は指定したメソッドを制御します。
例えば<Limit GET POST OPTIONS>と指定すればGET,POST,OPTIONSを制御、つまり禁止します。
逆に<LimitExcept>は,指定していないメソッドを制御します。
例えば<LimitExcept GET POST OPTIONS>と指定すればGET,POST,OPTIONS以外のメソッドを制御します。
このLimitの使用方法を間違える場合が多いようです。
今回のようにセキュリティが目的なら、一般的には LimitExcept を使用するべきでしょう。
そうしなくては、禁止すべきメソッドを全て列挙しなくてはいけないからです。
1 2 3 4 5 6 7 8 | <Limit GET POST OPTIONS> ←GET POST OPTIONSを許可 Order allow,deny Allow from all < /Limit > <LimitExcept GET POST OPTIONS> ←GET POST OPTIONS以外を制限 Order deny,allow Deny from all < /LimitExcept > |
4.アパッチのトップページを非表示にする(テストページ)
ここにもOSやらApacheのバージョンが表記されています。
隠しましょう。
welcome.confの英語をよく見ると、コメントアウトするようにかいています。
その通りコメントアウトします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | vim /etc/httpd/conf .d /welcome .conf # # This configuration file enables the default "Welcome" # page if there is no default index page present for # the root URL. To disable the Welcome page, comment # out all the lines below. # <LocationMatch "^/+$" > Options -Indexes ErrorDocument 403 /error/noindex .html < /LocationMatch > 非表示にするためには、全ての行をコメントアウトします(訳) ↓ # # This configuration file enables the default "Welcome" # page if there is no default index page present for # the root URL. To disable the Welcome page, comment # out all the lines below. # #<LocationMatch "^/+$"> # Options -Indexes # ErrorDocument 403 /error/noindex.html #</LocationMatch> |
5.使ってないAlias設定を無効化
Apacheの英語訳の通りにしても、
http://[URL]/error/noindex.html
にアクセスすると、結局テストページは表示されます。
それはAiliasが設定されているためです。
不要なAiliasはコメントアウトしておきましょう。
1 2 3 4 5 6 7 8 | # vi /etc/httpd/conf/httpd.conf Alias /icons/ "/var/www/icons/" ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" Alias /error/ "/var/www/error/" ↓ #Alias /icons/ "/var/www/icons/" #ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" #Alias /error/ "/var/www/error/" |
もしエラーページが必用なら、
/error/noindex.html
を削除してしまえばテストページは表示されません。
また、CGIを使用していなければScriptAliasはコメントアウトして問題ありませんが、
使用しているのであれば別ディレクトリにした方がいいかもしれません。
6.indexの非表示
これは危険です。
ページが全て丸見えになってしまいます。
(対応方法1)
httpd.confのOptionsからIndexesを外す。
これをしておくのが無難でしょう。
1 2 3 4 5 | # vi /etc/httpd/conf/httpd.conf Options Indexes FollowSymLinks ↓ # Options Indexes FollowSymLinks Options FollowSymLinks |
※複数のディレクティブで設定している場合はしてください。
(対応方法2)
httpd.confの
DirectoryIndex index.html index.php
に設定してあるindex.htmlやindex.phpを各ディレクトリに置くという方法もあります。
7.マニュアルの非表示
http://[URL]/manual/
で表示されます。
welcome.confのAliasMatchをコメントアウトします。
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 | vim /etc/httpd/conf .d /welcome .conf # # This configuration file allows the manual to be accessed at # AliasMatch ^ /manual (?:/(?:de|en|fr|ja|ko|ru))?(/.*)?$ "/var/www/manual$1" <Directory "/var/www/manual" > Options Indexes AllowOverride None Order allow,deny Allow from all < /Directory > ↓ # # This configuration file allows the manual to be accessed at # #AliasMatch ^/manual(?:/(?:de|en|fr|ja|ko|ru))?(/.*)?$ "/var/www/manual$1" <Directory "/var/www/manual" > Options Indexes AllowOverride None Order allow,deny Allow from all < /Directory > |
8.アパッチのREADMEファイルを削除する
/var/www/error/README の削除
9.エラーを変える
httpd.conf の ErrorDocumentディレクティブを修正しましょう。
直接文字を設定することも、リンクを設定することもできます。
1 2 3 | # vi /etc/httpd/conf/httpd.conf ErrorDocument 404 "Sorry. I can't find your requested file." ErrorDocument 404 /error/notfound .html |
10.ユーザーページの自動表示の停止
mod_userdirが入ってると、ユーザー・ホームディレクトリに各自が公開コンテンツをおけます。
/home/neko/public_html は http://[ドメイン]/~neko になります。
勝手に公開されていたなんてことがないように気を付けましょう!
使用していなければコメントアウトしておくにこしたことはありません。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # vi /etc/httpd/conf/httpd.conf LoadModule userdir_module libexec /apache/mod_userdir .so AddModule mod_userdir.c <IfModule mod_userdir.c> UserDir public_html < /IfModule > ↓ #LoadModule userdir_module libexec/apache/mod_userdir.so #AddModule mod_userdir.c #<IfModule mod_userdir.c> # UserDir public_html #</IfModule> |
11.HTTP ヘッダーからphpバージョン(X-Powered-By: PHP/5.2.0)を消す
PHPのバージョンが漏れると、脆弱性を攻撃されるかもしれません。
非表示にしましょう。
/etc/php.iniの
expose_php=On
の設定を
expose_php=Off
にします。
修正前だとヘッダーにバージョンがあります。
1 2 3 4 5 6 7 8 9 10 11 12 13 | # wget -S --spider localhost/test.php --16:33:07-- http: //localhost/test .php localhost をDNSに問いあわせています... 127.0.0.1 localhost|127.0.0.1|:80 に接続しています... 接続しました。 HTTP による接続要求を送信しました、応答を待っています... HTTP /1 .1 200 OK Date: Tue, 21 May 2013 07:33:07 GMT Server: Apache X-Powered-By: PHP /5 .1.6 Connection: close Content-Type: text /html ; charset=UTF-8 長さ: 特定できません 200 OK |
修正後には非表示になっていることが確認できます。
1 2 3 4 5 6 7 8 9 10 11 12 | # wget -S --spider localhost/test.php --16:32:35-- http: //localhost/test .php localhost をDNSに問いあわせています... 127.0.0.1 localhost|127.0.0.1|:80 に接続しています... 接続しました。 HTTP による接続要求を送信しました、応答を待っています... HTTP /1 .1 200 OK Date: Tue, 21 May 2013 07:32:35 GMT Server: Apache Connection: close Content-Type: text /html ; charset=UTF-8 長さ: 特定できません 200 OK |