Сб. Апр 27th, 2024

Продолжаю свою серию ебли с допиливанием скриптов по-умолчанию в Fail2Ban.В этот раз столкнулся таки с тем,что фейл2бан не видит безуспешные попытки авторизации в Апаче при стандартной авторизации.Я не говорю уже что если у вас Digest авторизация.Почему то в стандартном скрипте допущена ошибка,и потому он не работает.Вот его пример:

# Fail2Ban configuration file
#
# Author: Cyril Jaquier
#
# $Revision: 728 $
#

[INCLUDES]

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

[Definition]

# Option: failregex
# Notes.: regex to match the password failure 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>[\w\-.^_]+)
# Values: TEXT
#
failregex = ^%(_apache_error_client)s user .* (authentication failure|not found|password mismatch)

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

Смотрим на строчку

failregex = ^%(_apache_error_client)s user .* (authentication failure|not found|password mismatch)

Раньше изначально она выглядела так:

failregex = ^%(_apache_error_client)s user .* (authentication failure|not found|password mismatch)\s*$

И из-за \s*$ в конце она не работала. Потом я методом перебора нашел эту штуку и убрал,после чего скрипт стал видеть попытки и адреса атакующих. Далее я на основе этого сделал скрипт,который видит неудачные попытки при Digest авторизации.Я в папке /etc/fail2ban/filter.d/ создал файл с именем apache-auth-digest.conf и содержимым:

# Fail2Ban configuration file
#
# Author: RUSUA
#
# $Revision: 1 $
#

[INCLUDES]

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

[Definition]

# Option: failregex
# Notes.: regex to match the password failure 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>[\w\-.^_]+)
# Values: TEXT
#
failregex = ^%(_apache_error_client)s Digest: user .* (authentication failure|not found|password mismatch)

# Option: ignoreregex

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

Дальше я просто дописал правило в /etc/fail2ban/jail.conf:

[apache-digest]

enabled = true
port = http,https
filter = apache-auth-digest
logpath = /var/log/apache2/error*.log
maxretry = 3

Главное указать правильно имена и путь ваших логов. Перезагрузите теперь Fail2Ban и проверьте в /var/log/fail2ban.log что б при запуске ловушек были подхвачены ваши логи.Там должен быть отображен их спсисок. Если нет,проверяйте путь и имена логов,иначе работать не будет.

от RUSUA

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Анти-спам: выполните заданиеWordPress CAPTCHA