MAN page from RedHat EL 4 tcp_wrappers-libs-7.6-57.el4.rfx.x86_64.rpm
HOSTS_ACCESS
Section: File Formats (5)
Index NAME
hosts_access - format of host access control files
DESCRIPTION
This manual page describes a simple access control language that isbased on client (host name/address, user name), and server (processname, host name/address) patterns. Examples are given at the end. Theimpatient reader is encouraged to skip to the EXAMPLES section for aquick introduction.
An extended version of the access control language is described in thehosts_options(5) document. The extensions are turned on atprogram build time by building with -DPROCESS_OPTIONS.
In the following text, daemon is the the process name of anetwork daemon process, and client is the name and/or address ofa host requesting service. Network daemon process names are specifiedin the inetd configuration file.
ACCESS CONTROL FILES
The access control software consults two files. The search stopsat the first match:
- *
- Access will be granted when a (daemon,client) pair matches an entry inthe /etc/hosts.allow file.
- *
- Otherwise, access will be denied when a (daemon,client) pair matches anentry in the /etc/hosts.deny file.
- *
- Otherwise, access will be granted.
A non-existing access control file is treated as if it were an emptyfile. Thus, access control can be turned off by providing no accesscontrol files.
ACCESS CONTROL RULES
Each access control file consists of zero or more lines of text. Theselines are processed in order of appearance. The search terminates when amatch is found.
- *
- A newline character is ignored when it is preceded by a backslashcharacter. This permits you to break up long lines so that they areeasier to edit.
- *
- Blank lines or lines that begin with a `#' character are ignored.This permits you to insert comments and whitespace so that the tablesare easier to read.
- *
- All other lines should satisfy the following format, things between []being optional:
daemon_list : client_list [ : shell_command ]
daemon_list is a list of one or more daemon process names(argv[0] values) or wildcards (see below).
client_list is a listof one or more host names, host addresses, patterns or wildcards (seebelow) that will be matched against the client host name or address.
The more complex forms daemon@host and userAATThost areexplained in the sections on server endpoint patterns and on clientusername lookups, respectively.
List elements should be separated by blanks and/or commas.
With the exception of NIS (YP) netgroup lookups, all access controlchecks are case insensitive.
PATTERNS
The access control language implements the following patterns:
- *
- A string that begins with a `.' character. A host name is matched ifthe last components of its name match the specified pattern. Forexample, the pattern `.tue.nl' matches the host name`wzv.win.tue.nl'.
- *
- A string that ends with a `.' character. A host address is matched ifits first numeric fields match the given string. For example, thepattern `131.155.' matches the address of (almost) every host on theEindhoven 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 hostmember of the specified netgroup. Netgroup matches are not supportedfor daemon process names or for client user names.
- *
- An expression of the form `n.n.n.n/m.m.m.m' is interpreted as a`net/mask' pair. An IPv4 host address is matched if `net' is equal to thebitwise AND of the address and the `mask'. For example, the net/maskpattern `131.155.72.0/255.255.254.0' matches every address in therange `131.155.72.0' through `131.155.73.255'.
- *
- An expression of the form `[n:n:n:n:n:n:n:n]/m' is interpreted as a`[net]/prefixlen' pair. An IPv6 host address is matched if`prefixlen' bits of `net' is equal to the `prefixlen' bits of theaddress. For example, the [net]/prefixlen pattern`[3ffe:505:2:1::]/64' matches every address in the range`3ffe:505:2:1::' through `3ffe:505:2:1:ffff:ffff:ffff:ffff'.
- *
- A string that begins with a `/' character is treated as a filename. A host name or address is matched if it matches any host nameor address pattern listed in the named file. The file format iszero or more lines with zero or more host name or address patternsseparated by whitespace. A file name pattern can be used anywherea host name or address pattern can be used.
- *
- Wildcards `*' and `?' can be used to match hostnames or IP addresses. Thismethod of matching cannot be used in conjunction with `net/mask' matching,hostname matching beginning with `.' or IP address matching ending with `.'.
WILDCARDS
The access control language supports explicit wildcards:
- 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 nameor address are unknown. This pattern should be used with care:host names may be unavailable due to temporary name server problems. Anetwork address will be unavailable when the software cannot figure outwhat type of network it is talking to.
- KNOWN
- Matches any user whose name is known, and matches any host whose nameand address are known. This pattern should be used with care:host names may be unavailable due to temporary name server problems. Anetwork address will be unavailable when the software cannot figure outwhat type of network it is talking to.
- PARANOID
- Matches any host whose name does not match its address. When tcpd isbuilt with -DPARANOID (default mode), it drops requests from suchclients even before looking at the access control tables. Buildwithout -DPARANOID when you want more control over such requests.
OPERATORS
- EXCEPT
- Intended use is of the form: `list_1 EXCEPT list_2'; this constructmatches anything that matches list_1 unless it matcheslist_2. The EXCEPT operator can be used in daemon_lists and inclient_lists. The EXCEPT operator can be nested: if the controllanguage would permit the use of parentheses, `a EXCEPT b EXCEPT c'would parse as `(a EXCEPT (b EXCEPT c))'.
SHELL COMMANDS
If the first-matched access control rule contains a shell command, thatcommand is subjected to %<letter> substitutions (see next section).The result is executed by a
/bin/sh child process with standardinput, output and error connected to
/dev/null. Specify an `&'at the end of the command if you do not want to wait until it hascompleted.
Shell commands should not rely on the PATH setting of the inetd.Instead, they should use absolute path names, or they should begin withan explicit PATH=whatever statement.
The hosts_options(5) document describes an alternative languagethat uses the shell command field in a different and incompatible way.
% EXPANSIONS
The following expansions are available within shell commands:
- %a (%A)
- The client (server) host address.
- %c
- Client information: user@host, userAATTaddress, a host name, or just anaddress, 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 isunavailable.
- %n (%N)
- The client (server) host name (or "unknown" or "paranoid").
- %p
- The daemon process id.
- %s
- Server information: daemon@host, daemonAATTaddress, 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 byunderscores.
SERVER ENDPOINT PATTERNS
In order to distinguish clients by the network address that theyconnect to, use patterns of the form:
process_nameAATThost_pattern : client_list ...
Patterns like these can be used when the machine has different internetaddresses with different internet hostnames. Service providers can usethis facility to offer FTP, GOPHER or WWW archives with internet namesthat 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 physicalinterface; with other systems you may have to resort to SLIP or PPPpseudo interfaces that live in a dedicated network address space.
The host_pattern obeys the same syntax rules as host names andaddresses in client_list context. Usually, server endpoint informationis available only with connection-oriented services.
CLIENT USERNAME LOOKUP
When the client host supports the RFC 931 protocol or one of itsdescendants (TAP, IDENT, RFC 1413) the wrapper programs can retrieveadditional information about the owner of a connection. Client usernameinformation, when available, is logged together with the client hostname, and can be used to match patterns like:
daemon_list : ... user_patternAATThost_pattern ...
The daemon wrappers can be configured at compile time to performrule-driven username lookups (default) or to always interrogate theclient host. In the case of rule-driven username lookups, the aboverule would cause username lookup only when both the daemon_listand the host_pattern match.
A user pattern has the same syntax as a daemon process pattern, so thesame wildcards apply (netgroup membership is not supported). Oneshould not get carried away with username lookups, though.
- *
- The client username information cannot be trusted when it is neededmost, 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 onlywhen the client host runs a suitable daemon; in all other cases theresult is "unknown".
- *
- A well-known UNIX kernel bug may cause loss of service when usernamelookups are blocked by a firewall. The wrapper README documentdescribes a procedure to find out if your kernel has this bug.
- *
- Username lookups may cause noticeable delays for non-UNIX users. Thedefault timeout for username lookups is 10 seconds: too short to copewith 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.
DETECTING ADDRESS SPOOFING ATTACKS
A flaw in the sequence number generator of many TCP/IP implementationsallows intruders to easily impersonate trusted hosts and to break invia, for example, the remote shell service. The IDENT (RFC931 etc.)service can be used to detect such and other host address spoofingattacks.
Before accepting a client request, the wrappers can use the IDENTservice to find out that the client did not send the request at all.When the client host provides IDENT service, a negative IDENT lookupresult (the client matches `UNKNOWNAATThost') is strong evidence of a hostspoofing attack.
A positive IDENT lookup result (the client matches `KNOWNAATThost') isless trustworthy. It is possible for an intruder to spoof both theclient connection and the IDENT lookup, although doing so is muchharder than spoofing just a client connection. It may also be thatthe client's IDENT server is lying.
Note: IDENT lookups don't work with UDP services.
EXAMPLES
The language is flexible enough that different types of access controlpolicy can be expressed with a minimum of fuss. Although the languageuses two access control tables, the most common policies can beimplemented with one of the tables being trivial or even empty.
When reading the examples below it is important to realize that theallow table is scanned before the deny table, that the searchterminates when a match is found, and that access is granted when nomatch is found at all.
The examples use host and domain names. They can be improved byincluding address and/or network/netmask information, to reduce theimpact of temporary name server lookup failures.
MOSTLY CLOSED
In this case, access is denied by default. Only explicitly authorizedhosts are permitted access.
The default policy (no access) is implemented with a trivial denyfile:
/etc/hosts.deny: ALL: ALL
This denies all service to all hosts, unless they are permitted accessby 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_netgroupnetgroup. The second rule permits access from all hosts in thefoobar.edu domain (notice the leading dot), with the exception ofterminalserver.foobar.edu.
MOSTLY OPEN
Here, access is granted by default; only explicitly specified hosts arerefused service.
The default policy (access granted) makes the allow file redundant sothat it can be omitted. The explicitly non-authorized hosts are listedin the deny file. For example:
/etc/hosts.deny:ALL: some.host.name, .some.domain
ALL EXCEPT in.fingerd: other.host.name, .other.domain
The first rule denies some hosts and domains all services; the secondrule still permits finger requests from other hosts and domains.
BOOBY TRAPS
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 offendinghost. The result is mailed to the superuser.
/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 comes with the tcpd wrapper and should beinstalled in a suitable place. It limits possible damage from data sentby the remote finger server. It gives better protection than thestandard finger command.
The expansion of the %h (client host) and %d (service name) sequencesis described in the section on shell commands.
Warning: do not booby-trap your finger daemon, unless you are preparedfor 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 tothe outer world. All other services can be "bugged" just like the abovetftp example. The result is an excellent early-warning system.
DIAGNOSTICS
An error is reported when a syntax error is found in a host accesscontrol rule; when the length of an access control rule exceeds thecapacity of an internal buffer; when an access control rule is notterminated by a newline character; when the result of %<letter>expansion would overflow an internal buffer; when a system call failsthat shouldn't. All problems are reported via the syslog daemon.
FILES
/etc/hosts.allow, (daemon,client) pairs that are granted access./etc/hosts.deny, (daemon,client) pairs that are denied access.
SEE ALSO
tcpd(8) tcp/ip daemon wrapper program.tcpdchk(8), tcpdmatch(8), test programs.
BUGS
If a name server lookup times out, the host name will not be availableto the access control software, even though the host is registered.
Domain name server lookups are case insensitive; NIS (formerly YP)netgroup lookups are case sensitive.
AUTHOR
Wietse Venema (wietseAATTwzv.win.tue.nl)Department of Mathematics and Computing ScienceEindhoven University of TechnologyDen Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
Index
- NAME
- DESCRIPTION
- ACCESS CONTROL FILES
- ACCESS CONTROL RULES
- PATTERNS
- WILDCARDS
- OPERATORS
- SHELL COMMANDS
- % EXPANSIONS
- SERVER ENDPOINT PATTERNS
- CLIENT USERNAME LOOKUP
- DETECTING ADDRESS SPOOFING ATTACKS
- EXAMPLES
- MOSTLY CLOSED
- MOSTLY OPEN
- BOOBY TRAPS
- DIAGNOSTICS
- FILES
- SEE ALSO
- BUGS
- AUTHOR
This document was created byman2html,using the manual pages.