LoginSignup
2
1

More than 5 years have passed since last update.

Raspbian + Apache2.4.25 のDos対策(mod_dosdetector)

Last updated at Posted at 2017-11-14

メモ代わりに残しておきます。

導入

sudo apt update
sudo apt upgrade #サボらずちゃんとやっておきましょう
sudo apt install apache2-dev
git clone https://github.com/stanaka/mod_dosdetector.git
cd mod_detector
vim Makefile #apxsのパスを/usr/sbin/から/usr/binに修正
make #警告出るけど動くのでok
make install
find /usr/lib/apache2/modules/mod_dos* #mod_dosdetector.soの存在を確認
cat /etc/apache2/mods-available/dosdetector.load

LoadModule dosdetector_module /usr/lib/apache2/modules/mod_dosdetector.so
とあればok
これで導入は終了です。
mod_dosdetectorのダウンロードは色々なサイトからも落とせますが、ちゃんとgithubから落としましょう。古い場合があります。(というかありました)
https://github.com/stanaka/mod_dosdetector

/etc/apache2/以下の構造

apache2.conf ... メイン設定ファイル。このファイル内にxxx-enabled以下のファイルを読み込むように書いてある。centOSのhttpd.confと同じ(?)
xxx-enabled ... 中身は全部xxx-available内ファイルへのリンク。起動時に読み込まれるのはこっち。
mods-available ... modsの読み込みファイルは.load , 設定ファイルは.conf にする
conf-available ... 設定ファイル。.conf
site-available ... サイトの設定。.conf

dos_detectorの設定

mods-available/dos_detector.conf に書くのが好ましいでしょう。
書き終わったら忘れずにmods-enabledにln -sでリンクを作製しましょう。

DoSDetection On #dos_detectionをオンにします
DoSPeriod 60 #この秒数間に
DoSThreshold 30 #この回数アクセスされるとDos攻撃の疑いあり
DoSHardThreshold 120 #この回数アクセスされると激しいDos攻撃と設定
DoSBanPeriod 3600 #アクセス制限する時間(秒)
DoSTableSize 1024 #追跡(記録)するアドレスの数(?)
DoSIgnoreContentType ^(image/|application/|text/javascript|text/css)

他にも設定できる項目はあるので調べてみると良いでしょう。

mod_rewriteの設定

mod_dosdetectorはDos攻撃を感知し変数を設定するだけなので、mod_rewriteを使って感知した場合に503を返す設定をします。
sites-available/000-default.confのVirtualHost内に追記します。
ここに書かないと動きませんので気をつけてください。

RewriteEngine On #RewriteEngineをオンにします
RewriteCond %{ENV:SuspectHardDoS} =1 #激しいDosを感知した時
RewriteRule .* - [R=503,L] #503を返す
ErrorDocument 503 "Server is busy." #エラーメッセージ

ここの設定はネット上に沢山あるので好みのものを作成しましょう
またmod_rewriteはデフォルトではoffになっているはずなのでonにします
sudo a2enmod rewrite

最後にapache2を再起動します
sudo service apache2 reload

以上でDos対策は終了です。
自分で過剰なアクセスをして確かめてみましょう。
ログは/var/log/apache2/以下にaccess.logとerror.logがあります。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1