среда, 12 октября 2011 г.

Asterisk и fail2ban или как что делать с iptables

Шаг 1. Установка fail2ban. # apt-get install fail2ban Шаг 2. Установка python и iptables. Возможно вам понадобиться установить эти пакеты, поэтому # apt-get install iptables python Шаг 3. Конфигурация fail2ban. И так, займемся конфигурацией. Для этого перейдем в каталог /etc/fail2ban/filter.d. # cd /etc/fail2ban/filter.d Создаем новый фильтр: # touch asterisk.conf Содержимое файла /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 "" can # be used for standard IP/hostname matching and is only an alias for # (?:::f{4,6}:)?(?P\S+) # Values: TEXT failregex = NOTICE.* .*: Registration from '.*' failed for '' - Wrong password NOTICE.* .*: Registration from '.*' failed for '' - No matching peer found NOTICE.* .*: Registration from '.*' failed for '' - Username/auth name mismatch NOTICE.* .*: Registration from '.*' failed for '' - Device does not match ACL NOTICE.* failed to authenticate as '.*'$ NOTICE.* .*: No registration for peer '.*' \(from \) NOTICE.* .*: Host failed MD5 authentication for '.*' (.*) NOTICE.* .*: Failed to authenticate user .*@.* # Option: ignoreregex # Notes.: regex to ignore. If this regex matches, the line is ignored. # Values: TEXT ignoreregex = Шаг 4. Редактируем /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/messages (Тут внимательно! Посмотрите где у вас логи храняться!) maxretry = 5 bantime = 259200 Шаг 5. Логирование Asterisk. Открываем /etc/asterisk/logger.conf и раскомментируем: [general] dateformat=%F %T В консоли перегружаем сервис логирования: # asterisk -rx "logger reload" Шаг 6. Запуск. # /etc/init.d/iptables start Проверим: # iptables -L -v Должно появиться что то типа этого: # iptables -L -v Chain INPUT (policy ACCEPT 20100 packets, 3866K bytes) pkts bytes target prot opt in out source destination 62 5692 fail2ban-ssh tcp -- any any anywhere anywhere multiport dports ssh 2049 471K fail2ban-ASTERISK all -- any any anywhere anywhere Chain FORWARD (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination Chain OUTPUT (policy ACCEPT 18948 packets, 5246K bytes) pkts bytes target prot opt in out source destination Chain fail2ban-ASTERISK (1 references) pkts bytes target prot opt in out source destination 2049 471K RETURN all -- any any anywhere anywhere Chain fail2ban-ssh (1 references) pkts bytes target prot opt in out source destination 62 5692 RETURN all -- any any anywhere anywhere Шаг 7. Автозапуск fail2ban и iptables: # update-rc.d iptables defaults # update-rc.d fail2ban defaults

Комментариев нет:

Отправить комментарий