はじめに
EC2にmod_securityをインストールしたときの備忘録です。mode_securityをインストールしたときに、ドキュメントルートに配置したindex.html(/var/www/html/index.html)が表示されなくなり困りました。代わりに、Apacheのテストページが表示されました。mod_securityの影響かと思い、調査したときの話を記事にします。
環境
環境は以下になります。
・EC2:Amazon Linux
・Apache
・mod_security
インストール手順
Apacheをインストールします。
$ sudo yum install httpd -y
mod_securityをインストールします。
$ sudo yum install mod_security -y
mode_security_crsをインストールします。
sudo yum install mod_security_crs
Apacheを起動します。
$ sudo service httpd start
Apancheのテストページが表示されるように・・・
この時点でドキュメントルートに配置したindex.html(/var/www/html/index.html)ではなく、Apacheのテストページが表示されるようになり、(;´д`)トホホになりました。
mod_securityをオフにしてみた
mod_securityをオフにすると、ドキュメントルートに配置したindex.html(/var/www/html/index.html)が表示されるようになった。ので、やはり、mod_securityの影響と思われる。
設定ファイルは以下。
/etc/httpd/conf.d/mod_security.conf
mod_securityのルールエンジンをOFFにします。
1 <IfModule mod_security2.c>
2 # ModSecurity Core Rules Set configuration
3 IncludeOptional modsecurity.d/*.conf
4 IncludeOptional modsecurity.d/activated_rules/*.conf
5
6 # Default recommended configuration
7 SecRuleEngine Off
Apacheを再起動します。
$systemctl restart httpd
この時点では、ドキュメントルートに配置したindex.html(/var/www/html/index.html)が表示されるようになります。
これでは、mod_securityの動作確認はできないので、mod_securityのルールエンジンをONに戻します。
1 <IfModule mod_security2.c>
2 # ModSecurity Core Rules Set configuration
3 IncludeOptional modsecurity.d/*.conf
4 IncludeOptional modsecurity.d/activated_rules/*.conf
5
6 # Default recommended configuration
7 SecRuleEngine On
Apacheを再起動します。
$systemctl restart httpd
ちょっと、真の原因は分からないのですが、SecRuleEngine On にしても、ドキュメントルートに配置したindex.html(/var/www/html/index.html)が表示されるようになりました。ので、次に進みます。
単純にPOSTするindex.htmlをドキュメントルート(/var/www/html/index.html)に配置します。
<html>
<form>
<input type="text" name="value">
<input type="submit">
</form>
</html>
さてさて、入力ボックスに、SQLインジェクションに掛かる文字を入力するとどうなるのか。。。。
なんでだ。。。。う~ん、何だかよく分からないので、あ を入れて送信をクリックすると、Apacheのテストページには飛ばなくなった。何か効いてはいるのだろうか。
とりあえず、先に進みます。
mod_securityのログ(/var/log/httpd/modsec_audit.log)を確認してみます。
$cd /var/log/httpd
$ls -lrt
$-rw-r----- 1 root root 0 Jan 29 16:40 modsec_debug.log
$-rw-r----- 1 root root 38132 Feb 3 11:29 modsec_audit.log
$-rw-r--r-- 1 root root 37559 Feb 3 11:29 error_log
$-rw-r--r-- 1 root root 11284 Feb 3 11:29 access_log
おおおおおーーーー、modesc_audit.log に何か書かれている。
おわりに
次回は、modsec_audit.log の内容理解と、なぜapacheのテストページに遷移するのか、を紐解いていきたいと思います。
では、また。