

This regular expression is quite simple but you should understand that not all matches are technically valid IP addresses. So, please be aware, that this jail only protects you from some kind of DoS attack that targets a large amount of non-existing URLs/pathes, which is mostly the case for malicious vulnerability scans. Parse a file and print all expressions that match a range between 0.0.0.0 and 999.999.999.999. It will ignore any failing GET /robots.txt requests (as most bots request this) and it will not care about "sane" HTTP status codes like 200 (OK), 301 (Moved Permanently), 302 (Found). For our use case, I have created a regex101 with some sample log lines which you can play around with. You might want to tune the failregex to your needs. If this regex matches, the line is ignored. The tag "" # can be used for standard IP/hostname matching and is only an alias for # (?:::f:)?(?P+) # Values: TEXT failregex = ^. # The host must be matched by a group named "host". We're going to scan all customer Apache access.log logfiles which are in a slightly tuned (non-standard) combined log format:įilter.d/nf # Fail2Ban filter to scan Apache access.log for DoS attacks before = nf # Option: failregex # Notes.: regex to match GET requests in the logfile resulting in one of the # following status codes: 401, 403, 404, 503.

Ban the attackers IP if there are more than 300 GET requests during a time span of 5 mins resulting in HTTP non-200 (OK) status codes: 401, 403, 404, 503.

#Apache log grep unique ip install#
