1 # $NetBSD: README,v 1.7 2015/01/26 00:34:50 christos Exp $
3 This package contains library that can be used by network daemons to
4 communicate with a packet filter via a daemon to enforce opening and
5 closing ports dynamically based on policy.
7 The interface to the packet filter is in libexec/blacklistd-helper
8 (this is currently designed for npf) and the configuration file
9 (inspired from inetd.conf) is in etc/blacklistd.conf.
11 On NetBSD you can find an example npf.conf and blacklistd.conf in
12 /usr/share/examples/blacklistd; you need to adjust the interface
13 in npf.conf and copy both files to /etc; then you just enable
14 blacklistd=YES in /etc/rc.conf, start it up, and you are all set.
16 There is also a startup file in etc/rc.d/blacklistd
18 Patches to various daemons to add blacklisting capabilitiers are in the
20 - OpenSSH: diff/ssh.diff [tcp socket example]
21 - Bind: diff/named.diff [both tcp and udp]
22 - ftpd: diff/ftpd.diff [tcp]
24 These patches have been applied to NetBSD-current.
26 The network daemon (for example sshd) communicates to blacklistd, via
27 a unix socket like syslog. The library calls are simple and everything
28 is handled by the library. In the simplest form the only thing the
29 daemon needs to do is to call:
31 blacklist(action, acceptedfd, message);
34 action = 0 -> successful login clear blacklist state
35 1 -> failed login, add to the failed count
36 acceptedfd -> the file descriptor where the server is
37 connected to the remote client. It is used
38 to determine the listening socket, and the
39 remote address. This allows any program to
40 contact the blacklist daemon, since the verification
41 if the program has access to the listening
42 socket is done by virtue that the port
43 number is retrieved from the kernel.
44 message -> an optional string that is used in debugging logs.
46 Unfortunately there is no way to get information about the "peer"
47 from a udp socket, because there is no connection and that information
48 is kept with the server. In that case the daemon can provide the
49 peer information to blacklistd via:
51 blacklist_sa(action, acceptedfd, sockaddr, sockaddr_len, message);
53 The configuration file contains entries of the form:
56 # host/Port type protocol owner name nfail disable
57 192.168.1.1:ssh stream tcp * -int 10 1m
58 8.8.8.8:ssh stream tcp * -ext 6 60m
59 ssh stream tcp6 * * 6 60m
60 http stream tcp * * 6 60m
62 Here note that owner is * because the connection is done from the
63 child ssh socket which runs with user privs. We treat ipv4 connections
64 differently by maintaining two different rules one for the external
65 interface and one from the internal We also register for both tcp
66 and tcp6 since those are different listening sockets and addresses;
67 we don't bother with ipv6 and separate rules. We use nfail = 6,
68 because ssh allows 3 password attempts per connection, and this
69 will let us have 2 connections before blocking. Finally we block
70 for an hour; we could block forever too by specifying * in the
73 blacklistd and the library use syslog(3) to report errors. The
74 blacklist filter state is persisted automatically in /var/db/blacklistd.db
75 so that if the daemon is restarted, it remembers what connections
76 is currently handling. To start from a fresh state (if you restart
77 npf too for example), you can use -f. To watch the daemon at work,
80 The current control file is designed for npf, and it uses the
81 dynamic rule feature. You need to create a dynamic rule in your
82 /etc/npf.conf on the group referring to the interface you want to block
83 called blacklistd as follows:
88 group "external" on $ext_if {
90 ruleset "blacklistd-ext"
95 group "internal" on $int_if {
97 ruleset "blacklistd-int"