PDA

توجه ! این یک نسخه آرشیو شده میباشد و در این حالت شما عکسی را مشاهده نمیکنید برای مشاهده کامل متن و عکسها بر روی لینک مقابل کلیک کنید : نصب fail2ban برای جلوگیری از ورود نامحدود به SquirrelMail



HugeServer
August 16th, 2009, 15:56
با سلام دوستان.

این آموزش به شما نشان خواهد داد که شما چگونه میتوانید با استفاده از fail2ban ، باعث جلوگیری از ورود های نامحدود به وبمیل و brute force attacks جلوگیری کنین.

1. اطمینان حاصل کنین که نرم اقزار های مرتبط قبلا نصب شده است . fail2ban و SquirrelMail .


yum install fail2ban squirrelmail

نکته 1. برای استقاده از این نرم افزار ؛ بر روی سرور شما حتما باید iptables نصب شده باشد، چون این نرم افزار با اضافه کردن رول به iptables کار میکن . ( آموزش نصب iptables قبلا در انجمن ذکر شده )

---------------------------------------------------------------------------------------------------------------------------
2. SquirrelMail logging configuration
SquirrelMail به طور معمولی لاگ های خود را در آدرس /var/log/maillog ذخیره میکند ولی این آدرس و لاگ گیری فقط توسط خود برنامه قابل انجام هست، در صورتی که ما احتیاج لاگ گیری توسط fail2ban را داریم. پس به صورت زیر عمل میکنیم .



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

نکته 2. اگر که سرور شما از ساعت GMT استفاده نمیکند، شما باید در فایل کانفیگ مقدار $sl_use_GMT = 1 را به $sl_use_GMT = 0 تغییر بدهید ، کع این کا را با ادیتور vi یا pico میتوانین انجام بدهید ..



Original 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;
...


Modified 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;
...


نکته 3. شما میتوانی الان فایل Squirrel Logger gzip را پاک کنید.


cd /usr/share/squirrelmail/plugins
rm squirrel_logger-2.3-1.2.7.tar.gz

حالا باید لاگر را کانفیگ کنیم ..


/usr/share/squirrelmail/config/conf.pl


SquirrelMail 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: Plugins




SquirrelMail 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_logger


SquirrelMail 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, Quit

----------------------------------------------------------------------------------------
3. Fail2ban configuration
وارد دایرکتوری Fail2ban بروید و فایل jail.conf را باز کنید .


cd /etc/fail2ban

[LEFT]

[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 = 4


نکته 5. مفدار maxretry را به 4 تغییر بدهید . و ایمیل آدرس dest و sender هم تغییر بدهید.



cd filter.d
حالا باید در اینجا یک فایل به نام 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\S+)
# Values: TEXT

failregex = \[LOGIN_ERROR\].*from <HOST>: 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/server

فایل datedetector.py را باز کنین و قسمت بین Apache format و Exim format sections این را تغییر دهید .


# 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)

حالا سرویس را ری استارت میکنیم service fail2ban restart

حالا میتوانین وارد وبمیل بشوید و امتحان کنین و از آدرس زیر خروجی ها رو بخونین .


cd /var/lib/squirrelmail/prefs
tail -f squirrelmail_access_log


این مقاله ترجمه شده است .
با شکر . BestServer.IR