banip: update 1.9.1-5

various log monitor fixes/improvements:
- fix bogus IPv6 extraction
- map IPv4-mapped IPv6 addresses to IPv4
- exclude IPv6 loopback/unspecified address
- add haproxy log terms to readme

Signed-off-by: Dirk Brenken <dev@brenken.org>
This commit is contained in:
Dirk Brenken committed 2026-11-02 17:05:50 +01:00
1 parent 24f7c0660b
commit 283ca12bef
3 files changed
+28 -8

No files matched your search

+1 -1
View File
@@ -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 <dev@brenken.org>
+6 -1
View File
@@ -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.
+21 -6
View File
@@ -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"
}