Skip to content

Fail2ban

andyceo edited this page Aug 18, 2015 · 1 revision

Установка fail2ban

	sudo aptitude install fail2ban

По умолчанию, уже настроены правила для ssh.

Параметры можно посмотреть и поменять в файле /etc/fail2ban/jail.conf.

Существующие фильтры (т.е. правила, по которым определяется неудачная попытка ввода пароля) лежат в директории /etc/fail2ban/filter.d.

Настройка fail2ban для Asterisk

Добавить (раскоментировать) в файле /etc/asterisk/logger.conf

Строчку

[general]
dateformat=%F %T

и к секции

[logfiles]

security => security

в конец файла

/etc/fail2ban/jail.conf

[asterisk-iptables]

enabled  = true
filter   = asterisk
action   = iptables-allports[name=ASTERISK, protocol=all]
       sendmail-whois[name=ASTERISK, dest=root, sender=fail2ban@example.org]
logpath  = /var/log/asterisk/security
maxretry = 5
bantime = 259200

Создать файл

/etc/fail2ban/filter.d/asterisk.conf

с содержимым

# Fail2Ban configuration file
#
#
# $Revision: 250 $
#

[INCLUDES]

# Read common prefixes. If any customizations 	available -- read them from
# common.local
#before = common.conf


[Definition]

#_daemon = asterisk

# 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 "<HOST>" can
#          be used for standard IP/hostname matching 	and is only an alias for
#          (?:::f{4,6}:)?(?P<host>\S+)
# Values:  TEXT
#

failregex = SECURITY.* 	SecurityEvent="FailedACL".*RemoteAddress=".+?/.+?/	<HOST>/.+?".*
            SECURITY.* 	SecurityEvent="InvalidAccountID".*Remo	teAddress=".+?/.+?/<HOST>/.+?".*
            SECURITY.* 	SecurityEvent="ChallengeResponseFailed	".*RemoteAddress=".+?/.+?/<HOST>/.	+?".*
            SECURITY.* SecurityEvent="InvalidPassword".*RemoteAdd	ress=".+?/.+?/<HOST>/.+?".*

# Option:  ignoreregex
# Notes.:  regex to ignore. If this regex matches, the 	line is ignored.
# Values:  TEXT
#
ignoreregex =

Создаём файл

/var/log/asterisk/security

Перезапускаем fail2ban

sudo service fail2ban restart

Источник:

http://habrahabr.ru/post/194356/

Sidebar is under construction

Clone this wiki locally