apacheでDoS攻撃対策。mod_evasiveのインストール
apacheでDoS攻撃対策。mod_evasiveのインストール
同一IPアドレスからのアクセスに回数制限を設けるのにApache のモジュールがいくつかある。
有名なのはここらへん。
mod_dosdetector
mod_evasive
Fail2ban ← 人気
簡単そうなので mod_evasive をインストールする。
インストール参考:https://okochang.hatenablog.jp/entry/2014/03/15/161134
以下手順。
読み込まれているモジュールの一覧
-----------------
httpd -M
-----------------
sharedのモジュールは、/etc/httpd/conf.modules.d配下の定義ファイルを編集することで、モジュールをロードしたり、ロードしないようにすることができる。
mod_evasive が無いことを確認
-----------------
httpd -M | grep evasive
-----------------
EPEL(イーペル)リポジトリにあるらしいので設定されいてるリポジトリを見る
-----------------
yum repolist all
-----------------
EPELがあることを確認する
mod_evasiveのインストール
-----------------
yum --enablerepo=epel install mod_evasive
-----------------
エラーが出る
-----------------
# yum --enablerepo=epel install mod_evasive
読み込んだプラグイン:fastestmirror, security
インストール処理の設定をしています
Determining fastest mirrors
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/6/base/mirrorlist.txt
エラー: Cannot find a valid baseurl for repo: base
-----------------
インストール可能なパッケージとインストール済みのパッケージを見ようとしてもエラーが出る
-----------------
yum list
-----------------
CentOSのバージョンが6.9と古いから出るエラーらしい。
対処参考URL1:https://shobon.hatenablog.com/entry/2020/12/03/212209
対処参考URL2:https://ex1.m-yabe.com/archives/5066
ページを参考に設定ファイルを書き変え
-----------------
/etc/yum.repos.d/CentOS-Base.repo
-----------------
書き変え後、一覧が出るか確認 → OK。
-----------------
yum list | grep evasive
-----------------
再度インストール実行
-----------------
yum --enablerepo=epel install mod_evasive
-----------------
インストールできているか確認
-----------------
httpd -M | grep evasive
-----------------
結果
-----------------
Syntax OK
evasive20_module (shared)
-----------------
設定ファイルの編集
うちのサーバーはここにあった
-----------------
cat /etc/httpd/conf.d/mod_evasive.conf
-----------------
モジュールに付属のテストファイルを実行
-----------------
# perl /usr/share/doc/mod_evasive-1.10.1/test.pl
-----------------
エラーが出る。最近の apache ではリクエストの改行コードがCRLFでないため 400 Bad Request が出る。
下記を参考に書き変え
https://www.kowloonet.net/2020/07/centos8-10apachedosmodevasive.html
再度実行してok。
カテゴリー:サーバートラブル・つながらない, サーバー設定