- the local allowlist is always read as is now, only the remote part
is backed up ('banIP.allowlist.remote.gz') and restored, on
(re-)start like the other feeds, on reload only after a download
error
Signed-off-by: Dirk Brenken <dev@brenken.org>
* add configurable burst limits for the ICMP, SYN and UDP DoS safeguards
('ban_icmpburstlimit', 'ban_synburstlimit', 'ban_udpburstlimit'),
default '5' (nft default, no change of the effective ruleset),
empty, zero or non-numeric values fall back to '5'
* apply the burst limit to the log and the drop rule of each safeguard
* show the burst limits in the status (nft_info) and debug output
* add new feeds: abuseipdb and threatfox (requires auth-key)
* readme update
Fixes: #31462
Signed-off-by: Dirk Brenken <dev@brenken.org>
* log monitor: fix the IP extraction for OpenVPN ('[AF_INET]<ip>:<port>')
* log monitor: validate IPv4 octets/IPv6 groups, skip partial matches
* fix config parsing of values with quotes (broke the asterisk log term)
* readme: fix the asterisk, AdGuardHome, nginx, haproxy and openvpn log terms
* deduplicate only across feeds with the same direction and port limitation,
add IPs only after a successful Set load, remove 'ban_feedcomplete'
* limit the RDAP subnet blocking to /24 (IPv4) and /48 (IPv6),
oversized IPv6 ranges fall back to the /64 of the IP
* tighten the IPv6 and MAC/IP validation of feeds and local lists
* don't retry nft loads with syntax or element errors, log the nft error
* remove port limitation from the urlhaus, hagezi and webclient feeds
* remove the outdated urlvir feed
* readme: point to the prebuilt basemaps (json-basemaps)
Signed-off-by: Dirk Brenken <dev@brenken.org>
- always count feed rule hits (restore old behavior);
'ban_nftcount' now controls only the per-element counters
and the base chain rule counters
- reduce the memory footprint of Set element counts,
new awk helper 'f_setcnt' (replace jsonfilter)
- reduce the memory footprint of the Set Reporting,
new awk helper 'f_sethits' (replace jsonfilter)
- readme update
Signed-off-by: Dirk Brenken <dev@brenken.org>
- add a new generic 'ban_authkey' option and an '{authkey}' feed URL
placeholder for sources which require a personal API-Key, feeds with
this placeholder are skipped as long as no valid key is set
- mask the key in the debug error log
- switch the 'urlhaus' feed to the authenticated 'urls_recent.txt' export
(requires a free abuse.ch Auth-Key); the old IDS ruleset URL is frozen
since 2024-10
- readme update
Signed-off-by: Dirk Brenken <dev@brenken.org>
- use the GNU regex matchers with gawk >= 5.4;
gawk 5.4 switched its default regex engine to MinRX, this
slows down the ip validation a lot (~35x slower)
Signed-off-by: Dirk Brenken <dev@brenken.org>
- faster IPv4 validation in f_chkip (~2-3 × faster)
- avoid full nft element fetches in the following functions:
f_actual, f_down (reload & count) and f_search
Signed-off-by: Dirk Brenken <dev@brenken.org>
* use RDAP startAddress/endAddress as a single interval element (one nft call per lookup)
* validate RDAP ranges, block nft command and log line injection
* always restart the procd instance (unique nonce via env)
* restart the log monitor if the log reader terminates (e.g. logd restart)
* f_rmpid clears the pidfile before killing child processes
* EXIT trap: route unexpected service exits through f_log "err"
* readme update
Signed-off-by: Dirk Brenken <dev@brenken.org>
- add the trigger interfaces to the runtime status
- support url templates for the country and asn feeds;
the readme contains an example of how to use an alternative
MaxMind source as country feed
- fix the fallback handling of the custom feed file
- disable the curl url globbing
- drop the unsupported 'w' nft expiry unit
- LuCI: show the trigger interfaces, label the board model
- LuCI: drop the unsupported 'w' expiry unit
- LuCI: fix the custom feed file handling
- readme update
Signed-off-by: Dirk Brenken <dev@brenken.org>
- cap the GeoIP lookup at 15 batch requests per report run (ip-api.com rate limit)
- reuse the map data for 60 seconds instead of querying the service again
- log batch requests without geo data
- limit the parallel background jobs exactly to `ban_cores (same as adblock)
- LuCI: fix the GeoIP map description
- readme update
Signed-off-by: Dirk Brenken <dev@brenken.org>
- f_getup() collects the wan state in one pass and diffs the uplink against
the local allowlist
- new f_refresh() patches only the changed allowlist Set elements
in a single atomic nft transaction, without touching the running instance
- the procd trigger calls start refresh, start_service() picks the path, a manual start is unaffected
- wan6 in ban_trigger is supported now
- updatted the README and moved to the package root
- LuCI: reworked the feed editor, get rid of custom css
Signed-off-by: Dirk Brenken dev@brenken.org
Signed-off-by: Dirk Brenken <dev@brenken.org>
CARTO now requires an API key for the raster basemaps at basemaps.cartocdn.com and watermarks every unauthenticated tile request, so the GeoIP map currently renders "API KEY REQUIRED" across the whole viewport.
Therefore in luci-app-banip the basemap is now drawn from country outlines that ship with the package: Natural Earth 1:110m, public domain, all attributes stripped, simplified to 36 kB (~10 kB in the apk).
readme changes in the base package only
Signed-off-by: Dirk Brenken <dev@brenken.org>
* new option ban_monitorallowed: in allowlist-only mode
the log monitor only honours the local allowlist, so attackers
from an explicitly allowed segment can be banned (fixesopenwrt/luci#8950)
* adds the allowlist.local.v4/.v6 Sets, built from /etc/banip/banip.allowlist only,
referenced by no rule
* allowlist-only mode: skip only those external feeds whose direction is
fully covered by the allowlist, instead of skipping all or none — split Sets included
* f_lookup keeps the monitor Set in sync with resolved domains
* f_restore: no more bogus per-proto restore attempts for the allowlist
* f_report: batched and deduplicated geo lookups, correct Set names in the report
* readme update
Signed-off-by: Dirk Brenken <dev@brenken.org>
- only cap the cpu core count by available memory if it was auto-detected,
a manually set 'ban_cores' is now authoritative and no longer lowered
- readme update: clarify that the auto-cap does not apply to a manually
set core count
Signed-off-by: Dirk Brenken <dev@brenken.org>
The runtime status reported the last run as DD/MM/YYYY, which reads as a
different date entirely for anyone used to month first ordering.
Use YYYY-MM-DD instead for the frontpage and the Set reporting.
The new ISO 8601 format is unambiguous regardless of the reader's locale.
Signed-off-by: Dirk Brenken <dev@brenken.org>
- better extract Uplink addresses
- the map array anchor was written inside the runtime file branch,
so a missing runtime file dropped the entire map instead of just the local marker
Signed-off-by: Dirk Brenken <dev@brenken.org>
- fixed log monitor source-IP spoofing (GHSA-r6hx-4f83-vp8m)
Fix: per-ban_logterm source anchoring — the real source (last IP in the line)
is used by default; opt-in 'first:' prefix for source-first formats (web-server access logs).
- add f_mem() helper to read MemAvailable from /proc/meminfo
- cap the auto-detected CPU core count by available memory in f_system:
ban_cores is limited to MemAvailable / 48 (MiB per job), floored to at least 1 core;
this bounds the number of feeds processed in parallel on constrained devices,
a user-set ban_cores is still honored as a ceiling (the cap only ever lowers it).
- derive the GNU sort buffer size from available memory, applied only when
coreutils sort is present; busybox sort is a no-op
Signed-off-by: Dirk Brenken <dev@brenken.org>
default feed updates:
- urlhaus, urlvir, webclient: switched from in to out
and added a tcp udp 80 443 port limit (destination feeds for LAN-initiated traffic)
- feodo, spamhaus, threat, threatview, proxy, tor, vpn, vpndc: switched from in to inout
- threatview: added url_6, as the source ships IPv4 and IPv6 in a single file
- country / asn: intentionally left on in; documented how to switch them to outbound/both
for the recurring "block connections to country X" case
- readme update:
- corrected the feed table to match the above,
- removed the stale drop row (replaced by spamhaus),
- and reworked the chain explanation to clarify the inbound-vs-outbound (source-IP vs destination-IP) model
- significantly expanded the custom-feeds section (all JSON fields, rule parameters, etc.
Signed-off-by: Dirk Brenken <dev@brenken.org>
* bugfix: only load the configuration once per run: a new `ban_confload`
guard short-circuits `f_conf()` on subsequent calls, avoiding
repeated `config_load` invocations
* new: the per-set report now sorts elements by their packet counter in
descending order before truncating to the top 50, so the report
shows the most active elements instead of just the first 50 found
Signed-off-by: Dirk Brenken <dev@brenken.org>
- gated config sanity checks at the end of banip-functions.sh
behind 'ban_action' to skip them on init script sourcing paths (enable/disable/help)
- added a ubus socket guard around f_system to harden against pre-ubus sourcing
- added a 'ban_bver' fallback in f_log for sourcing paths without prior f_system execution
- reordered system utility references before system library sourcing,
so f_log has a valid 'ban_logcmd' available if the library check fails
- minor code improvements and fixes
Signed-off-by: Dirk Brenken <dev@brenken.org>
- optimized pidfile handling in the init file
- small cornercase fixes & improvements
- drop deprecated 'drop' feed (replaced by 'spamhaus' json feed with the same content)
- LuCI: expose the new JSON Lines Format in the feed editor
- readme update
Signed-off-by: Dirk Brenken <dev@brenken.org>
- introduced a shared named nft limit (loglimit) referenced by
all log rules instead of per-rule limits, aligning with kernel printk rate limits
- added new 'ban_logratelimit' and 'ban_logburstlimit' UCI options for tuning
the shared log limit; setting ban_logratelimit=0 disables nft-side rate limiting
entirely (useful for ulogd or other userspace log handlers that bypass printk)
- LuCI: made the new UCI option available (Log Settings)
- readme update
Signed-off-by: Dirk Brenken <dev@brenken.org>
* flock/serialize the etag writing in the f_etag function
* added various variables to local scope
* LuCI: removed needless ACL
Signed-off-by: Dirk Brenken <dev@brenken.org>
* fixed the initialization of the banIP rundir (reported in the forum)
* sanitize possible windows line endings in local block- and allowlist
* refine the cpu/core detection
* code clean-up/linting
Signed-off-by: Dirk Brenken <dev@brenken.org>
* fixed two issues in the mail template, reported in the forum
* tweak the f_report function
* changed the f_actual function to reduce subshell calls
* further optimize the monitor function:
* fixed a possible RDAP rate-limit race condition,
serialize the rdap_tsfile via flock
* block_cache bounded growth, when the cache reaches 500
entries it resets to empty, preventing unbounded string growth
in the monitor loop
* set the printf format string in single quotes (overall)
Signed-off-by: Dirk Brenken <dev@brenken.org>
* removed needless fork/exec calls (#29010)
* removed needless eval calls
* added parallel country and ASN feed downloads (#29010)
* rework the IP monitor:
* IP extraction, counting, and threshold detection now run
entirely inside a single gawk process
* added a dynamic cache management and a three-tier IP deduplication
* added asynchronous/non-blocking RDAP requests
* hardend the cgi script and mail template
* fixed#28998
* LuCI: added more status information
* LuCI: more fixes & optimizations (e.g. #8486)
* readme update
Co-authored-by: Colin Brown <devs@coralesoft.nz>
Signed-off-by: Dirk Brenken <dev@brenken.org>
* add better input validation to the f_content and f_search functions,
to compensate for the very limited Wildcard ACL mechanisms in LuCI, see
https://github.com/openwrt/luci/issues/8435 for reference
* LuCI: add a proper poll mechanism to mitigate Reporting timeouts
on "Search" and "Refresh", even with big Sets
* LuCI: Refine some ACLs
* LuCI: more fixes & optimizations
* readme update
Signed-off-by: Dirk Brenken <dev@brenken.org>
* the debug mode now captures internal error output in a dedicated log file,
located by default in the banIP base directory as /tmp/ban_error.log
* replaced the non-functional recursive PID tree walk in f_rmpid with
a correct iterative implementation
* added several IP validator improvements
* fixed a copy-paste error in f_report
* fixed a uninitialized variable in f_actual
* fixed missing token validation in banip.cgi
* various other minor improvement & fixes
* removed abandoned nixspam feed
* LuCI: various fixes & optimizations
* readme update
Signed-off-by: Dirk Brenken <dev@brenken.org>
* hardened the uci config parsing
* added a fast, flexible & secure IPv4/IPv6 validator function, it eliminates > 99 % of garbage inputs
Please note: The ‘rule’ in the feed file now only contains parameters for the IP validator;
details can be found in the readme file. Old custom feed files are not compatible and will be
backed up/removed via the uci-defaults script
* added BCP38 support: to block packets with spoofed source IP addresses in all supported chains
* optimized the log monitor plus performance improvements
* removed the pallebone feed (discontinued)
* added the ipexdbl feed
* various small improvements
* LuCI: add the BC38 option under Table/Chain Settings
* LuCI: updating the custom feed editor
* LuCI: small usability improvements
* readme update
Signed-off-by: Dirk Brenken <dev@brenken.org>
* split block/logging rules (fixed#27990)
* adapt reload functions to support the new split logic
* the banIP status now includes the backend- and the frontend version information
* fixed a config parsing error with non existing dirs (reported in the forum)
* fixed a small reporting issue (reported in the forum)
* added a new public dns feed (by default restricted to outbound, ports 53 and 853)
* added a new gawk dependency due to significant performance gains
* LuCI: no longer call the logread binary, use rpc / the ubus log object instead
* LuCI: various code cleanups
* LuCI: various small usability improvements
* readme update
Signed-off-by: Dirk Brenken <dev@brenken.org>
* skip rdap requests/replies with placeholders for all IPv4/IPv6 addresses
* sanitize possible bogus config values, e.g. '/dev/null' as a directory
* change URL for beycyber feed
Signed-off-by: Dirk Brenken <dev@brenken.org>
* limit nft logging to a rate 10/second to prevent possible log-flooding
* skip external feed processing if "allowlist-only" mode is fully enabled (in in- and outbound)
* remove needless default icmpv6 rule in wan-input
* refine the housekeeping script (uci-defaults)
* readme update
Signed-off-by: Dirk Brenken <dev@brenken.org>
* fixed the restore rc handling
* skip allowlist entries during map creation
* disable the map button by default (only enabled if map & NFT counter are selected)
* disable the content filter checkbox for elements with hits by default (only enabled if NFT counter are selected)
* readme update
Signed-off-by: Dirk Brenken <dev@brenken.org>
* show the IP plus the packet counter in the modal Set content view (or on the CLI)
* add a filter to show only elements with hits in the modal Set content view (or on the CLI)
* limit the element output with hits to max. 50 per Set on the Set Reporting overview page
* fixed set names suffix in the report output
* fixed the Set content view for MAC based Sets
* display the map even if the HomeIP cannot be determined
Signed-off-by: Dirk Brenken <dev@brenken.org>
* add an uci-defaults script for housekeeping and option migration from former versions
* small fixes and improvements
Signed-off-by: Dirk Brenken <dev@brenken.org>
* the ETAG function now supports country and asn feeds as well
* fixed becyber URL and other small fixes
* LuCI fixes and improvements (separate commit)
Signed-off-by: Dirk Brenken <dev@brenken.org>
* fixed a JSON reporting issue (when the map and NFT counters are disabled)
* optimized the getfetch function call within the reporting function
* removed the stale IPv6 links in the becyber feed
* cosmetics
Signed-off-by: Dirk Brenken <dev@brenken.org>
* added a geoIP Map to show home IPs and potential attacker IPs on a leafletjs based map
* significantly improved the reporting performance on multicore hardware
* removed aria2 support (it doesn't support post data requests)
* removed the following outbound feeds due to too many false positives:
adaway, adguard, adguardtrackers, antipopads, oisdbig, oisdnsfw, oisdsmall, stevenblack and yoyo
* renamed the banIP command "survey" to "content"
* various other small tweaks
* update the readme
Signed-off-by: Dirk Brenken <dev@brenken.org>
* fix a race condition in the process scheduler
* sync the banIP country file with ipdeny feed
* refine etag handling with country/asn feeds
* refine logging with country/asn feeds
* refine the banIP status output (incl. LuCI changes)
Signed-off-by: Dirk Brenken <dev@brenken.org>
* optimized uci config processing (list options)
* optimized icmp rules in pre-routing (thanks @brada)
* set inbound marker in pre-routing only if inbound logging is enabled (fixes#26044)
* fix cornercase in Set removal function
* print chain-, set- and rules-counter in the banIP status
* clean up logging und download queue handling
* update the readme
Signed-off-by: Dirk Brenken <dev@brenken.org>