HOSTS_ACCESS(5) | HOSTS_ACCESS(5) |
Note that in a `stock' installation of the tcp_wrappers package, a program called tcpd is called from /etc/inetd.conf, and this program performs the wrapper checks and then executes the daemon. In NetBSD inetd(8) has been modified to perform this check internally, and so tcpd is neither used nor supplied.
Also note that libwrap under NetBSD uses the extensions to the access control language as described in the hosts_options(5).
In the following text, daemon is the process name of a network daemon process, and client is the name and/or address of a host requesting service. Network daemon process names are specified in the inetd configuration file.
• | Access will be granted when a (daemon,client) pair matches an entry in the /etc/hosts.allow file. |
• | Otherwise, access will be denied when a (daemon,client) pair matches an entry in the /etc/hosts.deny file. |
• | Otherwise, access will be granted. |
A non-existing access control file is treated as if it were an empty file. Thus, access control can be turned off by providing no access control files.
• | A newline character is ignored when it is preceded by a backslash character. This permits you to break up long lines so that they are easier to edit. WARNING: The total length of an entry can be no more than 2047 characters long including the final newline. |
• | Blank lines or lines that begin with a `#́ character are ignored. This permits you to insert comments and whitespace so that the tables are easier to read. |
• |
All other lines should satisfy the following format, things between [] being optional: |
daemon_list is a list of one or more daemon process names (argv[0] values) or wildcards (see below).
client_list is a list of one or more host names, host addresses, patterns or wildcards (see below) that will be matched against the client host name or address. When a client_list item needs to include colon character (for IPv6 addresses), the item needs to be wrapped with square bracket.
The more complex forms daemon@host and user@host are explained in the sections on server endpoint patterns and on client username lookups, respectively.
List elements should be separated by blanks and/or commas.
With the exception of NIS (YP) netgroup lookups, all access control checks are case insensitive.
• | A string that begins with a `.́ character. A host name is matched if the last components of its name match the specified pattern. For example, the pattern `.tue.nĺ matches the host name `wzv.win.tue.nĺ. |
• | A string that ends with a `.́ character. A host address is matched if its first numeric fields match the given string. For example, the pattern `131.155.́ matches the address of (almost) every host on the Eindhoven University network (131.155.x.x). |
• | A string that begins with an `@́ character is treated as an NIS (formerly YP) netgroup name. A host name is matched if it is a host member of the specified netgroup. Netgroup matches are not supported for daemon process names or for client user names. |
• | An expression of the form `n.n.n.n/m.m.m.ḿ is interpreted as a `net/masḱ pair. A host address is matched if `net́ is equal to the bitwise AND of the address and the `masḱ. For example, the net/mask pattern `131.155.72.0/255.255.254.0́ matches every address in the range `131.155.72.0́ through `131.155.73.255́. Note that `m.m.m.ḿ portion must always be specified. |
• | An expression of the form `ipv6-addr/ipv6-masḱ is interpreted as masked IPv6 address match, just like masked IPv4 address match (see above). Note that `ipv6-masḱ portion must always be specified. |
• | An expression of the form `ipv6-addr/prefixleń is interpreted as masked IPv6 address match (with mask specified by numeric prefixlen), just like masked IPv4 address match (see above). Note that `prefixleń portion must always be specified. |
• | A string that begins with a `/́ character is treated as a file name. A host name or address is matched if it matches any host name or address pattern listed in the named file. The file format is zero or more lines with zero or more host name or address patterns separated by whitespace. A file name pattern can be used anywhere a host name or address pattern can be used. |
ALL | The universal wildcard, always matches. |
LOCAL | Matches any host whose name does not contain a dot character. |
UNKNOWN | Matches any user whose name is unknown, and matches any host whose name or address are unknown. This pattern should be used with care: host names may be unavailable due to temporary name server problems. A network address will be unavailable when the software cannot figure out what type of network it is talking to. |
KNOWN | Matches any user whose name is known, and matches any host whose name and address are known. This pattern should be used with care: host names may be unavailable due to temporary name server problems. A network address will be unavailable when the software cannot figure out what type of network it is talking to. |
PARANOID | Matches any host whose name does not match its address. Note that unlike the default mode of tcpd, NetBSD inetd does not automatically drop these requests; you must explicitly drop them in your /etc/hosts.allow or /etc/hosts.deny file. |
{RBL}.domain | Matches any host whose reversed address appears in the DNS under domain. The primary such domain used for blocking unsolicited commercial e-mail (spam) is `.rbl.maps.vix.coḿ. |
EXCEPT |
Intended use is of the form: `list_1 EXCEPT list_2́; this construct matches anything that matches list_1 unless it matches list_2. The EXCEPT operator can be used in daemon_lists and in client_lists. The EXCEPT operator can be nested: if the control language would permit the use of parentheses, `a EXCEPT b EXCEPT ć would parse as `(a EXCEPT (b EXCEPT c))́. |
%a (%A) | The client (server) host address. |
%c | Client information: user@host, user@address, a host name, or just an address, depending on how much information is available. |
%d | The daemon process name (argv[0] value). |
%h (%H) | The client (server) host name or address, if the host name is unavailable. |
%n (%N) | The client (server) host name (or "unknown" or "paranoid"). |
%p | The daemon process id. |
%s | Server information: daemon@host, daemon@address, or just a daemon name, depending on how much information is available. |
%u | The client user name (or "unknown"). |
%% | Expands to a single `%́ character. |
Characters in % expansions that may confuse the shell are replaced by underscores.
daemon_list : ... user_pattern@host_pattern ...
The daemon wrappers can be configured at compile time to perform rule-driven username lookups (default) or to always interrogate the client host. In the case of rule-driven username lookups, the above rule would cause username lookup only when both the daemon_list and the host_pattern match.
A user pattern has the same syntax as a daemon process pattern, so the same wildcards apply (netgroup membership is not supported). One should not get carried away with username lookups, though.
• | The client username information cannot be trusted when it is needed most, i.e. when the client system has been compromised. In general, ALL and (UN)KNOWN are the only user name patterns that make sense. |
• | Username lookups are possible only with TCP-based services, and only when the client host runs a suitable daemon; in all other cases the result is "unknown". |
• | A well-known UNIX kernel bug may cause loss of service when username lookups are blocked by a firewall. The wrapper README document describes a procedure to find out if your kernel has this bug. |
• | Username lookups may cause noticeable delays for non-UNIX users. The default timeout for username lookups is 10 seconds: too short to cope with slow networks, but long enough to irritate PC users. |
Selective username lookups can alleviate the last problem. For example, a rule like:
daemon_list : @pcnetgroup ALL@ALL
would match members of the pc netgroup without doing username lookups, but would perform username lookups with all other systems.
Before accepting a client request, the wrappers can use the IDENT service to find out that the client did not send the request at all. When the client host provides IDENT service, a negative IDENT lookup result (the client matches `UNKNOWN@host') is strong evidence of a host spoofing attack.
A positive IDENT lookup result (the client matches `KNOWN@host') is less trustworthy. It is possible for an intruder to spoof both the client connection and the IDENT lookup, although doing so is much harder than spoofing just a client connection. It may also be that the client́s IDENT server is lying.
Note: IDENT lookups dońt work with UDP services.
When reading the examples below it is important to realize that the allow table is scanned before the deny table, that the search terminates when a match is found, and that access is granted when no match is found at all.
The examples use host and domain names. They can be improved by including address and/or network/netmask information, to reduce the impact of temporary name server lookup failures.
The default policy (no access) is implemented with a trivial deny file:
/etc/hosts.deny:
ALL: ALL
This denies all service to all hosts, unless they are permitted access by entries in the allow file.
The explicitly authorized hosts are listed in the allow file. For example:
/etc/hosts.allow:
ALL: LOCAL @some_netgroup
The first rule permits access from hosts in the local domain (no `.́ in the host name) and from members of the some_netgroup netgroup. The second rule permits access from all hosts in the foobar.edu domain (notice the leading dot), with the exception of terminalserver.foobar.edu.
The default policy (access granted) makes the allow file redundant so that it can be omitted. The explicitly non-authorized hosts are listed in the deny file. For example:
/etc/hosts.deny:
ALL: some.host.name, .some.domain
The first rule denies some hosts and domains all services; the second rule still permits finger requests from other hosts and domains.
/etc/hosts.allow:
in.tftpd: LOCAL, .my.domain
/etc/hosts.deny:
in.tftpd: ALL: spawn (/some/where/safe_finger -l @%h | \
/usr/ucb/mail -s %d-%h root) &
(The safe_finger command can be gotten from the tcp_wrappers package and installed in a suitable place. It limits possible damage from data sent by the remote finger server. It gives better protection than the standard finger command.)
The expansion of the %h (client host) and %d (service name) sequences is described in the section on shell commands.
Warning: do not booby-trap your finger daemon, unless you are prepared for infinite finger loops.
On network firewall systems this trick can be carried even further. The typical network firewall only provides a limited set of services to the outer world. All other services can be "bugged" just like the above tftp example. The result is an excellent early-warning system.
Domain name server lookups are case insensitive; NIS (formerly YP)
netgroup lookups are case sensitive.
The total length of an entry can be no more than 2047 characters long,
including the final newline.
August 25, 2011 |