サーバー設定 · 2 min read · Jan 02, 2026
SquirrelMailでのfail2banの設定(CentOS 5.3/ISPConfig 3)
SquirrelMailでのfail2banの設定(CentOS 5.3/ISPConfig 3)
はじめに
このチュートリアルでは、fail2banを使用してSquirrelMail Webログインに対する無制限のログイン試行およびブルートフォース攻撃を防ぐ方法を示します。
1. 要件
CentOS v5.3/ISPConfig 3マシンにfail2banとSquirrelMailの両方がインストールされていることを確認してください。詳細はここにあります。
ただし、インストールは簡単です:
yum install fail2ban squirrelmailiptablesをファイアウォールとして積極的に使用している必要があります。Fail2banは、未承認のソースIPアドレスに対して一時的なドロップルールを作成することで機能します。
2. SquirrelMailのログ設定
CentOS v5.3/ISPConfig 3のSquirrelMail(imapd)は、デフォルトで/var/log/maillogにログを記録しますが、IPアドレス127.0.0.1(localhost)としてのみ記録されます。特定のソースアドレスを禁止しようとしているため、fail2banはこのファイルを使用できません。したがって、Squirrel Loggerをインストールして、ログイン試行の実際のソースアドレスをキャプチャします。
Squirrel Loggerをダウンロードしてインストールします:
cd /usr/share/squirrelmail/plugins
wget http://squirrelmail.org/countdl.php?fileurl=http%3A%2F%2Fwww.squirrelmail.org%2Fplugins%2Fsquirrel_logger-2.3-1.2.7.tar.gz
tar zxvf squirrel_logger-2.3-1.2.7.tar.gz
cd squirrel_logger-2.3-1.2.7
cp config_example.php config.phpこのプラグインは最新のSquirrel Loggerのバージョンですが、改訂版がある場合は、ここからSquirrelMailプラグインサイトから直接ダウンロードしてください。
マシンがGMT以外のローカル時間を使用している場合は、viを使用してconfig.phpの$sl_use_GMT = 1を$sl_use_GMT = 0に変更します:
元のconfig.php:
...
// Log dates in GMT? If you do not do this, dates will
// be logged in whatever timezone each user is in (or
// has set in their personal preferences)
//
// 1 = yes
// 0 = no
//
$sl_use_GMT = 1;
...修正されたconfig.php:
...
// Log dates in GMT? If you do not do this, dates will
// be logged in whatever timezone each user is in (or
// has set in their personal preferences)
//
// 1 = yes
// 0 = no
//
$sl_use_GMT = 0;
...ダウンロードしたSquirrel Loggerのgzipファイルを削除します:
cd /usr/share/squirrelmail/plugins
rm squirrel_logger-2.3-1.2.7.tar.gzSquirrelMailをSquirrel Loggerプラグインを使用するように設定します:
/usr/share/squirrelmail/config/conf.plSquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1. Organization Preferences
2. Server Settings
3. Folder Defaults
4. General Options
5. Themes
6. Address Books
7. Message of the Day (MOTD)
8. Plugins
9. Database
10. Languages
D. Set pre-defined settings for specific IMAP servers
C Turn color on
S Save data
Q Quit
Command >>Select: PluginsSquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Plugins
Installed Plugins
1. delete_move_next
2. squirrelspell
3. newmail
Available Plugins:
4. listcommands
5. fortune
6. filters
7. translate
8. abook_take
9. spamcop
10. squirrel_logger
11. mail_fetch
12. calendar
13. sent_subfolders
14. message_details
15. administrator
16. info
17. bug_report
R Return to Main Menu
C Turn color on
S Save data
Q Quit
Command >> Select: squirrel_loggerSquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Plugins
Installed Plugins
1. delete_move_next
2. squirrelspell
3. newmail
4. squirrel_logger
Available Plugins:
5. listcommands
6. fortune
7. filters
8. translate
9. abook_take
10. spamcop
11. mail_fetch
12. calendar
13. sent_subfolders
14. message_details
15. administrator
16. info
17. bug_report
R Return to Main Menu
C Turn color on
S Save data
Q Quit
Command >> Select: Save data, Quit3. Fail2banの設定
fail2banの設定ディレクトリに移動します:
cd /etc/fail2banSquirrelMailにhttpトランスポートを使用していると仮定して、viを使用してjail.confファイルに次の行を追加します:
[squirrelmail-iptables]
enabled = true
filter = squirrelmail
action = iptables[name=SquirrelMail, port=http, protocol=tcp]
sendmail-whois[name=SquirrelMail, dest=you@your_domain.com, sender=fail2ban@your_domain.com]
logpath = /var/lib/squirrelmail/prefs/squirrelmail_access_log
maxretry = 4maxretryとdestおよびsenderのメールアドレスが要件に設定されていることを確認してください。
fail2banフィルターディレクトリに移動します:
cd filter.dfilter.dディレクトリで、viを使用して次の内容を持つsquirrelmail.confファイルを作成します:
# Fail2Ban configuration file
#
# Author: Bill Landry ((email_protected))
#
# $Revision: 510 $
[Definition]
# Option: failregex
# Notes.: regex to match the password failures messages in the logfile. The
# host must be matched by a group named "host". The tag "" can
# be used for standard IP/hostname matching and is only an alias for
# (?:::f{4,6}:)?(?P
# Values: TEXT
failregex = \[LOGIN_ERROR\].*from : Unknown user or password incorrect
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
ignoreregex = Fail2banはsquirrelmail_access_logファイルで使用される日付形式を認識する必要があります。
cd /usr/share/fail2ban/serverviを使用してdatedetector.pyファイルを編集し、Apache形式とExim形式のセクションの間に次の行を追加します:
# SquirrelMail 09/13/2007 06:43:20
template = DateStrptime()
template.setName("Month/Day/Year Hour:Minute:Second")
template.setRegex("\d{2}/\d{2}/\d{4} \d{2}:\d{2}:\d{2}")
template.setPattern("%m/%d/%Y %H:%M:%S")
self.__templates.append(template)新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。