All,
thanks for the suggestions.
APIBAN looks fine but still there is the risk of packets from an unknown IP to hit the server.
So I was thinking in patching the parser code to log the src IP in case of error but when I tested sending an invalid message against latest kamailio I got this in the logs:
2024-10-25T07:30:56.970881+09:00 lab225012 /usr/local/src/git/kamailio-5.8/kamailio[1404214]: ERROR: <core> [core/receive.c:378]: receive_msg(): core parsing of SIP message failed (
10.0.0.1:57005/1)
So the function parse_msg itself will not log the src IP but the subsequent ERROR log line from function receive_msg will have it (ip 10.0.0.1) and will also include the port (57005).
So nothing needs to be done as fail2ban can get the ip with the proper filter definition.
However there is at least one other scenario.
I removed the header Call-ID from a valid SIP message and when I sent it I got just this:
2024-10-25T07:41:16.825827+09:00 lab225012 /usr/local/src/git/kamailio-5.8/kamailio[1404217]: ERROR: <core> [core/receive.c:450]: receive_msg(): required headers not found in request
So I could not get the src IP. So am thinking in patching this.
However, meanwhile it seems I can handle this kind of situation generically by using: