Apache2.4セキュリティ「ApacheとPHPのバージョン表示を無効にする」
- 公開:
- カテゴリ: linux Apache
- タグ: PHP,Linux,CentOS,Apache,Security,httpd,2.4,7.2
ApacheやPHPはデフォルトではバージョンの取得(=表示)が有効になっています。Apacheのバージョンが第三者に分かってしまうと、脆弱性が発見された時にドンピシャのバージョンであったりすると、攻撃の標的になり被害を被るリスクが高まりますので、非表示にしてしまいます。
尚、今回の検証機環境は以下の通りです。
- CentOS 7.2
- Apache 2.4
- 192.168.33.20
- http://192.168.33.20/
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.conf
httpd.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.conf
httpd.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
<
<!DOCTYPE html>
<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」の表示が消えました。設定完了です。