Apache脆弱性診断およびその対応について
概要
Apacheを使用しているサーバーをNiktoを使用して、脆弱性診断を行います。また、その時に出たエラーに対応していきます。
なお、サーバーに直接Niktoをインストールして脆弱性診断を行うこともできますが、今回はローカルのPCからNiktoを使用して診断しています。
環境
ローカル
- OS: macOS Mojave
- Nikto: v2.1.6
サーバー
- OS: Linux version 4.14.128-112.105.amzn2.x86_64
- Apache: 2.4
脆弱性診断
$ nikto -h http://{ホストIP または ホスト名}
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP: {ホストIP}
+ Target Hostname: {ホスト名}
+ Target Port: 80
+ Start Time: 2019-08-19 21:00:00 (GMT9)
---------------------------------------------------------------------------
+ Server: Apache
+ Cookie XSRF-TOKEN created without the httponly flag
+ All CGI directories 'found', use '-C none' to test none
+ Server leaks inodes via ETags, header found with file /robots.txt, fields: 0x18 0x5906d6a72994b
+ Server banner has changed from 'Apache' to 'awselb/2.0' which may suggest a WAF, load balancer or proxy is in place
+ Allowed HTTP Methods: GET, HEAD
+ OSVDB-3233: /icons/README: Apache default file found.
+ 26098 requests: 0 error(s) and 4 item(s) reported on remote host
+ End Time: 2019-08-19 21:30:00 (GMT9) (1800 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested
エラーと対応
セキュリティ対応設定は、/etc/httpd/conf.d/に任意の.confを作成して対応するとデフォルトの設定と混在しないためわかりやすいです。今回は例として、security.confとします。
HTTPOnly属性設定
エラー
Cookie XSRF-TOKEN created without the httponly flag
設定
Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
エンティティタグ(ETag)の出力制御
エラー
Server leaks inodes via ETags, header found with file /robots.txt, fields: 0x18 0x5906d6a72994b
設定
FileETag None
CGI ディレクトリの診断有無
メッセージ
All CGI directories 'found', use '-C none' to test none
エラーというより、CGIディレクトリの診断についてオプションで指定する必要がありそうです。
nikto/program/plugins/nikto_cgi.plugin
診断しない場合
$ nikto -h http://{ホストIP または ホスト名} -C none
診断する場合
$ nikto -h http://{ホストIP または ホスト名} -C all
iconsディレクトリ対策
エラー
OSVDB-3233: /icons/README: Apache default file found.
http://{ホストIPまたはホスト名}/icons/README
にアクセスしてみてください。
READMEファイルが表示されます。無効化にはautoindex.confを編集します。
/etc/httpd/conf.d/autoindex.conf
Alias /icons/ "/usr/share/httpd/icons/"
<Directory "/usr/share/httpd/icons">
Options Indexes MultiViews FollowSymlinks
AllowOverride None
Require all granted
</Directory>
↓ コメントアウトします
# Alias /icons/ "/usr/share/httpd/icons/"
#
# <Directory "/usr/share/httpd/icons">
# Options Indexes MultiViews FollowSymlinks
# AllowOverride None
# Require all granted
# </Directory>
Apache再起動
文法チェック
apacheの再起動前にエラーがないかチェックしておきましょう。
$ httpd -t
Syntax OK
再起動
エラーがなければ、再起動を行いましょう。
$ systemctl reload httpd
再診断
今回はCGIは使用しない設定にしているため、-C none
オプションを付けて診断に含みません。
$ nikto -h http://{ホストIP または ホスト名} -C none
- Nikto v2.1.6
---------------------------------------------------------------------------
+ Target IP: {ホストIP}
+ Target Hostname: {ホスト名}
+ Target Port: 80
+ Start Time: 2019-08-19 22:00:00 (GMT9)
---------------------------------------------------------------------------
+ Server: Apache
+ Server banner has changed from 'Apache' to 'awselb/2.0' which may suggest a WAF, load balancer or proxy is in place
+ Allowed HTTP Methods: GET, HEAD
+ 7422 requests: 0 error(s) and 1 item(s) reported on remote host
+ End Time: 2019-08-19 22:06:00 (GMT9) (360 seconds)
---------------------------------------------------------------------------
+ 1 host(s) tested
ご覧の通りこの結果が万全ではないです。
しかし、このようにして脆弱性を減らしていく、という流れをご理解いただければと思います。