У меня тот же вопрос. Можно тут продолжить тему.
содержимое jail.conf
Код: Выделить всё
[DEFAULT]
maxretry = 5
findtime = 600
bantime = 12h
ignoreip = 127.0.0.1/8 192.168.0.1/24 11.11.11.11 22.22.22.22 ([i]11.11.11.11 и 22.22.22.22 мои два внешних IP адреса)[/i]
[asterisk]
enabled = true
[asterisk]
port = 5060,5061
action = %(banaction)s[name=%(__name__)s-tcp, port="%(port)s", protocol="tcp", chain="%(chain)s", actname=%(banaction)s-tcp]
%(banaction)s[name=%(__name__)s-udp, port="%(port)s", protocol="udp", chain="%(chain)s", actname=%(banaction)s-udp]
%(mta)s-whois[name=%(__name__)s, dest="%(destemail)s"]
logpath = /var/log/asterisk/full
maxretry = 10
Содержимое fail2ban\filter.d\asterisk.conf (вроде как все дефолтное)
Код: Выделить всё
# Fail2Ban filter for asterisk authentication failures
[INCLUDES]
# Read common prefixes. If any customizations available -- read them from
# common.local
before = common.conf
[Definition]
_daemon = asterisk
__pid_re = (?:\[\d+\])
iso8601 = \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+[+-]\d{4}
# All Asterisk log messages begin like this:
log_prefix= (?:NOTICE|SECURITY|WARNING)%(__pid_re)s:?(?:\[C-[\da-f]*\])? [^:]+:\d*(?:(?: in)? \w+:)?
failregex = ^%(__prefix_line)s%(log_prefix)s Registration from '[^']*' failed for '<HOST>(:\d+)?' - (Wrong password|Username/auth name mismatch|No matching peer found|Not a local domain|Device does not match ACL|Peer is not supposed to register|ACL error \(permit/deny\)|Not a local domain)$
^%(__prefix_line)s%(log_prefix)s Call from '[^']*' \(<HOST>:\d+\) to extension '[^']*' rejected because extension not found in context
^%(__prefix_line)s%(log_prefix)s Host <HOST> failed to authenticate as '[^']*'$
^%(__prefix_line)s%(log_prefix)s No registration for peer '[^']*' \(from <HOST>\)$
^%(__prefix_line)s%(log_prefix)s Host <HOST> failed MD5 authentication for '[^']*' \([^)]+\)$
^%(__prefix_line)s%(log_prefix)s Failed to authenticate (user|device) [^@]+@<HOST>\S*$
^%(__prefix_line)s%(log_prefix)s hacking attempt detected '<HOST>'$
^%(__prefix_line)s%(log_prefix)s SecurityEvent="(FailedACL|InvalidAccountID|ChallengeResponseFailed|InvalidPassword)",EventTV="([\d-]+|%(iso8601)s)",Severity="[\w]+",Service="[\w]+",EventVersion="\d+",AccountID="(\d*|<unknown>)",SessionID=".+",LocalAddress="IPV[46]/(UDP|TCP|WS)/[\da-fA-F:.]+/\d+",RemoteAddress="IPV[46]/(UDP|TCP|WS)/<HOST>/\d+"(,Challenge="[\w/]+")?(,ReceivedChallenge="\w+")?(,Response="\w+",ExpectedResponse="\w*")?(,ReceivedHash="[\da-f]+")?(,ACLName="\w+")?$
^%(__prefix_line)s%(log_prefix)s "Rejecting unknown SIP connection from <HOST>"$
^%(__prefix_line)s%(log_prefix)s Request (?:'[^']*' )?from '[^']*' failed for '<HOST>(?::\d+)?'\s\(callid: [^\)]*\) - (?:No matching endpoint found|Not match Endpoint(?: Contact)? ACL|(?:Failed|Error) to authenticate)\s*$
ignoreregex =
# Author: Xavier Devlamynck / Daniel Black
# General log format - main/logger.c:ast_log
# Address format - ast_sockaddr_stringify
# First regex: channels/chan_sip.c
# main/logger.c:ast_log_vsyslog - "in {functionname}:" only occurs in syslog
в /var/log/fail2ban.log пишется
Код: Выделить всё
2022-12-27 20:51:57,669 fail2ban.filter [27094]: INFO [asterisk] Found 107.189.11.125
2022-12-27 20:52:27,578 fail2ban.filter [27094]: INFO [asterisk] Found 145.131.4.212
2022-12-27 20:53:19,766 fail2ban.filter [27094]: INFO [asterisk] Ignore 22.22.22.22 by ip
2022-12-27 20:53:37,706 fail2ban.filter [27094]: INFO [asterisk] Found 145.131.8.175
2022-12-27 20:54:15,212 fail2ban.filter [27094]: INFO [asterisk] Found 51.222.102.47
2022-12-27 20:54:46,977 fail2ban.filter [27094]: INFO [asterisk] Found 128.90.204.100
2022-12-27 20:54:57,828 fail2ban.filter [27094]: INFO [asterisk] Found 128.90.204.100
2022-12-27 20:55:20,270 fail2ban.filter [27094]: INFO [asterisk] Found 51.255.208.207
2022-12-27 20:55:20,965 fail2ban.filter [27094]: INFO [asterisk] Found 72.167.54.101
2022-12-27 20:55:24,986 fail2ban.filter [27094]: INFO [asterisk] Ignore 22.22.22.22 by ip
2022-12-27 20:56:03,308 fail2ban.filter [27094]: INFO [asterisk] Found 107.189.11.125
2022-12-27 20:56:43,836 fail2ban.filter [27094]: INFO [asterisk] Found 145.131.4.212
в консоли астериска
Код: Выделить всё
[Dec 27 20:51:57] NOTICE[28504]: chan_sip.c:28499 handle_request_register: Registration from '<sip:9223@наш_домен_для_почты_второй>' failed for '107.189.11.125:57513' - Wrong password
[Dec 27 20:52:27] NOTICE[28504]: chan_sip.c:28499 handle_request_register: Registration from '<sip:9860@наш_домен_для_почты_первый>' failed for '145.131.4.212:54717' - Wrong password
[Dec 27 20:53:19] NOTICE[28504][C-00000022]: chan_sip.c:26179 handle_request_invite: Failed to authenticate device <sip:11@22.22.22.22>;tag=1119240214
[Dec 27 20:53:37] NOTICE[28504]: chan_sip.c:28499 handle_request_register: Registration from '<sip:6622@наш_домен_для_почты_второй>' failed for '145.131.8.175:53496' - Wrong password
[Dec 27 20:54:15] NOTICE[28504]: chan_sip.c:28499 handle_request_register: Registration from '<sip:9221@наш_домен_для_почты_первый>' failed for '51.222.102.47:51914' - Wrong password
[Dec 27 20:54:46] NOTICE[28504]: chan_sip.c:28499 handle_request_register: Registration from '<sip:user02@22.22.22.22>' failed for '128.90.204.100:59596' - Wrong password
[Dec 27 20:54:57] NOTICE[28504]: chan_sip.c:28499 handle_request_register: Registration from '<sip:user02@11.11.11.11>' failed for '128.90.204.100:56927' - Wrong password
[Dec 27 20:55:20] NOTICE[28504]: chan_sip.c:28499 handle_request_register: Registration from '<sip:9335@наш_домен_для_почты_первый>' failed for '51.255.208.207:55818' - Wrong password
[Dec 27 20:55:20] NOTICE[28504]: chan_sip.c:28499 handle_request_register: Registration from '<sip:9331@наш_домен_для_почты_второй>' failed for '72.167.54.101:56030' - Wrong password
[Dec 27 20:55:24] NOTICE[28504][C-00000023]: chan_sip.c:26179 handle_request_invite: Failed to authenticate device <sip:11@22.22.22.22>;tag=1506681268
[Dec 27 20:56:03] NOTICE[28504]: chan_sip.c:28499 handle_request_register: Registration from '<sip:9224@наш_домен_для_почты_второй>' failed for '107.189.11.125:60974' - Wrong password
[Dec 27 20:56:43] NOTICE[28504]: chan_sip.c:28499 handle_request_register: Registration from '<sip:1694@наш_домен_для_почты_первый>' failed for '145.131.4.212:53038' - Wrong password
[Dec 27 20:57:37] NOTICE[28504][C-00000024]: chan_sip.c:26179 handle_request_invite: Failed to authenticate device <sip:11@22.22.22.22>;tag=714769043
Получается события
Код: Выделить всё
[Dec 27 20:53:19] NOTICE[28504][C-00000022]: chan_sip.c:26179 handle_request_invite: Failed to authenticate device <sip:11@22.22.22.22>;tag=1119240214
[Dec 27 20:55:24] NOTICE[28504][C-00000023]: chan_sip.c:26179 handle_request_invite: Failed to authenticate device <sip:11@22.22.22.22>;tag=1506681268
игнорируются по причине того что в них указан наш внешний IP адрес
Код: Выделить всё
Содержимое asterisk\logger.conf
[logfiles]
;debug => debug
;security => security
console => notice,warning,error
;console => notice,warning,error,debug
messages => notice,warning,error
full => notice,warning,error,debug,verbose,dtmf,fax
;syslog keyword : This special keyword logs to syslog facility
;
;syslog.local0 => notice,warning,error
;
разблокировал и прописал
Код: Выделить всё
security => security
full => notice,warning,error,debug,verbose,dtmf,fax,security
файл security появился, но все равно такое событие игнорится
что нужно еще сделать?
После внесенные изменений вот так пишется
/var/log/fail2ban.log
2022-12-27 21:56:33,395 fail2ban.filter [29709]: INFO [asterisk] Ignore 22.22.22.22 by ip
лог security
Код: Выделить всё
[Dec 27 21:56:33] SECURITY[29136] res_security_log.c: SecurityEvent="ChallengeSent",EventTV="2022-12-27T21:56:33.273+0200",Severity="Informational",Service="SIP",EventVersion="1",AccountID="sip:11@22.22.22.22",SessionID="0x7f3dec01ce80",LocalAddress="IPV4/UDP/11.11.11.11/5060",RemoteAddress="IPV4/UDP/45.93.16.185/52939",Challenge="2c71ae7f"
[Dec 27 21:56:33] SECURITY[29136] res_security_log.c: SecurityEvent="InvalidPassword",EventTV="2022-12-27T21:56:33.394+0200",Severity="Error",Service="SIP",EventVersion="2",AccountID="70700012526593403",SessionID="0x7f3dec01ce80",LocalAddress="IPV4/UDP/11.11.11.11/5060",RemoteAddress="IPV4/UDP/45.93.16.185/52939",Challenge="2c71ae7f",ReceivedChallenge="2c71ae7f",ReceivedHash="246476342243800fdb7c85ef9bfcfe4e"
лог full
Код: Выделить всё
[Dec 27 21:56:33] SECURITY[29136] res_security_log.c: SecurityEvent="ChallengeSent",EventTV="2022-12-27T21:56:33.273+0200",Severity="Informational",Service="SIP",EventVersion="1",AccountID="sip:11@22.22.22.22",SessionID="0x7f3dec01ce80",LocalAddress="IPV4/UDP/11.11.11.11/5060",RemoteAddress="IPV4/UDP/45.93.16.185/52939",Challenge="2c71ae7f"
[Dec 27 21:56:33] NOTICE[29130][C-0000000d] chan_sip.c: Failed to authenticate device <sip:11@22.22.22.22>;tag=640047713
[Dec 27 21:56:33] SECURITY[29136] res_security_log.c: SecurityEvent="InvalidPassword",EventTV="2022-12-27T21:56:33.394+0200",Severity="Error",Service="SIP",EventVersion="2",AccountID="70700012526593403",SessionID="0x7f3dec01ce80",LocalAddress="IPV4/UDP/11.11.11.11/5060",RemoteAddress="IPV4/UDP/45.93.16.185/52939",Challenge="2c71ae7f",ReceivedChallenge="2c71ae7f",ReceivedHash="246476342243800fdb7c85ef9bfcfe4e"