wobblyhead hg > freebsd > botblockd
comparison README.md @ 0:9f8d79c98fd2 0.4.0
initial public release
| author | Arkadiusz Juszczyk <ark@wobblyhead.net> |
|---|---|
| date | 2026-10-26 11:29 +0100 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:9f8d79c98fd2 |
|---|---|
| 1 # botblockd | |
| 2 | |
| 3 A small FreeBSD daemon that blocks abusive web clients at the firewall. | |
| 4 | |
| 5 botblockd tails an nginx access log, counts HTTP error responses per | |
| 6 source IP, and adds persistent offenders to a `pf` table so they are | |
| 7 dropped at the host edge. It reinforces application-level decisions | |
| 8 (rate limits, web application firewall rules) at the network layer, | |
| 9 where they are cheap to enforce. | |
| 10 | |
| 11 IPv4 only. No external dependencies: it uses the FreeBSD base system | |
| 12 toolchain, headers and `pfctl`. | |
| 13 | |
| 14 ## How it works | |
| 15 | |
| 16 Every source address that receives an error response becomes a suspect. A | |
| 17 periodic sweep evaluates suspects through a small state machine: | |
| 18 | |
| 19 - An inspection window (a number of seconds or requests, whichever comes | |
| 20 first) decides whether a suspect's error balance warrants a block. | |
| 21 - A blocked address is released after a configurable interval into a | |
| 22 probation period, during which renewed bad behaviour re-blocks it. | |
| 23 - Suspects that stop causing errors are forgotten after a cooldown. | |
| 24 | |
| 25 Successful requests count against errors. A client is blocked only when | |
| 26 its errors reach a minimum count and outnumber its successful requests. | |
| 27 An occasional error among normal requests does not block a client, and a | |
| 28 client can clear itself by behaving. | |
| 29 | |
| 30 Which status codes count as errors is configurable; anything else counts | |
| 31 as success. | |
| 32 | |
| 33 ## Safety | |
| 34 | |
| 35 A whitelist file of addresses that are never blocked keeps operators | |
| 36 from being locked out. | |
| 37 | |
| 38 The daemon treats the `pf` table as its own and flushes it at startup | |
| 39 and on shutdown. When it blocks an address, it also kills that | |
| 40 address's existing `pf` states, so open connections are cut off. | |
| 41 | |
| 42 ## Requirements | |
| 43 | |
| 44 - FreeBSD. Tested on FreeBSD 15. | |
| 45 - `pf` enabled, with a `botblock` table and a matching block rule. | |
| 46 | |
| 47 ## Install | |
| 48 | |
| 49 Source releases and install notes are on the project page, | |
| 50 <https://www.wobblyhead.net/projects/botblockd.html>. | |
| 51 | |
| 52 To build and install from an unpacked source release: | |
| 53 | |
| 54 make -C src | |
| 55 make -C src install | |
| 56 | |
| 57 ## pf setup | |
| 58 | |
| 59 botblockd manages a `pf` table named `botblock`; you provide the table | |
| 60 and the rule. A sample is installed at | |
| 61 `share/examples/botblockd/pf.conf.sample`: | |
| 62 | |
| 63 table <botblock> persist | |
| 64 block in quick from <botblock> | |
| 65 | |
| 66 Splice it into your ruleset and reload with `pfctl -f /etc/pf.conf`. | |
| 67 | |
| 68 ## Run | |
| 69 | |
| 70 sysrc botblockd_enable=YES | |
| 71 service botblockd start | |
| 72 | |
| 73 The configuration is read from `/usr/local/etc/botblockd/conf`; copy | |
| 74 `conf.sample` from the same directory and edit it. Send `SIGHUP` (or | |
| 75 `service botblockd reload`) to re-read it. If the new configuration or | |
| 76 whitelist has an error, the reload is rejected and the daemon keeps | |
| 77 running with the previous one; the error goes to the system log. Run | |
| 78 `botblockd check` as root to see errors before reloading. | |
| 79 | |
| 80 ## Commands | |
| 81 | |
| 82 botblockd run [-f] run the daemon (-f: foreground) | |
| 83 botblockd check validate configuration and exit | |
| 84 botblockd list list currently blocked addresses | |
| 85 botblockd unblock <addr> remove an address from the block table | |
| 86 botblockd unblock -a clear the whole table | |
| 87 | |
| 88 The daemon logs to syslog under the `daemon` facility. | |
| 89 | |
| 90 See `botblockd(8)` for the full configuration reference. | |
| 91 | |
| 92 ## Bugs | |
| 93 | |
| 94 Report bugs by email to ark@wobblyhead.net. Include the version, which | |
| 95 `botblockd help` prints on its first line, and the relevant lines from | |
| 96 the system log. | |
| 97 | |
| 98 ## Licence | |
| 99 | |
| 100 BSD 2-Clause. See [LICENSE](LICENSE). |
