0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【mod_security】EC2にmod_securityをインストールしたら、index.htmlがApacheのテストページ表示になったときの解決方法

Last updated at Posted at 2022-01-30

はじめに

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にします。

/etc/httpd/conf.d/mod_security.conf
  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)に配置します。

index.html
<html>
<form>
<input type="text" name="value">
<input type="submit">
</form>
</html>

ブラウザで開くとこんな感じ。
image.png

さてさて、入力ボックスに、SQLインジェクションに掛かる文字を入力するとどうなるのか。。。。

こんな感じで、送信をクリック
image.png

あれ、Apacheのテストページに飛んだ????
image.png

なんでだ。。。。う~ん、何だかよく分からないので、あ を入れて送信をクリックすると、Apacheのテストページには飛ばなくなった。何か効いてはいるのだろうか。
image.png

とりあえず、先に進みます。

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のテストページに遷移するのか、を紐解いていきたいと思います。
では、また。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?