xref: /freebsd/contrib/blocklist/bin/blacklistd.8 (revision 5f4c09dd85bff675e0ca63c55ea3c517e0fddfcc)
1*5f4c09ddSEd Maste.\" $NetBSD: blacklistd.8,v 1.23 2020/04/21 13:57:12 christos Exp $
2*5f4c09ddSEd Maste.\"
3*5f4c09ddSEd Maste.\" Copyright (c) 2015 The NetBSD Foundation, Inc.
4*5f4c09ddSEd Maste.\" All rights reserved.
5*5f4c09ddSEd Maste.\"
6*5f4c09ddSEd Maste.\" This code is derived from software contributed to The NetBSD Foundation
7*5f4c09ddSEd Maste.\" by Christos Zoulas.
8*5f4c09ddSEd Maste.\"
9*5f4c09ddSEd Maste.\" Redistribution and use in source and binary forms, with or without
10*5f4c09ddSEd Maste.\" modification, are permitted provided that the following conditions
11*5f4c09ddSEd Maste.\" are met:
12*5f4c09ddSEd Maste.\" 1. Redistributions of source code must retain the above copyright
13*5f4c09ddSEd Maste.\"    notice, this list of conditions and the following disclaimer.
14*5f4c09ddSEd Maste.\" 2. Redistributions in binary form must reproduce the above copyright
15*5f4c09ddSEd Maste.\"    notice, this list of conditions and the following disclaimer in the
16*5f4c09ddSEd Maste.\"    documentation and/or other materials provided with the distribution.
17*5f4c09ddSEd Maste.\"
18*5f4c09ddSEd Maste.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19*5f4c09ddSEd Maste.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20*5f4c09ddSEd Maste.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21*5f4c09ddSEd Maste.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22*5f4c09ddSEd Maste.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23*5f4c09ddSEd Maste.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24*5f4c09ddSEd Maste.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25*5f4c09ddSEd Maste.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26*5f4c09ddSEd Maste.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27*5f4c09ddSEd Maste.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28*5f4c09ddSEd Maste.\" POSSIBILITY OF SUCH DAMAGE.
29*5f4c09ddSEd Maste.\"
30*5f4c09ddSEd Maste.Dd April 21, 2020
31*5f4c09ddSEd Maste.Dt BLACKLISTD 8
32*5f4c09ddSEd Maste.Os
33*5f4c09ddSEd Maste.Sh NAME
34*5f4c09ddSEd Maste.Nm blacklistd
35*5f4c09ddSEd Maste.Nd block and release ports on demand to avoid DoS abuse
36*5f4c09ddSEd Maste.Sh SYNOPSIS
37*5f4c09ddSEd Maste.Nm
38*5f4c09ddSEd Maste.Op Fl dfrv
39*5f4c09ddSEd Maste.Op Fl C Ar controlprog
40*5f4c09ddSEd Maste.Op Fl c Ar configfile
41*5f4c09ddSEd Maste.Op Fl D Ar dbfile
42*5f4c09ddSEd Maste.Op Fl P Ar sockpathsfile
43*5f4c09ddSEd Maste.Op Fl R Ar rulename
44*5f4c09ddSEd Maste.Op Fl s Ar sockpath
45*5f4c09ddSEd Maste.Op Fl t Ar timeout
46*5f4c09ddSEd Maste.Sh DESCRIPTION
47*5f4c09ddSEd Maste.Nm
48*5f4c09ddSEd Masteis a daemon similar to
49*5f4c09ddSEd Maste.Xr syslogd 8
50*5f4c09ddSEd Mastethat listens to sockets at paths specified in the
51*5f4c09ddSEd Maste.Ar sockpathsfile
52*5f4c09ddSEd Mastefor notifications from other daemons about successful or failed connection
53*5f4c09ddSEd Masteattempts.
54*5f4c09ddSEd MasteIf no such file is specified, then it only listens to the socket path
55*5f4c09ddSEd Mastespecified by
56*5f4c09ddSEd Maste.Ar sockspath
57*5f4c09ddSEd Masteor if that is not specified to
58*5f4c09ddSEd Maste.Pa /var/run/blacklistd.sock .
59*5f4c09ddSEd MasteEach notification contains an (action, port, protocol, address, owner) tuple
60*5f4c09ddSEd Mastethat identifies the remote connection and the action.
61*5f4c09ddSEd MasteThis tuple is consulted against entries in
62*5f4c09ddSEd Maste.Ar configfile
63*5f4c09ddSEd Mastewith syntax specified in
64*5f4c09ddSEd Maste.Xr blacklistd.conf 5 .
65*5f4c09ddSEd MasteIf an entry is matched, a state entry is created for that tuple.
66*5f4c09ddSEd MasteEach entry contains a number of tries limit and a duration.
67*5f4c09ddSEd Maste.Pp
68*5f4c09ddSEd MasteThe way
69*5f4c09ddSEd Maste.Nm
70*5f4c09ddSEd Mastedoes configuration entry matching is by having the client side pass the
71*5f4c09ddSEd Mastefile descriptor associated with the connection the client wants to blacklist
72*5f4c09ddSEd Masteas well as passing socket credentials.
73*5f4c09ddSEd Maste.Pp
74*5f4c09ddSEd MasteThe file descriptor is used to retrieve information (address and port)
75*5f4c09ddSEd Masteabout the remote side with
76*5f4c09ddSEd Maste.Xr getpeername 2
77*5f4c09ddSEd Masteand the local side with
78*5f4c09ddSEd Maste.Xr getsockname 2 .
79*5f4c09ddSEd Maste.Pp
80*5f4c09ddSEd MasteBy examining the port of the local side,
81*5f4c09ddSEd Maste.Nm
82*5f4c09ddSEd Mastecan determine if the client program
83*5f4c09ddSEd Maste.Dq owns
84*5f4c09ddSEd Mastethe port.
85*5f4c09ddSEd MasteBy examining the optional address portion on the local side, it can match
86*5f4c09ddSEd Masteinterfaces.
87*5f4c09ddSEd MasteBy examining the remote address, it can match specific allow or deny rules.
88*5f4c09ddSEd Maste.Pp
89*5f4c09ddSEd MasteFinally
90*5f4c09ddSEd Maste.Nm
91*5f4c09ddSEd Mastecan examine the socket credentials to match the user in the configuration file.
92*5f4c09ddSEd Maste.Pp
93*5f4c09ddSEd MasteWhile this works well for TCP sockets, it cannot be relied on for unbound
94*5f4c09ddSEd MasteUDP sockets.
95*5f4c09ddSEd MasteIt is also less meaningful when it comes to connections using non-privileged
96*5f4c09ddSEd Masteports.
97*5f4c09ddSEd MasteOn the other hand, if we receive a request that has a local endpoint indicating
98*5f4c09ddSEd Mastea UDP privileged port, we can presume that the client was privileged to be
99*5f4c09ddSEd Masteable to acquire that port.
100*5f4c09ddSEd Maste.Pp
101*5f4c09ddSEd MasteOnce an entry is matched
102*5f4c09ddSEd Maste.Nm
103*5f4c09ddSEd Mastecan perform various actions.
104*5f4c09ddSEd MasteIf the action is
105*5f4c09ddSEd Maste.Dq add
106*5f4c09ddSEd Masteand the number of tries limit is reached, then a
107*5f4c09ddSEd Mastecontrol script
108*5f4c09ddSEd Maste.Ar controlprog
109*5f4c09ddSEd Masteis invoked with arguments:
110*5f4c09ddSEd Maste.Bd -literal -offset indent
111*5f4c09ddSEd Mastecontrol add <rulename> <proto> <address> <mask> <port>
112*5f4c09ddSEd Maste.Ed
113*5f4c09ddSEd Maste.Pp
114*5f4c09ddSEd Masteand should invoke a packet filter command to block the connection
115*5f4c09ddSEd Mastespecified by the arguments.
116*5f4c09ddSEd MasteThe
117*5f4c09ddSEd Maste.Ar rulename
118*5f4c09ddSEd Masteargument can be set from the command line (default
119*5f4c09ddSEd Maste.Dv blacklistd ) .
120*5f4c09ddSEd MasteThe script could print a numerical id to stdout as a handle for
121*5f4c09ddSEd Mastethe rule that can be used later to remove that connection, but
122*5f4c09ddSEd Mastethat is not required as all information to remove the rule is
123*5f4c09ddSEd Mastekept.
124*5f4c09ddSEd Maste.Pp
125*5f4c09ddSEd MasteIf the action is
126*5f4c09ddSEd Maste.Dq rem
127*5f4c09ddSEd MasteThen the same control script is invoked as:
128*5f4c09ddSEd Maste.Bd -literal -offset indent
129*5f4c09ddSEd Mastecontrol rem <rulename> <proto> <address> <mask> <port> <id>
130*5f4c09ddSEd Maste.Ed
131*5f4c09ddSEd Maste.Pp
132*5f4c09ddSEd Mastewhere
133*5f4c09ddSEd Maste.Ar id
134*5f4c09ddSEd Masteis the number returned from the
135*5f4c09ddSEd Maste.Dq add
136*5f4c09ddSEd Masteaction.
137*5f4c09ddSEd Maste.Pp
138*5f4c09ddSEd Maste.Nm
139*5f4c09ddSEd Mastemaintains a database of known connections in
140*5f4c09ddSEd Maste.Ar dbfile .
141*5f4c09ddSEd MasteOn startup it reads entries from that file, and updates its internal state.
142*5f4c09ddSEd Maste.Pp
143*5f4c09ddSEd Maste.Nm
144*5f4c09ddSEd Mastechecks the list of active entries every
145*5f4c09ddSEd Maste.Ar timeout
146*5f4c09ddSEd Masteseconds (default
147*5f4c09ddSEd Maste.Dv 15 )
148*5f4c09ddSEd Masteand removes entries and block rules using the control program as necessary.
149*5f4c09ddSEd Maste.Pp
150*5f4c09ddSEd MasteThe following options are available:
151*5f4c09ddSEd Maste.Bl -tag -width indent
152*5f4c09ddSEd Maste.It Fl C Ar controlprog
153*5f4c09ddSEd MasteUse
154*5f4c09ddSEd Maste.Ar controlprog
155*5f4c09ddSEd Masteto communicate with the packet filter, usually
156*5f4c09ddSEd Maste.Pa /usr/libexec/blacklistd-helper .
157*5f4c09ddSEd MasteThe following arguments are passed to the control program:
158*5f4c09ddSEd Maste.Bl -tag -width protocol
159*5f4c09ddSEd Maste.It action
160*5f4c09ddSEd MasteThe action to perform:
161*5f4c09ddSEd Maste.Dv add ,
162*5f4c09ddSEd Maste.Dv rem ,
163*5f4c09ddSEd Masteor
164*5f4c09ddSEd Maste.Dv flush
165*5f4c09ddSEd Masteto add, remove or flush a firewall rule.
166*5f4c09ddSEd Maste.It name
167*5f4c09ddSEd MasteThe rule name.
168*5f4c09ddSEd Maste.It protocol
169*5f4c09ddSEd MasteThe optional protocol name (can be empty):
170*5f4c09ddSEd Maste.Dv tcp ,
171*5f4c09ddSEd Maste.Dv tcp6 ,
172*5f4c09ddSEd Maste.Dv udp ,
173*5f4c09ddSEd Maste.Dv udp6 .
174*5f4c09ddSEd Maste.It address
175*5f4c09ddSEd MasteThe IPv4 or IPv6 numeric address to be blocked or released.
176*5f4c09ddSEd Maste.It mask
177*5f4c09ddSEd MasteThe numeric mask to be applied to the blocked or released address
178*5f4c09ddSEd Maste.It port
179*5f4c09ddSEd MasteThe optional numeric port to be blocked (can be empty).
180*5f4c09ddSEd Maste.It id
181*5f4c09ddSEd MasteFor packet filters that support removal of rules by rule identifier, the
182*5f4c09ddSEd Masteidentifier of the rule to be removed.
183*5f4c09ddSEd MasteThe add command is expected to return the rule identifier string to stdout.
184*5f4c09ddSEd Maste.El
185*5f4c09ddSEd Maste.It Fl c Ar configuration
186*5f4c09ddSEd MasteThe name of the configuration file to read, usually
187*5f4c09ddSEd Maste.Pa /etc/blacklistd.conf .
188*5f4c09ddSEd Maste.It Fl D Ar dbfile
189*5f4c09ddSEd MasteThe Berkeley DB file where
190*5f4c09ddSEd Maste.Nm
191*5f4c09ddSEd Mastestores its state, usually
192*5f4c09ddSEd Maste.Pa /var/db/blacklistd.db .
193*5f4c09ddSEd Maste.It Fl d
194*5f4c09ddSEd MasteNormally,
195*5f4c09ddSEd Maste.Nm
196*5f4c09ddSEd Mastedisassociates itself from the terminal unless the
197*5f4c09ddSEd Maste.Fl d
198*5f4c09ddSEd Masteflag is specified, in which case it stays in the foreground.
199*5f4c09ddSEd Maste.It Fl f
200*5f4c09ddSEd MasteTruncate the state database and flush all the rules named
201*5f4c09ddSEd Maste.Ar rulename
202*5f4c09ddSEd Masteare deleted by invoking the control script as:
203*5f4c09ddSEd Maste.Bd -literal -offset indent
204*5f4c09ddSEd Mastecontrol flush <rulename>
205*5f4c09ddSEd Maste.Ed
206*5f4c09ddSEd Maste.It Fl P Ar sockspathsfile
207*5f4c09ddSEd MasteA file containing a list of pathnames, one per line that
208*5f4c09ddSEd Maste.Nm
209*5f4c09ddSEd Mastewill create sockets to listen to.
210*5f4c09ddSEd MasteThis is useful for chrooted environments.
211*5f4c09ddSEd Maste.It Fl R Ar rulename
212*5f4c09ddSEd MasteSpecify the default rule name for the packet filter rules, usually
213*5f4c09ddSEd Maste.Dv blacklistd .
214*5f4c09ddSEd Maste.It Fl r
215*5f4c09ddSEd MasteRe-read the firewall rules from the internal database, then
216*5f4c09ddSEd Masteremove and re-add them.
217*5f4c09ddSEd MasteThis helps for packet filters that do not retain state across reboots.
218*5f4c09ddSEd Maste.It Fl s Ar sockpath
219*5f4c09ddSEd MasteAdd
220*5f4c09ddSEd Maste.Ar sockpath
221*5f4c09ddSEd Masteto the list of Unix sockets
222*5f4c09ddSEd Maste.Nm
223*5f4c09ddSEd Mastelistens to.
224*5f4c09ddSEd Maste.It Fl t Ar timeout
225*5f4c09ddSEd MasteThe interval in seconds
226*5f4c09ddSEd Maste.Nm
227*5f4c09ddSEd Mastepolls the state file to update the rules.
228*5f4c09ddSEd Maste.It Fl v
229*5f4c09ddSEd MasteCause
230*5f4c09ddSEd Maste.Nm
231*5f4c09ddSEd Masteto print
232*5f4c09ddSEd Mastediagnostic messages to
233*5f4c09ddSEd Maste.Dv stdout
234*5f4c09ddSEd Masteinstead of
235*5f4c09ddSEd Maste.Xr syslogd 8 .
236*5f4c09ddSEd Maste.El
237*5f4c09ddSEd Maste.Sh SIGNAL HANDLING
238*5f4c09ddSEd Maste.Nm
239*5f4c09ddSEd Mastedeals with the following signals:
240*5f4c09ddSEd Maste.Bl -tag -width "USR2"
241*5f4c09ddSEd Maste.It Dv HUP
242*5f4c09ddSEd MasteReceipt of this signal causes
243*5f4c09ddSEd Maste.Nm
244*5f4c09ddSEd Masteto re-read the configuration file.
245*5f4c09ddSEd Maste.It Dv INT , Dv TERM & Dv QUIT
246*5f4c09ddSEd MasteThese signals tell
247*5f4c09ddSEd Maste.Nm
248*5f4c09ddSEd Masteto exit in an orderly fashion.
249*5f4c09ddSEd Maste.It Dv USR1
250*5f4c09ddSEd MasteThis signal tells
251*5f4c09ddSEd Maste.Nm
252*5f4c09ddSEd Masteto increase the internal debugging level by 1.
253*5f4c09ddSEd Maste.It Dv USR2
254*5f4c09ddSEd MasteThis signal tells
255*5f4c09ddSEd Maste.Nm
256*5f4c09ddSEd Masteto decrease the internal debugging level by 1.
257*5f4c09ddSEd Maste.El
258*5f4c09ddSEd Maste.Sh FILES
259*5f4c09ddSEd Maste.Bl -tag -width /usr/libexec/blacklistd-helper -compact
260*5f4c09ddSEd Maste.It Pa /usr/libexec/blacklistd-helper
261*5f4c09ddSEd MasteShell script invoked to interface with the packet filter.
262*5f4c09ddSEd Maste.It Pa /etc/blacklistd.conf
263*5f4c09ddSEd MasteConfiguration file.
264*5f4c09ddSEd Maste.It Pa /var/db/blacklistd.db
265*5f4c09ddSEd MasteDatabase of current connection entries.
266*5f4c09ddSEd Maste.It Pa /var/run/blacklistd.sock
267*5f4c09ddSEd MasteSocket to receive connection notifications.
268*5f4c09ddSEd Maste.El
269*5f4c09ddSEd Maste.Sh SEE ALSO
270*5f4c09ddSEd Maste.Xr blacklistd.conf 5 ,
271*5f4c09ddSEd Maste.Xr blacklistctl 8 ,
272*5f4c09ddSEd Maste.Xr pfctl 8 ,
273*5f4c09ddSEd Maste.Xr syslogd 8
274*5f4c09ddSEd Maste.Sh HISTORY
275*5f4c09ddSEd Maste.Nm
276*5f4c09ddSEd Mastefirst appeared in
277*5f4c09ddSEd Maste.Nx 7 .
278*5f4c09ddSEd Maste.Fx
279*5f4c09ddSEd Mastesupport for
280*5f4c09ddSEd Maste.Nm
281*5f4c09ddSEd Mastewas implemented in
282*5f4c09ddSEd Maste.Fx 11 .
283*5f4c09ddSEd Maste.Sh AUTHORS
284*5f4c09ddSEd Maste.An Christos Zoulas
285