|
0
|
1 .\" SPDX-License-Identifier: BSD-2-Clause
|
|
|
2 .\" Copyright (c) 2026 Arkadiusz Juszczyk <ark@wobblyhead.net>
|
|
|
3 .\"
|
|
|
4 .Dd October 25, 2026
|
|
|
5 .Dt BOTBLOCKD 8
|
|
|
6 .Os
|
|
|
7 .Sh NAME
|
|
|
8 .Nm botblockd
|
|
|
9 .Nd nginx-to-pf bot blocker
|
|
|
10 .Sh SYNOPSIS
|
|
|
11 .Nm
|
|
|
12 .Cm run
|
|
|
13 .Op Fl f
|
|
|
14 .Op Fl c Ar config
|
|
|
15 .Op Fl p Ar pidfile
|
|
|
16 .Nm
|
|
|
17 .Cm check
|
|
|
18 .Op Fl c Ar config
|
|
|
19 .Nm
|
|
|
20 .Cm list
|
|
|
21 .Nm
|
|
|
22 .Cm unblock
|
|
|
23 .Ar address ...
|
|
|
24 .Nm
|
|
|
25 .Cm unblock Fl a
|
|
|
26 .Nm
|
|
|
27 .Cm help
|
|
|
28 .Sh DESCRIPTION
|
|
|
29 .Nm
|
|
|
30 tails an nginx access log via
|
|
|
31 .Xr kqueue 2 ,
|
|
|
32 counts HTTP error responses per source IP, and blocks persistently
|
|
|
33 abusive clients at the host
|
|
|
34 .Xr pf 4
|
|
|
35 firewall by adding them to the
|
|
|
36 .Sy botblock
|
|
|
37 table.
|
|
|
38 It reads the standard combined log format, accepting both the raw form
|
|
|
39 and the form produced when
|
|
|
40 .Xr syslogd 8
|
|
|
41 aggregates the log with a prepended syslog header.
|
|
|
42 The log is followed across rotation and truncation.
|
|
|
43 Only IPv4 is handled.
|
|
|
44 .Pp
|
|
|
45 Each source that produces an error response becomes a suspect.
|
|
|
46 A periodic sweep evaluates suspects and moves them through a small state
|
|
|
47 machine.
|
|
|
48 An inspection window of
|
|
|
49 .Va INSPECT_SECONDS
|
|
|
50 seconds or
|
|
|
51 .Va INSPECT_REQUEST_COUNT
|
|
|
52 requests, whichever comes first, decides whether the error balance
|
|
|
53 warrants a block.
|
|
|
54 A blocked IP is released after
|
|
|
55 .Va BLOCK_SECONDS
|
|
|
56 seconds into a probation period, during which renewed bad behaviour
|
|
|
57 re-blocks it.
|
|
|
58 Suspects that cause no further errors are dropped after
|
|
|
59 .Va COOLDOWN_SECONDS
|
|
|
60 seconds.
|
|
|
61 Successful requests count against errors.
|
|
|
62 A client is blocked only when its errors reach
|
|
|
63 .Va MIN_ERROR_COUNT
|
|
|
64 and outnumber its successful requests.
|
|
|
65 An occasional error among normal requests does not block a client, and a
|
|
|
66 client can clear itself by behaving.
|
|
|
67 .Pp
|
|
|
68 A whitelist file protects operators.
|
|
|
69 It lists addresses that are never blocked.
|
|
|
70 .Pp
|
|
|
71 .Nm
|
|
|
72 logs to
|
|
|
73 .Xr syslog 3
|
|
|
74 under the
|
|
|
75 .Dv LOG_DAEMON
|
|
|
76 facility.
|
|
|
77 The
|
|
|
78 .Xr pf 4
|
|
|
79 .Sy botblock
|
|
|
80 table must exist and be referenced by a block rule in the host ruleset;
|
|
|
81 a sample is installed under
|
|
|
82 .Pa share/examples/botblockd .
|
|
|
83 .Nm
|
|
|
84 treats the table as its own and flushes it at startup and on exit.
|
|
|
85 When an address is blocked, its existing
|
|
|
86 .Xr pf 4
|
|
|
87 states are killed as well, so connections it has already established
|
|
|
88 are cut off.
|
|
|
89 .Sh COMMANDS
|
|
|
90 .Bl -tag -width "unblock"
|
|
|
91 .It Cm run
|
|
|
92 Run the daemon.
|
|
|
93 It detaches into the background unless
|
|
|
94 .Fl f
|
|
|
95 is given, and writes a pidfile.
|
|
|
96 The configuration, the whitelist, the input log and the
|
|
|
97 .Sy botblock
|
|
|
98 table are checked before detaching, so a problem with any of them is
|
|
|
99 reported in the exit status.
|
|
|
100 .It Cm check
|
|
|
101 Parse the configuration and whitelist, open the input log, verify that
|
|
|
102 the
|
|
|
103 .Sy botblock
|
|
|
104 table is loaded in
|
|
|
105 .Xr pf 4 ,
|
|
|
106 report the result, and exit.
|
|
|
107 The table is only read, never modified.
|
|
|
108 Run this as root before sending
|
|
|
109 .Dv SIGHUP :
|
|
|
110 a failed reload is reported only in the system log.
|
|
|
111 .It Cm list
|
|
|
112 Print the addresses currently in the
|
|
|
113 .Sy botblock
|
|
|
114 table.
|
|
|
115 .It Cm unblock Ar address ...
|
|
|
116 Remove one or more addresses from the
|
|
|
117 .Sy botblock
|
|
|
118 table.
|
|
|
119 .It Cm unblock Fl a
|
|
|
120 Remove all addresses from the table.
|
|
|
121 .It Cm help
|
|
|
122 Print the version and a usage summary.
|
|
|
123 .El
|
|
|
124 .Sh OPTIONS
|
|
|
125 .Bl -tag -width Fl
|
|
|
126 .It Fl c Ar config
|
|
|
127 Read configuration from
|
|
|
128 .Ar config
|
|
|
129 instead of the default.
|
|
|
130 With
|
|
|
131 .Cm run ,
|
|
|
132 the path must be absolute, so that a reload finds the file after the
|
|
|
133 daemon has changed to the root directory.
|
|
|
134 .It Fl f
|
|
|
135 Run in the foreground without detaching, mirroring log output to
|
|
|
136 standard error.
|
|
|
137 .It Fl p Ar pidfile
|
|
|
138 Write the pidfile to
|
|
|
139 .Ar pidfile
|
|
|
140 instead of the default.
|
|
|
141 .El
|
|
|
142 .Sh CONFIGURATION
|
|
|
143 The configuration file holds
|
|
|
144 .Sy KEY=VALUE
|
|
|
145 lines.
|
|
|
146 Blank lines and lines whose first non-blank character is
|
|
|
147 .Ql #
|
|
|
148 are ignored.
|
|
|
149 Unset keys keep their compiled-in defaults, and if the file does not
|
|
|
150 exist, all defaults apply.
|
|
|
151 A key that is present must have a valid value.
|
|
|
152 Numbers must be positive integers, and paths must be absolute.
|
|
|
153 A malformed value, an unknown key or a line that is not
|
|
|
154 .Sy KEY=VALUE
|
|
|
155 is an error rather than ignored: at startup
|
|
|
156 .Nm
|
|
|
157 exits, and a reload is rejected.
|
|
|
158 .Bl -tag -width "INSPECT_REQUEST_COUNT"
|
|
|
159 .It Va INSPECT_SECONDS
|
|
|
160 Length of the inspection window in seconds.
|
|
|
161 The default is 30.
|
|
|
162 .It Va INSPECT_REQUEST_COUNT
|
|
|
163 Request count that also closes the inspection window.
|
|
|
164 The default is 20.
|
|
|
165 .It Va MIN_ERROR_COUNT
|
|
|
166 Minimum number of errors a suspect must have caused before it is
|
|
|
167 first blocked.
|
|
|
168 Errors are counted from the first one and are not reset when the
|
|
|
169 inspection window closes.
|
|
|
170 The default is 2.
|
|
|
171 .It Va ERROR_STATUSES
|
|
|
172 Which HTTP status codes count as errors, as a comma-separated list of
|
|
|
173 single codes and
|
|
|
174 .Ar lo Ns - Ns Ar hi
|
|
|
175 ranges, for example
|
|
|
176 .Ql 401,403,404,444
|
|
|
177 or
|
|
|
178 .Ql 400-599 .
|
|
|
179 Any status not listed counts as a successful request.
|
|
|
180 The default is
|
|
|
181 .Ql 400-599 .
|
|
|
182 .It Va COOLDOWN_SECONDS
|
|
|
183 A suspect that has caused no error for this many seconds is
|
|
|
184 forgotten; successful requests do not keep it.
|
|
|
185 An address on probation is forgotten this many seconds after its
|
|
|
186 block was lifted.
|
|
|
187 The default is 600.
|
|
|
188 .It Va BLOCK_SECONDS
|
|
|
189 How long, in seconds, an address stays blocked before entering probation.
|
|
|
190 The default is 600.
|
|
|
191 .It Va INPUT_LOG
|
|
|
192 Path of the nginx access log to tail.
|
|
|
193 A reload that changes it is rejected; the change takes effect when
|
|
|
194 the daemon is restarted.
|
|
|
195 The default is
|
|
|
196 .Pa /var/log/nginx/access.log .
|
|
|
197 .It Va WHITELIST_FILE
|
|
|
198 Path of the whitelist, one IPv4 address or CIDR subnet per line.
|
|
|
199 A bare address is treated as a single host
|
|
|
200 .Pq Li /32 ;
|
|
|
201 a prefix length must be between 1 and 32, as
|
|
|
202 .Li /0
|
|
|
203 would whitelist every address.
|
|
|
204 Host bits below the prefix are accepted and masked off, so
|
|
|
205 .Li 10.0.0.5/24
|
|
|
206 is the same as
|
|
|
207 .Li 10.0.0.0/24 .
|
|
|
208 Blanks around an entry, blank lines and lines whose first non-blank
|
|
|
209 character is
|
|
|
210 .Ql #
|
|
|
211 are ignored; any other line that does not parse fails startup or
|
|
|
212 reload, just like a malformed configuration value.
|
|
|
213 A missing file leaves the whitelist empty; a file that exists but
|
|
|
214 cannot be read is an error.
|
|
|
215 The default is
|
|
|
216 .Pa /usr/local/etc/botblockd/whitelist .
|
|
|
217 .El
|
|
|
218 .Sh FILES
|
|
|
219 .Bl -tag -width "/usr/local/etc/botblockd/whitelist"
|
|
|
220 .It Pa /usr/local/etc/botblockd/conf
|
|
|
221 Configuration file
|
|
|
222 .It Pa /usr/local/etc/botblockd/whitelist
|
|
|
223 IP whitelist
|
|
|
224 .It Pa /usr/local/etc/rc.d/botblockd
|
|
|
225 .Xr rc 8
|
|
|
226 Startup script
|
|
|
227 .It Pa /var/run/botblockd.pid
|
|
|
228 Default pidfile
|
|
|
229 .El
|
|
|
230 .Sh SIGNALS
|
|
|
231 .Bl -tag -width SIGTERM
|
|
|
232 .It Dv SIGTERM , SIGINT
|
|
|
233 Graceful shutdown; flush the
|
|
|
234 .Xr pf 4
|
|
|
235 table before exiting.
|
|
|
236 .It Dv SIGHUP
|
|
|
237 Reload the configuration file and whitelist.
|
|
|
238 If either has an error, or
|
|
|
239 .Va INPUT_LOG
|
|
|
240 has changed, the reload is rejected: the error is logged and the
|
|
|
241 previous configuration and whitelist stay in effect.
|
|
|
242 .El
|
|
|
243 .Sh EXIT STATUS
|
|
|
244 .Cm run
|
|
|
245 exits 0 when stopped by a signal and 1 on any error, at startup or
|
|
|
246 while running.
|
|
|
247 The other commands exit 0 on success and 1 on failure.
|
|
|
248 .Sh SEE ALSO
|
|
|
249 .Xr kqueue 2 ,
|
|
|
250 .Xr syslog 3 ,
|
|
|
251 .Xr pf 4 ,
|
|
|
252 .Xr pfctl 8 ,
|
|
|
253 .Xr rc 8 ,
|
|
|
254 .Xr syslogd 8
|
|
|
255 .Sh AUTHORS
|
|
|
256 .An Arkadiusz Juszczyk Aq Mt ark@wobblyhead.net
|
|
|
257 .Sh CAVEATS
|
|
|
258 Only IPv4 is handled.
|
|
|
259 Log lines from IPv6 clients are skipped, so these clients are never
|
|
|
260 blocked.
|
|
|
261 .Pp
|
|
|
262 .Cm unblock
|
|
|
263 works on the
|
|
|
264 .Xr pf 4
|
|
|
265 table only and does not inform a running daemon.
|
|
|
266 The daemon still counts a manually unblocked address as blocked until
|
|
|
267 its block interval ends, so the address is not blocked again before
|
|
|
268 then, whatever errors it causes.
|