1*0a6a1f1dSLionel Sambuc.\" $NetBSD: blacklistd.8,v 1.14 2015/06/04 16:11:48 wiz Exp $ 2*0a6a1f1dSLionel Sambuc.\" 3*0a6a1f1dSLionel Sambuc.\" Copyright (c) 2015 The NetBSD Foundation, Inc. 4*0a6a1f1dSLionel Sambuc.\" All rights reserved. 5*0a6a1f1dSLionel Sambuc.\" 6*0a6a1f1dSLionel Sambuc.\" This code is derived from software contributed to The NetBSD Foundation 7*0a6a1f1dSLionel Sambuc.\" by Christos Zoulas. 8*0a6a1f1dSLionel Sambuc.\" 9*0a6a1f1dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without 10*0a6a1f1dSLionel Sambuc.\" modification, are permitted provided that the following conditions 11*0a6a1f1dSLionel Sambuc.\" are met: 12*0a6a1f1dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright 13*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer. 14*0a6a1f1dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright 15*0a6a1f1dSLionel Sambuc.\" notice, this list of conditions and the following disclaimer in the 16*0a6a1f1dSLionel Sambuc.\" documentation and/or other materials provided with the distribution. 17*0a6a1f1dSLionel Sambuc.\" 18*0a6a1f1dSLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19*0a6a1f1dSLionel Sambuc.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20*0a6a1f1dSLionel Sambuc.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21*0a6a1f1dSLionel Sambuc.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22*0a6a1f1dSLionel Sambuc.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23*0a6a1f1dSLionel Sambuc.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24*0a6a1f1dSLionel Sambuc.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25*0a6a1f1dSLionel Sambuc.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26*0a6a1f1dSLionel Sambuc.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27*0a6a1f1dSLionel Sambuc.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28*0a6a1f1dSLionel Sambuc.\" POSSIBILITY OF SUCH DAMAGE. 29*0a6a1f1dSLionel Sambuc.\" 30*0a6a1f1dSLionel Sambuc.Dd June 4, 2015 31*0a6a1f1dSLionel Sambuc.Dt BLACKLISTD 8 32*0a6a1f1dSLionel Sambuc.Os 33*0a6a1f1dSLionel Sambuc.Sh NAME 34*0a6a1f1dSLionel Sambuc.Nm blacklistd 35*0a6a1f1dSLionel Sambuc.Nd block and release ports on demand to avoid DoS abuse 36*0a6a1f1dSLionel Sambuc.Sh SYNOPSIS 37*0a6a1f1dSLionel Sambuc.Nm 38*0a6a1f1dSLionel Sambuc.Op Fl dfrv 39*0a6a1f1dSLionel Sambuc.Op Fl C Ar controlprog 40*0a6a1f1dSLionel Sambuc.Op Fl c Ar configfile 41*0a6a1f1dSLionel Sambuc.Op Fl D Ar dbfile 42*0a6a1f1dSLionel Sambuc.Op Fl P Ar sockpathsfile 43*0a6a1f1dSLionel Sambuc.Op Fl R Ar rulename 44*0a6a1f1dSLionel Sambuc.Op Fl s Ar sockpath 45*0a6a1f1dSLionel Sambuc.Op Fl t Ar timeout 46*0a6a1f1dSLionel Sambuc.Sh DESCRIPTION 47*0a6a1f1dSLionel Sambuc.Nm 48*0a6a1f1dSLionel Sambucis a daemon similar to 49*0a6a1f1dSLionel Sambuc.Xr syslogd 8 50*0a6a1f1dSLionel Sambucthat listens to a sockets at paths specified in the 51*0a6a1f1dSLionel Sambuc.Ar sockpathsfile 52*0a6a1f1dSLionel Sambucfor notifications from other daemons about successful or failed connection 53*0a6a1f1dSLionel Sambucattempts. 54*0a6a1f1dSLionel SambucIf no such file is specified, then it only listens to the socket path 55*0a6a1f1dSLionel Sambucspecified by 56*0a6a1f1dSLionel Sambuc.Ar sockspath 57*0a6a1f1dSLionel Sambucor if that is not specified to 58*0a6a1f1dSLionel Sambuc.Pa /var/run/blsock . 59*0a6a1f1dSLionel SambucEach notification contains an (action, port, protocol, address, owner) tuple 60*0a6a1f1dSLionel Sambucthat identifies the remote connection and the action. 61*0a6a1f1dSLionel SambucThis tuple is consulted against entries in 62*0a6a1f1dSLionel Sambuc.Ar configfile 63*0a6a1f1dSLionel Sambucwith syntax specified in 64*0a6a1f1dSLionel Sambuc.Xr blacklistd.conf 5 . 65*0a6a1f1dSLionel SambucIf an entry is matched, a state entry is created for that tuple. 66*0a6a1f1dSLionel SambucEach entry contains a number of tries limit and a duration. 67*0a6a1f1dSLionel Sambuc.Pp 68*0a6a1f1dSLionel SambucIf the action is 69*0a6a1f1dSLionel Sambuc.Dq add 70*0a6a1f1dSLionel Sambucand the number of tries limit is reached, then a 71*0a6a1f1dSLionel Sambuccontrol script 72*0a6a1f1dSLionel Sambuc.Ar controlprog 73*0a6a1f1dSLionel Sambucis invoked with arguments: 74*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent 75*0a6a1f1dSLionel Sambuccontrol add <rulename> <proto> <address> <mask> <port> 76*0a6a1f1dSLionel Sambuc.Ed 77*0a6a1f1dSLionel Sambuc.Pp 78*0a6a1f1dSLionel Sambucand should invoke a packet filter command to block the connection 79*0a6a1f1dSLionel Sambucspecified by the arguments. 80*0a6a1f1dSLionel SambucThe 81*0a6a1f1dSLionel Sambuc.Ar rulename 82*0a6a1f1dSLionel Sambucargument can be set from the command line (default 83*0a6a1f1dSLionel Sambuc.Dv blacklistd ) . 84*0a6a1f1dSLionel SambucThe script could print a numerical id to stdout as a handle for 85*0a6a1f1dSLionel Sambucthe rule that can be used later to remove that connection, but 86*0a6a1f1dSLionel Sambucthat is not required as all information to remove the rule is 87*0a6a1f1dSLionel Sambuckept. 88*0a6a1f1dSLionel Sambuc.Pp 89*0a6a1f1dSLionel SambucIf the action is 90*0a6a1f1dSLionel Sambuc.Dq remove 91*0a6a1f1dSLionel SambucThen the same control script is invoked as: 92*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent 93*0a6a1f1dSLionel Sambuccontrol remove <rulename> <proto> <address> <mask> <port> <id> 94*0a6a1f1dSLionel Sambuc.Ed 95*0a6a1f1dSLionel Sambuc.Pp 96*0a6a1f1dSLionel Sambucwhere 97*0a6a1f1dSLionel Sambuc.Ar id 98*0a6a1f1dSLionel Sambucis the number returned from the 99*0a6a1f1dSLionel Sambuc.Dq add 100*0a6a1f1dSLionel Sambucaction. 101*0a6a1f1dSLionel Sambuc.Pp 102*0a6a1f1dSLionel Sambuc.Nm 103*0a6a1f1dSLionel Sambucmaintains a database of known connections in 104*0a6a1f1dSLionel Sambuc.Ar dbfile . 105*0a6a1f1dSLionel SambucOn startup it reads entries from that file, and updates its internal state. 106*0a6a1f1dSLionel Sambuc.Pp 107*0a6a1f1dSLionel Sambuc.Nm 108*0a6a1f1dSLionel Sambucchecks the list of active entries every 109*0a6a1f1dSLionel Sambuc.Ar timeout 110*0a6a1f1dSLionel Sambucseconds (default 111*0a6a1f1dSLionel Sambuc.Dv 15 ) 112*0a6a1f1dSLionel Sambucand removes entries and block rules using the control program as necessary. 113*0a6a1f1dSLionel Sambuc.Pp 114*0a6a1f1dSLionel SambucThe following options are available: 115*0a6a1f1dSLionel Sambuc.Bl -tag -width indent 116*0a6a1f1dSLionel Sambuc.It Fl C Ar controlprog 117*0a6a1f1dSLionel SambucUse 118*0a6a1f1dSLionel Sambuc.Ar controlprog 119*0a6a1f1dSLionel Sambucto communicate with the packet filter, usually 120*0a6a1f1dSLionel Sambuc.Pa /libexec/blacklistd-helper . 121*0a6a1f1dSLionel SambucThe following arguments are passed to the control program: 122*0a6a1f1dSLionel Sambuc.Bl -tag -width protocol 123*0a6a1f1dSLionel Sambuc.It action 124*0a6a1f1dSLionel SambucThe action to perform: 125*0a6a1f1dSLionel Sambuc.Dv add , 126*0a6a1f1dSLionel Sambuc.Dv rem , 127*0a6a1f1dSLionel Sambucor 128*0a6a1f1dSLionel Sambuc.Dv flush 129*0a6a1f1dSLionel Sambucto add, remove or flush a firewall rule. 130*0a6a1f1dSLionel Sambuc.It name 131*0a6a1f1dSLionel SambucThe rule name. 132*0a6a1f1dSLionel Sambuc.It protocol 133*0a6a1f1dSLionel SambucThe optional protocol name (can be empty): 134*0a6a1f1dSLionel Sambuc.Dv tcp , 135*0a6a1f1dSLionel Sambuc.Dv tcp6 , 136*0a6a1f1dSLionel Sambuc.Dv udp , 137*0a6a1f1dSLionel Sambuc.Dv udp6 . 138*0a6a1f1dSLionel Sambuc.It address 139*0a6a1f1dSLionel SambucThe IPv4 or IPv6 numeric address to be blocked or released. 140*0a6a1f1dSLionel Sambuc.It mask 141*0a6a1f1dSLionel SambucThe numeric mask to be applied to the blocked or released address 142*0a6a1f1dSLionel Sambuc.It port 143*0a6a1f1dSLionel SambucThe optional numeric port to be blocked (can be empty). 144*0a6a1f1dSLionel Sambuc.It id 145*0a6a1f1dSLionel SambucFor packet filters that support removal of rules by rule identifier, the 146*0a6a1f1dSLionel Sambucidentifier of the rule to be removed. 147*0a6a1f1dSLionel SambucThe add command is expected to return the rule identifier string to stdout. 148*0a6a1f1dSLionel Sambuc.El 149*0a6a1f1dSLionel Sambuc.It Fl c Ar configuration 150*0a6a1f1dSLionel SambucThe name of the configuration file to read, usually 151*0a6a1f1dSLionel Sambuc.Pa /etc/blacklistd.conf . 152*0a6a1f1dSLionel Sambuc.It Fl D Ar dbfile 153*0a6a1f1dSLionel SambucThe Berkeley DB file where 154*0a6a1f1dSLionel Sambuc.Nm 155*0a6a1f1dSLionel Sambucstores its state, usually 156*0a6a1f1dSLionel Sambuc.Pa /var/run/blacklistd.db . 157*0a6a1f1dSLionel Sambuc.It Fl d 158*0a6a1f1dSLionel SambucNormally, 159*0a6a1f1dSLionel Sambuc.Nm 160*0a6a1f1dSLionel Sambucdisassociates itself from the terminal unless the 161*0a6a1f1dSLionel Sambuc.Fl d 162*0a6a1f1dSLionel Sambucflag is specified, in which case it stays in the foreground. 163*0a6a1f1dSLionel Sambuc.It Fl f 164*0a6a1f1dSLionel SambucTruncate the state database and flush all the rules named 165*0a6a1f1dSLionel Sambuc.Ar rulename 166*0a6a1f1dSLionel Sambucare deleted by invoking the control script as: 167*0a6a1f1dSLionel Sambuc.Bd -literal -offset indent 168*0a6a1f1dSLionel Sambuccontrol flush <rulename> 169*0a6a1f1dSLionel Sambuc.Ed 170*0a6a1f1dSLionel Sambuc.It Fl P Ar sockspathsfile 171*0a6a1f1dSLionel SambucA file containing a list of pathnames, one per line that 172*0a6a1f1dSLionel Sambuc.Nm 173*0a6a1f1dSLionel Sambucwill create sockets to listen to. 174*0a6a1f1dSLionel SambucThis is useful for chrooted environments. 175*0a6a1f1dSLionel Sambuc.It Fl R Ar rulename 176*0a6a1f1dSLionel SambucSpecify the default rule name for the packet filter rules, usually 177*0a6a1f1dSLionel Sambuc.Dv blacklistd . 178*0a6a1f1dSLionel Sambuc.It Fl r 179*0a6a1f1dSLionel SambucRe-read the firewall rules from the internal database, then 180*0a6a1f1dSLionel Sambucremove and re-add them. 181*0a6a1f1dSLionel SambucThis helps for packet filters that don't retain state across reboots. 182*0a6a1f1dSLionel Sambuc.It Fl s Ar sockpath 183*0a6a1f1dSLionel SambucAdd 184*0a6a1f1dSLionel Sambuc.Ar sockpath 185*0a6a1f1dSLionel Sambucto the list of Unix sockets 186*0a6a1f1dSLionel Sambuc.Nm 187*0a6a1f1dSLionel Sambuclistens to. 188*0a6a1f1dSLionel Sambuc.It Fl t Ar timeout 189*0a6a1f1dSLionel SambucThe interval in seconds 190*0a6a1f1dSLionel Sambuc.Nm 191*0a6a1f1dSLionel Sambucpolls the state file to update the rules. 192*0a6a1f1dSLionel Sambuc.It Fl v 193*0a6a1f1dSLionel SambucCause 194*0a6a1f1dSLionel Sambuc.Nm 195*0a6a1f1dSLionel Sambucto print 196*0a6a1f1dSLionel Sambucdiagnostic messages to 197*0a6a1f1dSLionel Sambuc.Dv stdout 198*0a6a1f1dSLionel Sambucinstead of 199*0a6a1f1dSLionel Sambuc.Xr syslogd 8 . 200*0a6a1f1dSLionel Sambuc.El 201*0a6a1f1dSLionel Sambuc.Sh FILES 202*0a6a1f1dSLionel Sambuc.Bl -tag -width /libexec/blacklistd-helper -compact 203*0a6a1f1dSLionel Sambuc.It Pa /libexec/blacklistd-helper 204*0a6a1f1dSLionel SambucShell script invoked to interface with the packet filter. 205*0a6a1f1dSLionel Sambuc.It Pa /etc/blacklistd.conf 206*0a6a1f1dSLionel SambucConfiguration file. 207*0a6a1f1dSLionel Sambuc.It Pa /var/db/blacklistd.db 208*0a6a1f1dSLionel SambucDatabase of current connection entries. 209*0a6a1f1dSLionel Sambuc.It Pa /var/run/blsock 210*0a6a1f1dSLionel SambucSocket to receive connection notifications. 211*0a6a1f1dSLionel Sambuc.El 212*0a6a1f1dSLionel Sambuc.Sh SEE ALSO 213*0a6a1f1dSLionel Sambuc.Xr blacklistd.conf 5 , 214*0a6a1f1dSLionel Sambuc.Xr blacklistctl 8 , 215*0a6a1f1dSLionel Sambuc.Xr npfctl 8 , 216*0a6a1f1dSLionel Sambuc.Xr syslogd 8 217*0a6a1f1dSLionel Sambuc.Sh HISTORY 218*0a6a1f1dSLionel Sambuc.Nm 219*0a6a1f1dSLionel Sambucappeared in 220*0a6a1f1dSLionel Sambuc.Nx 7 . 221*0a6a1f1dSLionel Sambuc.Sh AUTHORS 222*0a6a1f1dSLionel Sambuc.An Christos Zoulas 223