1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
|
.\" $OpenBSD: hosts_access.5,v 1.23 2004/02/19 22:25:38 jmc Exp $
.\"
.\" Copyright (c) 1997, Jason Downs. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS
.\" OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
.\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT,
.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
.\" CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.Dd June 23, 1997
.Dt HOSTS_ACCESS 5
.Os
.Sh NAME
.Nm hosts_access ,
.Nm hosts.deny ,
.Nm hosts.allow
.Nd tcp wrapper format of host access control files
.Sh DESCRIPTION
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.
.Pp
An extended version of the access control language is described in the
.Xr hosts_options 5
document.
.\" The extensions are turned on at
.\" program build time by building with -DPROCESS_OPTIONS.
.Pp
In the following text,
.Ar daemon
is the process name of a network daemon process, and
.Ar client
is the name and/or address of a host requesting service.
Network daemon process names are specified in the inetd configuration file.
.Sh ACCESS CONTROL FILES
The access control software consults two files.
The search stops at the first match:
.Bl -bullet -width XXX
.It
Access will be granted when a (daemon,client) pair matches an entry in
the
.Pa /etc/hosts.allow
file.
.It
Otherwise, access will be denied when a (daemon,client) pair matches an
entry in the
.Pa /etc/hosts.deny
file.
.It
Otherwise, access will be granted.
.El
.Pp
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.
.Sh ACCESS CONTROL RULES
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.
.Bl -bullet -width XXX
.It
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.
.It
Blank lines or lines that begin with a
.Sq #
character are ignored.
This permits you to insert comments and whitespace so that the tables
are easier to read.
.It
All other lines should satisfy the following format, things between []
being optional:
.Pp
.Dl daemon_list\ \&: client_list [\ \&: shell_command\ \&]
.El
.Pp
.Ar daemon_list
is a list of one or more daemon process names
.Pf ( Va argv[0]
values) or wildcards (see below).
.Pp
.Ar 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 characters (for IPv6 addresses),
the item needs to be wrapped with square brackets.
.Pp
The more complex forms
.Ar daemon@host
and
.Ar user@host
are
explained in the sections on server endpoint patterns and on client
username lookups, respectively.
.Pp
List elements should be separated by blanks and/or commas.
.Pp
With the exception of YP netgroup lookups, all access control
checks are case insensitive.
.Sh PATTERNS
The access control language implements the following patterns:
.Bl -bullet -width XXX
.It
A string that begins with a
.Sq \&.
character.
A host name is matched if
the last components of its name match the specified pattern.
For example, the pattern
.Sq .tue.nl
matches the host name
.Sq wzv.win.tue.nl .
.It
A string that ends with a
.Sq \&.
character.
A host address is matched if its first numeric fields match the given string.
For example, the pattern
.Sq 131.155.
matches the address of (almost) every host on the Eind\%hoven University
network (131.155.x.x).
.It
A string that begins with an
.Sq @
character is treated as a 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.
.It
An expression of the form
.Sq n.n.n.n/m.m.m.m
is interpreted as a
.Sq net/mask
pair.
A host address is matched if
.Sq net
is equal to the bitwise AND of the address and the
.Sq mask .
For example, the net/mask
pattern
.Sq 131.155.72.0/255.255.254.0
matches every address in the range
.Sq 131.155.72.0
through
.Sq 131.155.73.255 .
Note that the
.Sq m.m.m.m
portion must always be specified.
.It
An expression of the form
.Sq ipv6-addr/ipv6-mask
is interpreted as a masked IPv6 address match,
just like a masked IPv4 address match (see above).
Note that the
.Sq ipv6-mask
portion must always be specified.
.It
An expression of the form
.Sq ipv6-addr/prefixlen
is interpreted as a masked IPv6 address match
(with mask specified by numeric prefixlen),
just like a masked IPv4 address match (see above).
Note that the
.Sq prefixlen
portion must always be specified.
.El
.Sh WILDCARDS
The access control language supports explicit wildcards:
.Bl -tag -width XXXXXXX
.It ALL
The universal wildcard, always matches.
.It LOCAL
Matches any host whose name does not contain a dot character.
.It 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.
.It 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.
.\" .IP PARANOID
.\" Matches any host whose name does not match its address.
.\" When tcpd is built with -DPARANOID (default mode), it drops requests
.\" from such clients even before looking at the access control tables.
.\" Build without -DPARANOID when you want more control over such requests.
.El
.Sh OPERATORS
.Ss EXCEPT
Intended use is of the form:
.Sq list_1 EXCEPT list_2 ;
this construct matches anything that matches
.Ar list_1
unless it matches
.Ar 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,
.Sq a EXCEPT b EXCEPT c
would parse as
.Sq (a EXCEPT (b EXCEPT c)) .
.Sh SHELL COMMANDS
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
.Pa /bin/sh
child process with standard
input, output and error connected to
.Pa /dev/null .
Specify an
.Sq &
at the end of the command if you do not want to wait until it has completed.
.Pp
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.
.Pp
The
.Xr hosts_options 5
document describes an alternative language
that uses the shell command field in a different and incompatible way.
.Sh % EXPANSIONS
The following expansions are available within shell commands:
.Bl -tag -width XXXXXXX
.It "%a (%A)"
The client (server) host address.
.It %c
Client information: user@host, user@address, a host name, or just an
address, depending on how much information is available.
.It %d
The daemon process name
.Pf ( Va argv[0]
value).
.It "%h (%H)"
The client (server) host name or address, if the host name is
unavailable.
.It "%n (%N)"
The client (server) host name (or "unknown" or "paranoid").
.It %p
The daemon process ID.
.It %s
Server information: daemon@host, daemon@address, or just a daemon name,
depending on how much information is available.
.It %u
The client user name (or "unknown").
.It %%
Expands to a single
.Sq %
character.
.El
.Pp
Characters in % expansions that may confuse the shell are replaced by
underscores.
.Sh SERVER ENDPOINT PATTERNS
In order to distinguish clients by the network address that they
connect to, use patterns of the form:
.Pp
.Dl process_name@host_pattern\ \&: client_list ...
.Pp
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
.Sq twist
option in the
.Xr hosts_options 5
document.
Many systems 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.
.Pp
The host_pattern obeys the same syntax rules as host names and
addresses in client_list context.
Usually, server endpoint information
is available only with connection-oriented services.
.Sh CLIENT USERNAME LOOKUP
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:
.Pp
.Dl daemon_list\ \&: ... user_pattern@host_pattern ...
.Pp
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
.Ar daemon_list
and the
.Ar host_pattern
match.
.Pp
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.
.Bl -bullet -width XXX
.It
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.
.It
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".
.\" .It
.\" 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.
.It
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.
.El
.Pp
Selective username lookups can alleviate the last problem.
For example, a rule like:
.Pp
.Dl daemon_list\ \&: @pcnetgroup ALL@ALL
.Pp
would match members of the pc netgroup without doing username lookups,
but would perform username lookups with all other systems.
.Sh DETECTING ADDRESS SPOOFING ATTACKS
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 (RFC 931 etc.\&)
service can be used to detect such and other host address spoofing attacks.
.Pp
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
.Sq UNKNOWN@host )
is strong evidence of a host spoofing attack.
.Pp
A positive IDENT lookup result (the client matches
.Sq 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.
.Pp
Note: IDENT lookups don't work with UDP services.
.Sh EXAMPLES
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.
.Pp
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.
.Pp
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.
.Sh MOSTLY CLOSED
In this case, access is denied by default.
Only explicitly authorized hosts are permitted access.
.Pp
The default policy (no access) is implemented with a trivial deny
file:
.Pp
.Pa /etc/hosts.deny :
.Pp
.Dl ALL: ALL
.Pp
This denies all services to all hosts, unless they are permitted access
by entries in the allow file.
.Pp
The explicitly authorized hosts are listed in the allow file.
For example:
.Pp
.Pa /etc/hosts.allow :
.Bd -literal -offset indent
ALL: LOCAL @some_netgroup
ALL: .foobar.edu EXCEPT terminalserver.foobar.edu
.Ed
.Pp
The first rule permits access from hosts in the local domain (no
.Sq \&.
in the host name) and from members of the
.Ar some_netgroup
netgroup.
The second rule permits access from all hosts in the
.Ar foobar.edu
domain (notice the leading dot), with the exception of
.Ar terminalserver.foobar.edu .
.Sh MOSTLY OPEN
Here, access is granted by default; only explicitly specified hosts are
refused service.
.Pp
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:
.Pp
.Pa /etc/hosts.deny :
.Bd -unfilled -offset indent
ALL: some.host.name, .some.domain
ALL EXCEPT in.fingerd: other.host.name, .other.domain
.Ed
.Pp
The first rule denies some hosts and domains all services; the second
rule still permits finger requests from other hosts and domains.
.Sh 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 offending host.
The result is mailed to the superuser.
.Pp
.Pa /etc/hosts.allow :
.Pp
.Dl tftpd: LOCAL, .my.domain
.Pp
.Pa /etc/hosts.deny :
.Bd -unfilled -offset indent
tftpd: ALL: (/some/where/safe_finger -l @%h | \e
/usr/bin/mail -s %d-%h root) &
.Ed
.Pp
The
.Nm 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.
.Pp
The expansion of the %h (client host) and %d (service name) sequences
is described in the section on shell commands.
.Pp
Warning: do not booby-trap your finger daemon, unless you are prepared
for infinite finger loops.
.Pp
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.
.Sh FILES
.Bl -tag -width /etc/hosts.allow -compact
.It Pa /etc/hosts.allow
Access control table (allow list)
.It Pa /etc/hosts.deny
Access control table (deny list)
.El
.Sh DIAGNOSTICS
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.
.Sh SEE ALSO
.Xr tcpd 8 ,
.Xr tcpdchk 8 ,
.Xr tcpdmatch 8
.Sh AUTHORS
.Bd -unfilled -offset indent
Wietse Venema (wietse@wzv.win.tue.nl)
Department of Mathematics and Computing Science
Eindhoven University of Technology
Den Dolech 2, P.O. Box 513,
5600 MB Eindhoven, The Netherlands
.Ed
.Sh BUGS
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.
.Pp
Domain name server lookups are case insensitive; YP
netgroup lookups are case sensitive.
.Pp
The total length of an entry can be no more than 2047 characters long,
including the final newline.
.\" @(#) hosts_access.5 1.20 95/01/30 19:51:46
|