wobblyhead hg > freebsd > botblockd
view README.md @ 1:30f396bc751c default tip
Added tag 0.4.0 for changeset 9f8d79c98fd2
| author | Arkadiusz Juszczyk <ark@wobblyhead.net> |
|---|---|
| date | 2026-10-26 11:29 +0100 |
| parents | 9f8d79c98fd2 |
| children |
line wrap: on
line source
# botblockd A small FreeBSD daemon that blocks abusive web clients at the firewall. botblockd tails an nginx access log, counts HTTP error responses per source IP, and adds persistent offenders to a `pf` table so they are dropped at the host edge. It reinforces application-level decisions (rate limits, web application firewall rules) at the network layer, where they are cheap to enforce. IPv4 only. No external dependencies: it uses the FreeBSD base system toolchain, headers and `pfctl`. ## How it works Every source address that receives an error response becomes a suspect. A periodic sweep evaluates suspects through a small state machine: - An inspection window (a number of seconds or requests, whichever comes first) decides whether a suspect's error balance warrants a block. - A blocked address is released after a configurable interval into a probation period, during which renewed bad behaviour re-blocks it. - Suspects that stop causing errors are forgotten after a cooldown. Successful requests count against errors. A client is blocked only when its errors reach a minimum count and outnumber its successful requests. An occasional error among normal requests does not block a client, and a client can clear itself by behaving. Which status codes count as errors is configurable; anything else counts as success. ## Safety A whitelist file of addresses that are never blocked keeps operators from being locked out. The daemon treats the `pf` table as its own and flushes it at startup and on shutdown. When it blocks an address, it also kills that address's existing `pf` states, so open connections are cut off. ## Requirements - FreeBSD. Tested on FreeBSD 15. - `pf` enabled, with a `botblock` table and a matching block rule. ## Install Source releases and install notes are on the project page, <https://www.wobblyhead.net/projects/botblockd.html>. To build and install from an unpacked source release: make -C src make -C src install ## pf setup botblockd manages a `pf` table named `botblock`; you provide the table and the rule. A sample is installed at `share/examples/botblockd/pf.conf.sample`: table <botblock> persist block in quick from <botblock> Splice it into your ruleset and reload with `pfctl -f /etc/pf.conf`. ## Run sysrc botblockd_enable=YES service botblockd start The configuration is read from `/usr/local/etc/botblockd/conf`; copy `conf.sample` from the same directory and edit it. Send `SIGHUP` (or `service botblockd reload`) to re-read it. If the new configuration or whitelist has an error, the reload is rejected and the daemon keeps running with the previous one; the error goes to the system log. Run `botblockd check` as root to see errors before reloading. ## Commands botblockd run [-f] run the daemon (-f: foreground) botblockd check validate configuration and exit botblockd list list currently blocked addresses botblockd unblock <addr> remove an address from the block table botblockd unblock -a clear the whole table The daemon logs to syslog under the `daemon` facility. See `botblockd(8)` for the full configuration reference. ## Bugs Report bugs by email to ark@wobblyhead.net. Include the version, which `botblockd help` prints on its first line, and the relevant lines from the system log. ## Licence BSD 2-Clause. See [LICENSE](LICENSE).
