1. Home
  2. Linux
  3. Apache
  4. Apache2.4セキュリティ「ApacheとPHPのバージョン表示を無効にする」

Apache2.4セキュリティ「ApacheとPHPのバージョン表示を無効にする」

  • 公開日
  • カテゴリ:Apache
  • タグ:PHP,Linux,CentOS,Apache,Security,httpd,2.4,7.2
Apache2.4セキュリティ「ApacheとPHPのバージョン表示を無効にする」

Apache や PHP はデフォルトではバージョンの取得(=表示)が有効になっています。 Apache のバージョンが第三者に分かってしまうと、脆弱性が発見された時にドンピシャのバージョンであったりすると、攻撃の標的になり被害を被るリスクが高まりますので、非表示にしてしまいます。

Contents

  1. Apache のバージョン表示を無効にする
  2. PHP のバージョン表示を無効にする

Apache のバージョン表示を無効にする

まずはバージョン表示の確認を行います。 curl コマンドで対象の URL を叩いてレスポンスを確認します。

# curl コマンドで対照 URL のレスポンスを確認する
curl -v -X GET http://192.168.33.20/

# 実行結果
[demo@localhost ~]# curl -v -X GET http://192.168.33.20/

* About to connect() to 192.168.33.20 port 80 (#0)
*   Trying 192.168.33.20...
* Connected to 192.168.33.20 (192.168.33.20) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 192.168.33.20
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sat, 16 Dec 2017 09:28:28 GMT
< Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/7.1.8
< X-Powered-By: PHP/7.1.10
< Last-Modified: Sat, 16 Dec 2017 07:52:18 GMT
< ETag: "4f-5573ec209bc00"
< Accept-Ranges: bytes
< Content-Length: 79
< X-FRAME-OPTIONS: SAMEORIGIN
< Content-Type: text/html; charset=UTF-8
<html>
<head>
<title>title</title>
</head>
<body>
Hello World!
</body>
</html>
* Connection #0 to host 192.168.33.20 left intact

残念ながら「< Server: Apache/2.4.6 」ばっちり表示されてしまっています。

これを非表示にするには、conf ファイルに設定を記述します。

ファイル設置箇所/etc/httpd/conf ファイル名 httpd.confhttpd.conf を開いて、以下を記述します。

# vim コマンドで httpd.conf を開く
vim /etc/httpd/conf/httpd.conf

# httpd.conf に以下を追記
# Apache version Hide
ServerTokens ProductOnly
ServerSignature off

※もし「ServerTokens 」「ServerSignature 」の設定が既にあれば、そこを変更する形にします。

Apache を再起動する前に書式チェックを行います。

# conf ファイルの書式チェックを行う
apachectl configtest

# 実行結果
[demo@localhost ~]# apachectl configtest
Syntax OK // ←これが出れば OK

Apache を再起動します。

# Apache の再起動
apachectl restart

これで設定が完了したので、改めて、バージョン表示の確認を行います。 curl コマンドで対象の URL を叩いてレスポンスを確認します。

# curl コマンドで対照 URL のレスポンスを確認する
curl -v -X GET http://192.168.33.20/

# 実行結果
[demo@localhost ~]# curl -v -X GET http://192.168.33.20/
* About to connect() to 192.168.33.20 port 80 (#0)
*   Trying 192.168.33.20...
* Connected to 192.168.33.20 (192.168.33.20) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 192.168.33.20
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Sat, 16 Dec 2017 09:33:49 GMT
< Server: Apache
< X-Powered-By: PHP/7.1.10
< Last-Modified: Sat, 16 Dec 2017 07:52:18 GMT
< ETag: "4f-5573ec209bc00"
< Accept-Ranges: bytes
< Content-Length: 79
< X-FRAME-OPTIONS: SAMEORIGIN
< Content-Type: text/html; charset=UTF-8
< 
<html>
<head>
<title>title</title>
</head>
<body>
Hello World!
</body>
</html>
* Connection #0 to host 192.168.33.20 left intact

「< Server: Apache 」バージョン情報がしっかり非表示になっていますので、これで設定は完了です。

PHP のバージョン表示を無効にする

# curl コマンドで対照 URL のレスポンスを確認する
curl -v -X GET http://192.168.33.20/

# 実行結果
[demo@localhost ~]# curl -v -X GET http://192.168.33.20/
* About to connect() to 192.168.33.20 port 80 (#0)
*   Trying 192.168.33.20...
* Connected to 192.168.33.20 (192.168.33.20) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 192.168.33.20
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Sat, 16 Dec 2017 09:33:49 GMT
< Server: Apache
< X-Powered-By: PHP/7.1.10
< Last-Modified: Sat, 16 Dec 2017 07:52:18 GMT
< ETag: "4f-5573ec209bc00"
< Accept-Ranges: bytes
< Content-Length: 79
< X-FRAME-OPTIONS: SAMEORIGIN
< Content-Type: text/html; charset=UTF-8
< 
<html>
<head>
<title>title</title>
</head>
<body>
Hello World!
</body>
</html>
* Connection #0 to host 192.168.33.20 left intact

こちらもデフォルトでは有効になっているため、コマンドや、デベロッパーツールで確認すると「< X-Powered-By: PHP/7.1.8 」のように、ばっちり表示されています。

使用している PHP のバージョンが容易に判明してしまうのは、その PHP のバージョンに脆弱性が発見された場合に攻撃対象になるリスクが高まる。という事と、そもそも表示させておく必要もない(マイナス面しかない)ので、非表示にしてしまいます。

ファイル設置箇所/etc/httpd/conf ファイル名 httpd.confhttpd.conf を開いて、以下を記述します。

# vim コマンドで httpd.conf を開く
vim /etc/httpd/conf/httpd.conf

# httpd.conf に以下を追記
# PHP version Hide
Header unset X-Powered-By

Apache を再起動する前に conf ファイルの書式チェック!

# conf ファイルの書式チェックを行う
apachectl configtest

# 実行結果
[demo@localhost ~]# apachectl configtest
Syntax OK // ←これが出れば OK

Apache を再起動します。

# Apache の再起動
apachectl restart

これで、改めて curl コマンドを叩いて確認してみます。

# curl コマンドで対照 URL のレスポンスを確認する
curl -v -X GET http://192.168.33.20/

# 実行結果
[demo@localhost ~]# curl -v -X GET http://192.168.33.20/

* About to connect() to 192.168.33.20 port 80 (#0)
*   Trying 192.168.33.20...
* Connected to 192.168.33.20 (192.168.33.20) port 80 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 192.168.33.20
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Sat, 16 Dec 2017 04:05:36 GMT
< Server: Apache
< Last-Modified: Sat, 16 Dec 2017 01:14:55 GMT
< ETag: "b1-5574d52bc1b18"
< Accept-Ranges: bytes
< Content-Length: 177
< X-FRAME-OPTIONS: DENY
< Content-Type: text/html; charset=UTF-8
<

<html lang="ja">
<head
<meta charset="UTF-8">
<title>title</title>
</head>
<body>
<h1>Hello World!</h1>
<p>こちらは検証1号機です</p>
</body>
</html>
* Connection #0 to host 192.168.33.20 left intact

これで「< X-Powered-By: PHP/7.1.8 」の表示が消えました。設定完了です。

Author

rito

  • Backend Engineer
  • Tokyo, Japan
  • PHP 5 技術者認定上級試験 認定者
  • 統計検定 3 級