diff --git a/net/banip/Makefile b/net/banip/Makefile index 0181342d7c..4702506afa 100644 --- a/net/banip/Makefile +++ b/net/banip/Makefile @@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=banip PKG_VERSION:=1.9.1 -PKG_RELEASE:=4 +PKG_RELEASE:=5 PKG_LICENSE:=GPL-3.0-or-later PKG_MAINTAINER:=Dirk Brenken diff --git a/net/banip/README.md b/net/banip/README.md index f4f877d0ec..70eb2e0b4e 100644 --- a/net/banip/README.md +++ b/net/banip/README.md @@ -442,7 +442,12 @@ For every matched line banIP picks the attacker's address out of the log entry. Some formats instead lead with the source IP — most notably web-server access logs, where the client address is the first field. For those, prefix the term with `first:`: ``` -nginx : 'first:"[A-Z]+ /wp-login\.php[^"]*" 40[13]' +nginx : 'first:"[A-Z]+ /wp-login\.php[^"]*" 40[13]' +haproxy1 : 'first:haproxy .* SSL handshake failure .*error:.*:wrong version number' +haproxy2 : 'first:haproxy .* SSL handshake failure .*error:.*:http request' +haproxy3 : 'first:haproxy .* SSL handshake failure .*error:.*:unsupported protocol' +haproxy4 : 'first:haproxy .* SSL handshake failure .*error:.*:no shared cipher' +haproxy5 : 'first:haproxy .* SSL handshake failure .*error:.*:bad key share' ``` The `first:`/`last:` prefix is parsed off before matching and applies only to that single term, so terms with different anchors can be mixed freely. diff --git a/net/banip/files/banip-functions.sh b/net/banip/files/banip-functions.sh index a24ccfb209..7f0a4191d0 100644 --- a/net/banip/files/banip-functions.sh +++ b/net/banip/files/banip-functions.sh @@ -3017,12 +3017,28 @@ f_monitor() { ;; esac } | ban_logterm_map="${ban_logterm_map}" "${ban_awkcmd}" -v threshold="${ban_logcount}" -v limit=5000 ' - function pick_ip(s, mode, m, res) { + function valid_ip(c, n) { + if (c ~ /\./) return 1 + if (c !~ /[A-Fa-f0-9]/ || c ~ /:::/ || c ~ /::.*::/) return 0 + n = gsub(/:/, ":", c) + return (c ~ /::/) ? (n <= 7) : (n == 7) + } + function pick_ip(s, mode, m, res, c, pre, last) { res = "" + last = " " while (match(s, /([0-9]{1,3}\.){3}[0-9]{1,3}|([A-Fa-f0-9]{0,4}:){2,7}[A-Fa-f0-9]{0,4}/, m)) { - res = m[0] - if (mode == "first") break + c = m[0] + pre = (RSTART > 1) ? substr(s, RSTART - 1, 1) : last + last = substr(c, length(c), 1) s = substr(s, RSTART + RLENGTH) + if (c ~ /^:[^:]/) { + c = substr(c, 2) + pre = ":" + } + if (c ~ /[^:]:$/) c = substr(c, 1, length(c) - 1) + if (pre ~ /[A-Za-z0-9_]/ || !valid_ip(c)) continue + res = c + if (mode == "first") break } return res } @@ -3044,7 +3060,7 @@ f_monitor() { } { pos = all_last ? "last" : anchor_for($0) - $0 = gensub(/(([0-9]{1,3}\.){3}[0-9]{1,3}):[0-9]+/, "\\1", "g", $0) + $0 = gensub(/(^|[^A-Fa-f0-9:])::[Ff]{4}:(([0-9]{1,3}\.){3}[0-9]{1,3})/, "\\1\\2", "g", $0) sub(/\]:[0-9]+/, "]", $0) gsub(/[<>[\]]/, "", $0) ip = "" @@ -3056,8 +3072,7 @@ f_monitor() { proto = ".v4" } } else if (cand ~ /:/) { - sub(/%.*/, "", cand) - if (cand !~ /^[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}$/ && cand !~ /^([A-Fa-f0-9]{2}:){5}[A-Fa-f0-9]{2}$/) { + if (cand !~ /^[0:]*(:0*1)?$/) { ip = cand proto = ".v6" }