LoginSignup
2
1

More than 3 years have passed since last update.

ModSecurity を Ubuntu の Apache2 で使う

Last updated at Posted at 2021-04-14

こちらにある方法を、Ubuntu 20.04 で確認しました。
How to Set Up ModSecurity with Apache on Debian/Ubuntu

sudo apt install libapache2-mod-security2
sudo a2enmod security2
sudo systemctl restart apache2

security2 が有効になったことの確認

$ ls /etc/apache2/mods-available/ | grep security2
security2.conf
security2.load

modsecurity.conf の設定

cd /etc/modsecurity
sudo mv modsecurity.conf-recommended modsecurity.conf
/etc/modsecurity/modsecurity.conf
SecRuleEngine On
(省略)
SecAuditLogParts ABCEFHJKZ
(省略)

Apache2 を再起動

sudo systemctl restart apache2

ルールのダウンロード

wget https://github.com/coreruleset/coreruleset/archive/v3.3.0.tar.gz
tar xvf v3.3.0.tar.gz

ダウンロードしたルールの設定

sudo mkdir /etc/apache2/modsecurity-crs/
sudo mv coreruleset-3.3.0/ /etc/apache2/modsecurity-crs/
cd /etc/apache2/modsecurity-crs/coreruleset-3.3.0/
sudo mv crs-setup.conf.example crs-setup.conf
/etc/apache2/mods-enabled/security2.conf
#       IncludeOptional /usr/share/modsecurity-crs/*.load
        IncludeOptional /etc/apache2/modsecurity-crs/coreruleset-3.3.0/crs-setup.conf
        IncludeOptional /etc/apache2/modsecurity-crs/coreruleset-3.3.0/rules/*.conf

Apache2 の設定が正しいか確認

sudo apache2ctl -t

Apache2 を再起動

sudo systemctl restart apache2

ModSecurity の運用を一時的に止めたい時は、次のようにしてから、apache2 を再起動。

/etc/modsecurity/modsecurity.conf
SecRuleEngine Off
(省略)
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