Section: File Formats (5)
This manual page describes a simple access control language that is based on client (host name/address, user name), and server (process name, host name/address) patterns. Examples are given at the end. The impatient reader is encouraged to skip to the EXAMPLES section for a quick introduction.
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.
The access control software consults two files. The search stops at the first match:
Each access control file consists of zero or more lines of text. These lines are processed in order of appearance. The search terminates when a match is found.
daemon_list : client_list [ : shell_command ]
daemon_list is a list of one or more daemon process names (argv values) or server port numbers 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.
List elements should be separated by blanks and/or commas.
The access control language implements the following patterns:
The access control language supports explicit wildcards:
If the first-matched access control rule contains a shell command, that command is subjected to %<letter> substitutions (see next section). The result is executed by a /bin/sh child process with standard input, output and error connected to /dev/null. Specify an `&' at the end of the command if you do not want to wait until it has completed.
Shell commands should not rely on the PATH setting of the inetd. Instead, they should use absolute path names, or they should begin with an explicit PATH=whatever statement.
The following expansions are available within shell commands:
In order to distinguish clients by the network address that they connect to, use patterns of the form:
process_name@host_pattern : client_list ...
Patterns like these can be used when the machine has different internet addresses with different internet hostnames. Service providers can use this facility to offer FTP, GOPHER or WWW archives with internet names that may even belong to different organizations. See also the `twist' option in the hosts_options?(5) document. Some systems (Solaris, FreeBSD) can have more than one internet address on one physical interface; with other systems you may have to resort to SLIP or PPP pseudo interfaces that live in a dedicated network address space.
When the client host supports the RFC 931 protocol or one of its descendants (TAP, IDENT, RFC 1413) the wrapper programs can retrieve additional information about the owner of a connection. Client username information, when available, is logged together with the client host name, and can be used to match patterns like:
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.
Selective username lookups can alleviate the last problem. For example, a rule like:
daemon_list : @pcnetgroup ALL@ALL
A flaw in the sequence number generator of many TCP/IP implementations allows intruders to easily impersonate trusted hosts and to break in via, for example, the remote shell service. The IDENT (RFC931 etc.) service can be used to detect such and other host address spoofing attacks.
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.
The language is flexible enough that different types of access control policy can be expressed with a minimum of fuss. Although the language uses two access control tables, the most common policies can be implemented with one of the tables being trivial or even empty.
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.
In this case, access is denied by default. Only explicitly authorized hosts are permitted access.
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
ALL: .foobar.edu EXCEPT terminalserver.foobar.edu
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.
Here, access is granted by default; only explicitly specified hosts are refused service.
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
ALL EXCEPT in.fingerd: other.host.name, .other.domain
The next example permits tftp requests from hosts in the local domain (notice the leading dot). Requests from any other hosts are denied. Instead of the requested file, a finger probe is sent to the offending host. The result is mailed to the superuser.
in.tftpd: LOCAL, .my.domain /etc/hosts.deny: in.tftpd: ALL: (/usr/sbin/safe_finger -l @%h | \ /usr/bin/mail -s %d-%h root) &
The safe_finger command comes with the tcpd wrapper and should be 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 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.
An error is reported when a syntax error is found in a host access control rule; when the length of an access control rule exceeds the capacity of an internal buffer; when an access control rule is not terminated by a newline character; when the result of %<letter> expansion would overflow an internal buffer; when a system call fails that shouldn't. All problems are reported via the syslog daemon.
/etc/hosts.allow, (daemon,client) pairs that are granted access. /etc/hosts.deny, (daemon,client) pairs that are denied access.
If a name server lookup times out, the host name will not be available to the access control software, even though the host is registered.
Wietse Venema (firstname.lastname@example.org) Department of Mathematics and Computing Science Eindhoven University of Technology Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
Tutoriais de Tecnologia Web