fail2ban failregex: udp: bad checksum

Einrichten des lokalen Netzes, Verbindung zu anderen Computern und Diensten.
Antworten
serecords
Beiträge: 124
Registriert: 14.11.2012 21:53:37

fail2ban failregex: udp: bad checksum

Beitrag von serecords » 10.07.2014 19:31:28

Hallo,

ich muss fail2ban so konfigurieren, dass es "UDP: Bad checksum" bannt.
Das hatte ich bei meiner Suche gefunden, jedoch kommt ein Error im failregex beim Neustart von fail2ban.

http://blog.colundrum.com/post/59096659 ... d-checksum

Kann mir jemand den Fehler aufzeigen?

Cae
Beiträge: 6349
Registriert: 17.07.2011 23:36:39
Wohnort: 2130706433

Re: fail2ban failregex: udp: bad checksum

Beitrag von Cae » 10.07.2014 20:07:14

serecords hat geschrieben:Kann mir jemand den Fehler aufzeigen?
Nein. Woher soll ich wissen, was deine Fehlermeldung ist? Siehe auch [1,2]. Die Anleitung selbst scheint soweit okay zu sein, abgesehen davon, dass sie auf franzoesisch und somit nicht international lesbar ist.

Gruss Cae

[1] https://wiki.debianforum.de/Benutzer:Cae#Grund_eins
[2] https://wiki.debianforum.de/Benutzer:Cae#Grund_vier
If universal surveillance were the answer, lots of us would have moved to the former East Germany. If surveillance cameras were the answer, camera-happy London, with something like 500,000 of them at a cost of $700 million, would be the safest city on the planet.

—Bruce Schneier

serecords
Beiträge: 124
Registriert: 14.11.2012 21:53:37

Re: fail2ban failregex: udp: bad checksum

Beitrag von serecords » 10.07.2014 20:10:59

Sorry, da hatte ich mich ungünstig ausgedrückt und kein Log angehängt.

Code: Alles auswählen

fail2ban.filter : ERROR  Unable to compile regular expression 'UDP: bad checksum. From (?:::f{4,6}:)?(?P(?:::f{4,6}:)?(?P<host>[\w\-.^_]+)[\w-.^_]+)'

Cae
Beiträge: 6349
Registriert: 17.07.2011 23:36:39
Wohnort: 2130706433

Re: fail2ban failregex: udp: bad checksum

Beitrag von Cae » 10.07.2014 20:40:40

Klassisch wuerde man da die RegEx so lange kuerzen, bis sie sich kompilieren laesst und das mit fail2ban-regex testen:

Code: Alles auswählen

# fail2ban-regex /var/log/kern.log /etc/fail2ban/filter.d/udp-checksum.conf
Ich kann den Fehler nachvollziehen, verstehe aber nicht wirklich, auf was die RegEx matchen soll. [Edit: da war ein Typo drin, deshalb hat das keinen Sinn ergeben. So funktioniert es. Kannst du mal ein paar passende Zeilen aus dem kern.log posten (IP-Adressen bitte in der Form a.b.c.d zensieren)?] [Edit#2: Der Typo ist auch in der Vorlage drin, daher der Fehler. Es soll hinten \- anstatt - heissen (man haette auch einfach das - an den "Rand" von [] packen koennen und damit das Problem vermeiden koennen...) :

Code: Alles auswählen

(?P<host>[\w-.^_]+)
(?P<host>[\w\-.^_]+)
Der Teil ist ohnehin als <HOST> (in Grossbuchstaben) als Alias verfuegbar, daher geht auch die Kurzform

Code: Alles auswählen

[Definition]
failregex = UDP: bad checksum. From <HOST>
#failregex = UDP: bad checksum. From (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
ignoreregex =
]

Gruss Cae
If universal surveillance were the answer, lots of us would have moved to the former East Germany. If surveillance cameras were the answer, camera-happy London, with something like 500,000 of them at a cost of $700 million, would be the safest city on the planet.

—Bruce Schneier

serecords
Beiträge: 124
Registriert: 14.11.2012 21:53:37

Re: AW: fail2ban failregex: udp: bad checksum

Beitrag von serecords » 10.07.2014 20:54:39

Also matchen soll es das hier:

Code: Alles auswählen

Jul 10 20:40:43 server kernel: [   92.642850] UDP: bad checksum. From a.b.c.d:19 to a.b.c.d:5223 ulen 6927
Jul 10 20:40:43 server kernel: [   92.745146] UDP: bad checksum. From a.b.c.d:19 to a.b.c.d:5223 ulen 1505
Jul 10 20:40:43 server kernel: [   92.831096] UDP: bad checksum. From a.b.c.d:19 to a.b.c.d:5223 ulen 1571
Jul 10 20:40:43 server kernel: [   92.915855] UDP: bad checksum. From a.b.c.d:19 to a.b.c.d:5223 ulen 1626

Cae
Beiträge: 6349
Registriert: 17.07.2011 23:36:39
Wohnort: 2130706433

Re: fail2ban failregex: udp: bad checksum

Beitrag von Cae » 10.07.2014 21:11:50

Ich hab' zwischenzeitlich oben drin rumeditiert und war zu dem Schluss gekommen, dass da ein Typo in der Vorlage ist (die vielleicht demnaechst korrigiert wird, wenn der Mensch auf meine Mail reagiert...). Wenn du das - in der RegEx zu \- korrigierst, sollte es matchen.

Gruss Cae
If universal surveillance were the answer, lots of us would have moved to the former East Germany. If surveillance cameras were the answer, camera-happy London, with something like 500,000 of them at a cost of $700 million, would be the safest city on the planet.

—Bruce Schneier

serecords
Beiträge: 124
Registriert: 14.11.2012 21:53:37

Re: fail2ban failregex: udp: bad checksum

Beitrag von serecords » 10.07.2014 21:17:29

Also die Datei sieht jetzt so aus:

Code: Alles auswählen

# Fail2Ban configuration file
#
# Author: Florent CARRÉ aka COLUNDRUM <colundrum@gmail.com>
#
# $Revision$
#
[Definition]
# Option: failregex
# Notes.: regex to match the UDP: bad checksum messages in the logfile. The
# host must be matched by a group named “host”. The tag “<HOST>”
# fails on test.
# Values: TEXT
#
failregex = UDP: bad checksum. From (?:::f{4,6}:)?(?P<host>[\w\-.^_]+)
# Option: ignoreregex
# Notes.: regex to ignore. If this regex matches, the line is ignored.
# Values: TEXT
#
ignoreregex =
Ich hab den regex Test gemacht und das Ergebnis sind 0 results:

Code: Alles auswählen

~# fail2ban-regex /var/log/kern.log /etc/fail2ban/filter.d/udp-checksum.conf

Running tests
=============

Use regex line : /etc/fail2ban/filter.d/udp-checksum.conf
Use log file   : /var/log/kern.log

No 'host' group in '/etc/fail2ban/filter.d/udp-checksum.conf'
Cannot remove regular expression. Index 0 is not valid

Results
=======

Failregex
|- Regular expressions:
|  [1] /etc/fail2ban/filter.d/udp-checksum.conf
|
`- Number of matches:
   [1] 0 match(es)

Ignoreregex
|- Regular expressions:
|
`- Number of matches:

Summary
=======

Sorry, no match

Look at the above section 'Running tests' which could contain important
information.

serecords
Beiträge: 124
Registriert: 14.11.2012 21:53:37

Re: fail2ban failregex: udp: bad checksum

Beitrag von serecords » 11.07.2014 11:12:22

Also ich wollte damit sagen, dass es 0 matches gibt, obwohl die kern.log voll mit diesen Meldungen ist.

Also muss es doch noch irgendwo einen Fehler geben?

abnort
Beiträge: 1
Registriert: 02.07.2015 16:50:43

Re: fail2ban failregex: udp: bad checksum

Beitrag von abnort » 02.07.2015 17:10:05

Hallo,

für alle die es vielleicht gebrauchen können, ich habe verschiedene Konfigurationen ausprobiert, so wie unten ist die beste Methode und der ban ist auch wirksam, dieses action = route Methode funktioniert bei mir nicht und es wird auch nichts gebannt...

System:
Debian Jessie 8.1
Fail2Ban v0.8.13

/etc/fail2ban/jail.conf

Code: Alles auswählen

[udp-badchecksum]
enabled = true
port     = all
banaction = iptables-allports
port     = anyport
filter = udp-badchecksum
protocol = udp
logpath = /var/log/kern.log
maxretry = 2
/etc/fail2ban/filter.d/udp-badchecksum.conf

Code: Alles auswählen

# Fail2Ban configuration file
#
#
#
[INCLUDES]
# Read common prefixes. If any customizations available -- read them from
# common.local
before = common.conf

[Definition]
# Option: failregex
# Notes.: regex to match the UDP: bad checksum messages in the logfile. The
# host must be matched by a group named “host”. The tag “<HOST>”
# fails on test.
# Values: TEXT
#
failregex = UDP: bad checksum. From <HOST>

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

Code: Alles auswählen

[ddos]
enabled = true
port     = all
banaction = iptables-allports
port     = anyport
protocol = udp
filter = ddos
logpath = /var/log/kern.log
maxretry = 2
/etc/fail2ban/filter.d/ddos.conf

Code: Alles auswählen

# Fail2Ban configuration file
#
#
#
[INCLUDES]

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

[Definition]

# Option:  failregex
# Notes.:  Auto block short UDP.
# Values:  TEXT
#
failregex = UDP: short packet: From <HOST>

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

Antworten