Я написал собственный джейл и фильтр в fail2ban для входа в мою службу. Файл журнала находится в /var/log/motion/motion.log
, и при неудачном входе в систему появляется такая строка:
[0:ml1] [ALR] [STR] [Nov 02 11:42:59] handle_basic_auth: motion-stream - failed auth attempt from <ip>
Моя тюрьма в /etc/fail2ban/jail.local
выглядит так:
[motion-auth]
enabled = true
port = 8008
filter = motion-auth.conf
logpath = /var/log/motion/motion.log
banaction = %(banaction_allports)s
maxretry = 3
findtime = 10800
bantime = 259200
И мой фильтр в /etc/fail2ban/filter.d
с именем motion-auth.conf
выглядит так:
[Definition]
failregex = \[0:ml1\] \[ALR\] \[STR\] \[.*\] handle_basic_auth: motion-stream - failed auth attempt from <HOST>
Когда я запускаю fail2ban-regex /var/log/motion/motion.log /etc/fail2ban/filter.d/motion-auth.conf
Я получаю подтверждение того, что мой фильтр работает так, как задумано:
Running tests
=============
Use failregex filter file : motion-auth, basedir: /etc/fail2ban
Use log file : /var/log/motion/motion.log
Use encoding : UTF-8
Results
=======
Failregex: 186 total
|- #) [# of hits] regular expression
| 1) [186] \[0:ml1\] \[ALR\] \[STR\] \[.*\] handle_basic_auth: motion-stream - failed auth attempt from <HOST>
`-
Ignoreregex: 0 total
Date template hits:
|- [# of hits] date format
| [2640] (?:DAY )?MON Day %k:Minute:Second(?:\.Microseconds)?(?: ExYear)?
`-
Lines: 2929 lines, 0 ignored, 186 matched, 2743 missed
[processed in 1.06 sec]
Но когда Я пытаюсь перезагрузить/перезапустить fail2ban, чтобы добавить свой новый фильтр. Я получаю следующее сообщение:
Found no accessible config files for 'filter.d/motion-auth.conf' under /etc/fail2ban
Unable to read the filter 'motion-auth.conf'
Errors in jail 'motion-auth'. Skipping...
OK
Кто-нибудь знает, что я делаю неправильно?
Со страницы руководства для jail.conf:
фильтр
имя фильтра --имя файла фильтра в /etc/fail2ban/filter.d/ без расширения.conf/.local . Только один можно указать фильтр.
Fail2ban, вероятно, ищет файл с именем motion-auth.conf.conf
.
Ваш джейл должен быть:
[motion-auth]
enabled = true
port = 8008
filter = motion-auth
...
Если ваш фильтр под /etc/fail2ban/filter.d/
соответствует имени джейла (, как здесь motion-auth.conf
для [motion-auth]
, , вам не нужно указывать фильтр , это значение по умолчанию.