1. Закрываем доступ через web! Я сделал это внешним фаеролом. Если вы хотите попасть в web конифгуратора elastix создайте ssh туннель с другого хоста.
2. Запретим гостевые вызовы, для этого в файле sip_general_custom.conf пропишем allowguest=no
3. Баним всяких подборщиков паролей и сохраняем для восстановления правил после перезагрузки:
- iptables -I INPUT -j DROP -p udp --dport 5060 -m string --string "friendly-scanner" --algo bm
- iptables -I INPUT -j DROP -p udp --dport 5060 -m string --string "sipcli" --algo bm
- iptables -I INPUT -j DROP -p udp --dport 5060 -m string --string "iWar" --algo bm
- iptables -I INPUT -j DROP -p udp --dport 5060 -m string --string "sipsak" --algo bm
- # /sbin/service iptables save
- Правила брандмауэра сохраняются в /etc/sysconfig/iptables: [ OK ]
touch /etc/fail2ban/filter.d/asterisk.conf
Правила скопипастены (нажмите view plain, чтобы скопировать по-нормальному):
- # Fail2Ban configuration file
- #
- #
- # $Revision: 251 $
- #
- [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
- #
- # Asterisk 1.8 uses Host:Port format which is reflected here
- failregex = NOTICE.* .*: Registration from '.*' failed for ':.*' - Wrong password
- NOTICE.* .*: Registration from '\".*\".*' failed for '' - Wrong password
- NOTICE.* .*: Registration from '\".*\".*' failed for '' - No matching peer found
- NOTICE.* .*: Registration from '.*' failed for '<host>:.*' - No matching peer found
- NOTICE.* .*: Registration from '.*' failed for '<host>:.*' - No matching peer found
- NOTICE.* .*: Registration from '.*' failed for '<host>:.*' - Username/auth name mismatch
- NOTICE.* .*: Registration from '.*' failed for '<host>:.*' - Device does not match ACL
- NOTICE.* .*: Registration from '.*' failed for '<host>:.*' - Peer is not supposed to register
- NOTICE.* .*: Registration from '.*' failed for '<host>:.*' - ACL error (permit/deny)
- NOTICE.* .*: Registration from '.*' failed for '<host>:.*' - Device does not match ACL
- NOTICE.* .*: Registration from '\".*\".*' failed for '<host>:.*' - No matching peer found
- NOTICE.* .*: Registration from '\".*\".*' failed for '<host>:.*' - Wrong password
- NOTICE.* <host> failed to authenticate as '.*'$
- NOTICE.* .*: No registration for peer '.*' \(from <host>\)
- NOTICE.* .*: Host <host> failed MD5 authentication for '.*' (.*)
- NOTICE.* .*: Failed to authenticate user .*@<host>.*
- NOTICE.* .*: <host> failed to authenticate as '.*'
- NOTICE.* .*: <host> tried to authenticate with nonexistent user '.*'
- VERBOSE.*SIP/<host>-.*Received incoming SIP connection from unknown peer
- NOTICE.* .*: Sending fake auth rejection for device.* \(<host>:.*\)
- NOTICE.* .*: Failed to authenticate device.* \(<host>:.*\)
- # Option: ignoreregex
- # Notes.: regex to ignore. If this regex matches, the line is ignored.
- # Values: TEXT
- #
- ignoreregex =
Добавляем в конфиг /etc/fail2ban/jail.conf (изменил немного, в почту слать ничего не надо, добавлены ip адреса игнорирования - внешняя статика и локальная сеть, бан изменен на пожизненный).
- [asterisk-iptables]
- enabled = true
- filter = asterisk
- action = iptables-allports[name=ASTERISK, protocol=all]
- #sendmail-whois[name=ASTERISK,dest=ваш_емаил_куда_слать_сообщения_о_бане, sender=fail2ban@local]
- logpath = /var/log/asterisk/full
- maxretry = 10
- bantime = -1
- ignoreip = 127.0.0.1 XXX.XXX.XXX.XXX 192.168.0.1/24
/etc/init.d/fail2ban start
Статус смотрим командой fail2ban-client status asterisk-iptables или # iptables -L -n (уже забанил :) )
- # fail2ban-client status asterisk-iptables
- Status for the jail: asterisk-iptables
- |- filter
- | |- File list: /var/log/asterisk/full
- | |- Currently failed: 1
- | `- Total failed: 16
- `- action
- |- Currently banned: 1
- | `- IP list: 50.30.35.55
- `- Total banned: 1
Для автостарта fail2ban в файл /etc/rc.d/rc.local добавим строчку /etc/rc.d/init.d/fail2ban start
После рестарта fail2ban или после перезагрузки все адреса сбрасываются. Поэтому можно добавить /sbin/service iptables save в крон. Я думаю раз в час будет достаточно ( /etc/crontab ):
- 0 * * * * root /sbin/service iptables save
Комментариев нет:
Отправить комментарий