]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/man/man7/security.7
This commit was generated by cvs2svn to compensate for changes in r147173,
[FreeBSD/FreeBSD.git] / share / man / man7 / security.7
1 .\" Copyright (C) 1998 Matthew Dillon. All rights reserved.
2 .\"
3 .\" Redistribution and use in source and binary forms, with or without
4 .\" modification, are permitted provided that the following conditions
5 .\" are met:
6 .\" 1. Redistributions of source code must retain the above copyright
7 .\"    notice, this list of conditions and the following disclaimer.
8 .\" 2. Redistributions in binary form must reproduce the above copyright
9 .\"    notice, this list of conditions and the following disclaimer in the
10 .\"    documentation and/or other materials provided with the distribution.
11 .\"
12 .\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 .\" ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
16 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22 .\" SUCH DAMAGE.
23 .\"
24 .\" $FreeBSD$
25 .\"
26 .Dd November 29, 2004
27 .Dt SECURITY 7
28 .Os
29 .Sh NAME
30 .Nm security
31 .Nd introduction to security under
32 .Fx
33 .Sh DESCRIPTION
34 Security is a function that begins and ends with the system administrator.
35 While all
36 .Bx
37 multi-user systems have some inherent security, the job of building and
38 maintaining additional security mechanisms to keep users
39 .Dq honest
40 is probably
41 one of the single largest undertakings of the sysadmin.
42 Machines are
43 only as secure as you make them, and security concerns are ever competing
44 with the human necessity for convenience.
45 .Ux
46 systems,
47 in general, are capable of running a huge number of simultaneous processes
48 and many of these processes operate as servers \(em meaning that external
49 entities can connect and talk to them.
50 As yesterday's mini-computers and mainframes
51 become today's desktops, and as computers become networked and internetworked,
52 security becomes an ever bigger issue.
53 .Pp
54 Security is best implemented through a layered onion approach.
55 In a nutshell,
56 what you want to do is to create as many layers of security as are convenient
57 and then carefully monitor the system for intrusions.
58 You do not want to
59 overbuild your security or you will interfere with the detection side, and
60 detection is one of the single most important aspects of any security
61 mechanism.
62 For example, it makes little sense to set the
63 .Cm schg
64 flags
65 (see
66 .Xr chflags 1 )
67 on every system binary because while this may temporarily protect the
68 binaries, it prevents an attacker who has broken in from making an
69 easily detectable change that may result in your security mechanisms not
70 detecting the attacker at all.
71 .Pp
72 System security also pertains to dealing with various forms of attacks,
73 including attacks that attempt to crash or otherwise make a system unusable
74 but do not attempt to break root.
75 Security concerns can be split up into
76 several categories:
77 .Bl -enum -offset indent
78 .It
79 Denial of Service attacks (DoS)
80 .It
81 User account compromises
82 .It
83 Root compromise through accessible servers
84 .It
85 Root compromise via user accounts
86 .It
87 Backdoor creation
88 .El
89 .Pp
90 A denial of service attack is an action that deprives the machine of needed
91 resources.
92 Typically, DoS attacks are brute-force mechanisms that attempt
93 to crash or otherwise make a machine unusable by overwhelming its servers or
94 network stack.
95 Some DoS attacks try to take advantages of bugs in the
96 networking stack to crash a machine with a single packet.
97 The latter can
98 only be fixed by applying a bug fix to the kernel.
99 Attacks on servers can
100 often be fixed by properly specifying options to limit the load the servers
101 incur on the system under adverse conditions.
102 Brute-force network attacks are harder to deal with.
103 A spoofed-packet attack, for example, is
104 nearly impossible to stop short of cutting your system off from the Internet.
105 It may not be able to take your machine down, but it can fill up Internet
106 pipe.
107 .Pp
108 A user account compromise is even more common than a DoS attack.
109 Many
110 sysadmins still run standard
111 .Xr telnetd 8 ,
112 .Xr rlogind 8 ,
113 .Xr rshd 8 ,
114 and
115 .Xr ftpd 8
116 servers on their machines.
117 These servers, by default, do not operate over encrypted
118 connections.
119 The result is that if you have any moderate-sized user base,
120 one or more of your users logging into your system from a remote location
121 (which is the most common and convenient way to log in to a system)
122 will have his or her password sniffed.
123 The attentive system administrator will analyze
124 his remote access logs looking for suspicious source addresses
125 even for successful logins.
126 .Pp
127 One must always assume that once an attacker has access to a user account,
128 the attacker can break root.
129 However, the reality is that in a well secured
130 and maintained system, access to a user account does not necessarily give the
131 attacker access to root.
132 The distinction is important because without access
133 to root the attacker cannot generally hide his tracks and may, at best, be
134 able to do nothing more than mess with the user's files or crash the machine.
135 User account compromises are very common because users tend not to take the
136 precautions that sysadmins take.
137 .Pp
138 System administrators must keep in mind that there are potentially many ways
139 to break root on a machine.
140 The attacker may know the root password,
141 the attacker
142 may find a bug in a root-run server and be able to break root over a network
143 connection to that server, or the attacker may know of a bug in an SUID-root
144 program that allows the attacker to break root once he has broken into a
145 user's account.
146 If an attacker has found a way to break root on a machine,
147 the attacker may not have a need to install a backdoor.
148 Many of the root holes found and closed to date involve a considerable amount
149 of work by the attacker to clean up after himself, so most attackers do install
150 backdoors.
151 This gives you a convenient way to detect the attacker.
152 Making
153 it impossible for an attacker to install a backdoor may actually be detrimental
154 to your security because it will not close off the hole the attacker used to
155 break in in the first place.
156 .Pp
157 Security remedies should always be implemented with a multi-layered
158 .Dq onion peel
159 approach and can be categorized as follows:
160 .Bl -enum -offset indent
161 .It
162 Securing root and staff accounts
163 .It
164 Securing root \(em root-run servers and SUID/SGID binaries
165 .It
166 Securing user accounts
167 .It
168 Securing the password file
169 .It
170 Securing the kernel core, raw devices, and file systems
171 .It
172 Quick detection of inappropriate changes made to the system
173 .It
174 Paranoia
175 .El
176 .Sh SECURING THE ROOT ACCOUNT AND SECURING STAFF ACCOUNTS
177 Do not bother securing staff accounts if you have not secured the root
178 account.
179 Most systems have a password assigned to the root account.
180 The
181 first thing you do is assume that the password is
182 .Em always
183 compromised.
184 This does not mean that you should remove the password.
185 The
186 password is almost always necessary for console access to the machine.
187 What it does mean is that you should not make it possible to use the password
188 outside of the console or possibly even with a
189 .Xr su 1
190 utility.
191 For example, make sure that your PTYs are specified as being
192 .Dq Li unsecure
193 in the
194 .Pa /etc/ttys
195 file
196 so that direct root logins via
197 .Xr telnet 1
198 or
199 .Xr rlogin 1
200 are disallowed.
201 If using
202 other login services such as
203 .Xr sshd 8 ,
204 make sure that direct root logins are
205 disabled there as well.
206 Consider every access method \(em services such as
207 .Xr ftp 1
208 often fall through the cracks.
209 Direct root logins should only be allowed
210 via the system console.
211 .Pp
212 Of course, as a sysadmin you have to be able to get to root, so we open up
213 a few holes.
214 But we make sure these holes require additional password
215 verification to operate.
216 One way to make root accessible is to add appropriate
217 staff accounts to the
218 .Dq Li wheel
219 group (in
220 .Pa /etc/group ) .
221 The staff members placed in the
222 .Li wheel
223 group are allowed to
224 .Xr su 1
225 to root.
226 You should never give staff
227 members native
228 .Li wheel
229 access by putting them in the
230 .Li wheel
231 group in their password entry.
232 Staff accounts should be placed in a
233 .Dq Li staff
234 group, and then added to the
235 .Li wheel
236 group via the
237 .Pa /etc/group
238 file.
239 Only those staff members who actually need to have root access
240 should be placed in the
241 .Li wheel
242 group.
243 It is also possible, when using an
244 authentication method such as Kerberos, to use Kerberos's
245 .Pa .k5login
246 file in the root account to allow a
247 .Xr ksu 1
248 to root without having to place anyone at all in the
249 .Li wheel
250 group.
251 This
252 may be the better solution since the
253 .Li wheel
254 mechanism still allows an
255 intruder to break root if the intruder has gotten hold of your password
256 file and can break into a staff account.
257 While having the
258 .Li wheel
259 mechanism
260 is better than having nothing at all, it is not necessarily the safest
261 option.
262 .Pp
263 An indirect way to secure the root account is to secure your staff accounts
264 by using an alternative login access method and *'ing out the crypted password
265 for the staff accounts.
266 This way an intruder may be able to steal the password
267 file but will not be able to break into any staff accounts or root, even if
268 root has a crypted password associated with it (assuming, of course, that
269 you have limited root access to the console).
270 Staff members
271 get into their staff accounts through a secure login mechanism such as
272 .Xr kerberos 8
273 or
274 .Xr ssh 1
275 using a private/public
276 key pair.
277 When you use something like Kerberos you generally must secure
278 the machines which run the Kerberos servers and your desktop workstation.
279 When you use a public/private key pair with SSH, you must generally secure
280 the machine you are logging in
281 .Em from
282 (typically your workstation),
283 but you can
284 also add an additional layer of protection to the key pair by password
285 protecting the keypair when you create it with
286 .Xr ssh-keygen 1 .
287 Being able
288 to *-out the passwords for staff accounts also guarantees that staff members
289 can only log in through secure access methods that you have set up.
290 You can
291 thus force all staff members to use secure, encrypted connections for
292 all their sessions which closes an important hole used by many intruders: that
293 of sniffing the network from an unrelated, less secure machine.
294 .Pp
295 The more indirect security mechanisms also assume that you are logging in
296 from a more restrictive server to a less restrictive server.
297 For example,
298 if your main box is running all sorts of servers, your workstation should not
299 be running any.
300 In order for your workstation to be reasonably secure
301 you should run as few servers as possible, up to and including no servers
302 at all, and you should run a password-protected screen blanker.
303 Of course, given physical access to
304 a workstation, an attacker can break any sort of security you put on it.
305 This is definitely a problem that you should consider but you should also
306 consider the fact that the vast majority of break-ins occur remotely, over
307 a network, from people who do not have physical access to your workstation or
308 servers.
309 .Pp
310 Using something like Kerberos also gives you the ability to disable or
311 change the password for a staff account in one place and have it immediately
312 affect all the machines the staff member may have an account on.
313 If a staff
314 member's account gets compromised, the ability to instantly change his
315 password on all machines should not be underrated.
316 With discrete passwords, changing a password on N machines can be a mess.
317 You can also impose
318 re-passwording restrictions with Kerberos: not only can a Kerberos ticket
319 be made to timeout after a while, but the Kerberos system can require that
320 the user choose a new password after a certain period of time
321 (say, once a month).
322 .Sh SECURING ROOT \(em ROOT-RUN SERVERS AND SUID/SGID BINARIES
323 The prudent sysadmin only runs the servers he needs to, no more, no less.
324 Be aware that third party servers are often the most bug-prone.
325 For example,
326 running an old version of
327 .Xr imapd 8
328 or
329 .Xr popper 8
330 is like giving a universal root
331 ticket out to the entire world.
332 Never run a server that you have not checked
333 out carefully.
334 Many servers do not need to be run as root.
335 For example,
336 the
337 .Xr talkd 8 ,
338 .Xr comsat 8 ,
339 and
340 .Xr fingerd 8
341 daemons can be run in special user
342 .Dq sandboxes .
343 A sandbox is not perfect unless you go to a large amount of trouble, but the
344 onion approach to security still stands: if someone is able to break in
345 through a server running in a sandbox, they still have to break out of the
346 sandbox.
347 The more layers the attacker must break through, the lower the
348 likelihood of his success.
349 Root holes have historically been found in
350 virtually every server ever run as root, including basic system servers.
351 If you are running a machine through which people only log in via
352 .Xr sshd 8
353 and never log in via
354 .Xr telnetd 8 ,
355 .Xr rshd 8 ,
356 or
357 .Xr rlogind 8 ,
358 then turn off those services!
359 .Pp
360 .Fx
361 now defaults to running
362 .Xr talkd 8 ,
363 .Xr comsat 8 ,
364 and
365 .Xr fingerd 8
366 in a sandbox.
367 Another program which may be a candidate for running in a sandbox is
368 .Xr named 8 .
369 The default
370 .Pa rc.conf
371 includes the arguments necessary to run
372 .Xr named 8
373 in a sandbox in a commented-out form.
374 Depending on whether you
375 are installing a new system or upgrading an existing system, the special
376 user accounts used by these sandboxes may not be installed.
377 The prudent
378 sysadmin would research and implement sandboxes for servers whenever possible.
379 .Pp
380 There are a number of other servers that typically do not run in sandboxes:
381 .Xr sendmail 8 ,
382 .Xr popper 8 ,
383 .Xr imapd 8 ,
384 .Xr ftpd 8 ,
385 and others.
386 There are alternatives to
387 some of these, but installing them may require more work then you are willing
388 to put
389 (the convenience factor strikes again).
390 You may have to run these
391 servers as root and rely on other mechanisms to detect break-ins that might
392 occur through them.
393 .Pp
394 The other big potential root hole in a system are the SUID-root and SGID
395 binaries installed on the system.
396 Most of these binaries, such as
397 .Xr rlogin 1 ,
398 reside in
399 .Pa /bin , /sbin , /usr/bin ,
400 or
401 .Pa /usr/sbin .
402 While nothing is 100% safe,
403 the system-default SUID and SGID binaries can be considered reasonably safe.
404 Still, root holes are occasionally found in these binaries.
405 A root hole
406 was found in Xlib in 1998 that made
407 .Xr xterm 1
408 (which is typically SUID)
409 vulnerable.
410 It is better to be safe than sorry and the prudent sysadmin will restrict SUID
411 binaries that only staff should run to a special group that only staff can
412 access, and get rid of
413 .Pq Dq Li "chmod 000"
414 any SUID binaries that nobody uses.
415 A server with no display generally does not need an
416 .Xr xterm 1
417 binary.
418 SGID binaries can be almost as dangerous.
419 If an intruder can break an SGID-kmem binary the
420 intruder might be able to read
421 .Pa /dev/kmem
422 and thus read the crypted password
423 file, potentially compromising any passworded account.
424 Alternatively an
425 intruder who breaks group
426 .Dq Li kmem
427 can monitor keystrokes sent through PTYs,
428 including PTYs used by users who log in through secure methods.
429 An intruder
430 that breaks the
431 .Dq Li tty
432 group can write to almost any user's TTY.
433 If a user
434 is running a terminal
435 program or emulator with a keyboard-simulation feature, the intruder can
436 potentially
437 generate a data stream that causes the user's terminal to echo a command, which
438 is then run as that user.
439 .Sh SECURING USER ACCOUNTS
440 User accounts are usually the most difficult to secure.
441 While you can impose
442 draconian access restrictions on your staff and *-out their passwords, you
443 may not be able to do so with any general user accounts you might have.
444 If
445 you do have sufficient control then you may win out and be able to secure the
446 user accounts properly.
447 If not, you simply have to be more vigilant in your
448 monitoring of those accounts.
449 Use of SSH and Kerberos for user accounts is
450 more problematic due to the extra administration and technical support
451 required, but still a very good solution compared to a crypted password
452 file.
453 .Sh SECURING THE PASSWORD FILE
454 The only sure fire way is to *-out as many passwords as you can and
455 use SSH or Kerberos for access to those accounts.
456 Even though the
457 crypted password file
458 .Pq Pa /etc/spwd.db
459 can only be read by root, it may
460 be possible for an intruder to obtain read access to that file even if the
461 attacker cannot obtain root-write access.
462 .Pp
463 Your security scripts should always check for and report changes to
464 the password file
465 (see
466 .Sx CHECKING FILE INTEGRITY
467 below).
468 .Sh SECURING THE KERNEL CORE, RAW DEVICES, AND FILE SYSTEMS
469 If an attacker breaks root he can do just about anything, but there
470 are certain conveniences.
471 For example, most modern kernels have a packet sniffing device driver built in.
472 Under
473 .Fx
474 it is called
475 the
476 .Xr bpf 4
477 device.
478 An intruder will commonly attempt to run a packet sniffer
479 on a compromised machine.
480 You do not need to give the intruder the
481 capability and most systems should not have the
482 .Xr bpf 4
483 device compiled in.
484 .Pp
485 But even if you turn off the
486 .Xr bpf 4
487 device, you still have
488 .Pa /dev/mem
489 and
490 .Pa /dev/kmem
491 to worry about.
492 For that matter,
493 the intruder can still write to raw disk devices.
494 Also, there is another kernel feature called the module loader,
495 .Xr kldload 8 .
496 An enterprising intruder can use a KLD module to install
497 his own
498 .Xr bpf 4
499 device or other sniffing device on a running kernel.
500 To avoid these problems you have to run
501 the kernel at a higher secure level, at least securelevel 1.
502 The securelevel can be set with a
503 .Xr sysctl 8
504 on the
505 .Va kern.securelevel
506 variable.
507 Once you have
508 set the securelevel to 1, write access to raw devices will be denied and
509 special
510 .Xr chflags 1
511 flags, such as
512 .Cm schg ,
513 will be enforced.
514 You must also ensure
515 that the
516 .Cm schg
517 flag is set on critical startup binaries, directories, and
518 script files \(em everything that gets run up to the point where the securelevel
519 is set.
520 This might be overdoing it, and upgrading the system is much more
521 difficult when you operate at a higher secure level.
522 You may compromise and
523 run the system at a higher secure level but not set the
524 .Cm schg
525 flag for every
526 system file and directory under the sun.
527 Another possibility is to simply
528 mount
529 .Pa /
530 and
531 .Pa /usr
532 read-only.
533 It should be noted that being too draconian in
534 what you attempt to protect may prevent the all-important detection of an
535 intrusion.
536 .Sh CHECKING FILE INTEGRITY: BINARIES, CONFIG FILES, ETC
537 When it comes right down to it, you can only protect your core system
538 configuration and control files so much before the convenience factor
539 rears its ugly head.
540 For example, using
541 .Xr chflags 1
542 to set the
543 .Cm schg
544 bit on most of the files in
545 .Pa /
546 and
547 .Pa /usr
548 is probably counterproductive because
549 while it may protect the files, it also closes a detection window.
550 The
551 last layer of your security onion is perhaps the most important \(em detection.
552 The rest of your security is pretty much useless (or, worse, presents you with
553 a false sense of safety) if you cannot detect potential incursions.
554 Half
555 the job of the onion is to slow down the attacker rather than stop him
556 in order to give the detection layer a chance to catch him in
557 the act.
558 .Pp
559 The best way to detect an incursion is to look for modified, missing, or
560 unexpected files.
561 The best
562 way to look for modified files is from another (often centralized)
563 limited-access system.
564 Writing your security scripts on the extra-secure limited-access system
565 makes them mostly invisible to potential attackers, and this is important.
566 In order to take maximum advantage you generally have to give the
567 limited-access box significant access to the other machines in the business,
568 usually either by doing a read-only NFS export of the other machines to the
569 limited-access box, or by setting up SSH keypairs to allow the limit-access
570 box to SSH to the other machines.
571 Except for its network traffic, NFS is
572 the least visible method \(em allowing you to monitor the file systems on each
573 client box virtually undetected.
574 If your
575 limited-access server is connected to the client boxes through a switch,
576 the NFS method is often the better choice.
577 If your limited-access server
578 is connected to the client boxes through a hub or through several layers
579 of routing, the NFS method may be too insecure (network-wise) and using SSH
580 may be the better choice even with the audit-trail tracks that SSH lays.
581 .Pp
582 Once you give a limit-access box at least read access to the client systems
583 it is supposed to monitor, you must write scripts to do the actual
584 monitoring.
585 Given an NFS mount, you can write scripts out of simple system
586 utilities such as
587 .Xr find 1
588 and
589 .Xr md5 1 .
590 It is best to physically
591 .Xr md5 1
592 the client-box files boxes at least once a
593 day, and to test control files such as those found in
594 .Pa /etc
595 and
596 .Pa /usr/local/etc
597 even more often.
598 When mismatches are found relative to the base MD5
599 information the limited-access machine knows is valid, it should scream at
600 a sysadmin to go check it out.
601 A good security script will also check for
602 inappropriate SUID binaries and for new or deleted files on system partitions
603 such as
604 .Pa /
605 and
606 .Pa /usr .
607 .Pp
608 When using SSH rather than NFS, writing the security script is much more
609 difficult.
610 You essentially have to
611 .Xr scp 1
612 the scripts to the client box in order to run them, making them visible, and
613 for safety you also need to
614 .Xr scp 1
615 the binaries (such as
616 .Xr find 1 )
617 that those scripts use.
618 The
619 .Xr sshd 8
620 daemon on the client box may already be compromised.
621 All in all,
622 using SSH may be necessary when running over unsecure links, but it is also a
623 lot harder to deal with.
624 .Pp
625 A good security script will also check for changes to user and staff members
626 access configuration files:
627 .Pa .rhosts , .shosts , .ssh/authorized_keys
628 and so forth, files that might fall outside the purview of the MD5 check.
629 .Pp
630 If you have a huge amount of user disk space it may take too long to run
631 through every file on those partitions.
632 In this case, setting mount
633 flags to disallow SUID binaries on those partitions is a good
634 idea.
635 The
636 .Cm nosuid
637 option
638 (see
639 .Xr mount 8 )
640 is what you want to look into.
641 I would scan them anyway at least once a
642 week, since the object of this layer is to detect a break-in whether or
643 not the break-in is effective.
644 .Pp
645 Process accounting
646 (see
647 .Xr accton 8 )
648 is a relatively low-overhead feature of
649 the operating system which I recommend using as a post-break-in evaluation
650 mechanism.
651 It is especially useful in tracking down how an intruder has
652 actually broken into a system, assuming the file is still intact after
653 the break-in occurs.
654 .Pp
655 Finally, security scripts should process the log files and the logs themselves
656 should be generated in as secure a manner as possible \(em remote syslog can be
657 very useful.
658 An intruder tries to cover his tracks, and log files are critical
659 to the sysadmin trying to track down the time and method of the initial
660 break-in.
661 One way to keep a permanent record of the log files is to run
662 the system console to a serial port and collect the information on a
663 continuing basis through a secure machine monitoring the consoles.
664 .Sh PARANOIA
665 A little paranoia never hurts.
666 As a rule, a sysadmin can add any number
667 of security features as long as they do not affect convenience, and
668 can add security features that do affect convenience with some added
669 thought.
670 Even more importantly, a security administrator should mix it up
671 a bit \(em if you use recommendations such as those given by this manual
672 page verbatim, you give away your methodologies to the prospective
673 attacker who also has access to this manual page.
674 .Sh SPECIAL SECTION ON DoS ATTACKS
675 This section covers Denial of Service attacks.
676 A DoS attack is typically a packet attack.
677 While there is not much you can do about modern spoofed
678 packet attacks that saturate your network, you can generally limit the damage
679 by ensuring that the attacks cannot take down your servers.
680 .Bl -enum -offset indent
681 .It
682 Limiting server forks
683 .It
684 Limiting springboard attacks (ICMP response attacks, ping broadcast, etc.)
685 .It
686 Kernel Route Cache
687 .El
688 .Pp
689 A common DoS attack is against a forking server that attempts to cause the
690 server to eat processes, file descriptors, and memory until the machine
691 dies.
692 The
693 .Xr inetd 8
694 server
695 has several options to limit this sort of attack.
696 It should be noted that while it is possible to prevent a machine from going
697 down it is not generally possible to prevent a service from being disrupted
698 by the attack.
699 Read the
700 .Xr inetd 8
701 manual page carefully and pay specific attention
702 to the
703 .Fl c , C ,
704 and
705 .Fl R
706 options.
707 Note that spoofed-IP attacks will circumvent
708 the
709 .Fl C
710 option to
711 .Xr inetd 8 ,
712 so typically a combination of options must be used.
713 Some standalone servers have self-fork-limitation parameters.
714 .Pp
715 The
716 .Xr sendmail 8
717 daemon has its
718 .Fl OMaxDaemonChildren
719 option which tends to work much
720 better than trying to use
721 .Xr sendmail 8 Ns 's
722 load limiting options due to the
723 load lag.
724 You should specify a
725 .Va MaxDaemonChildren
726 parameter when you start
727 .Xr sendmail 8
728 high enough to handle your expected load but not so high that the
729 computer cannot handle that number of
730 .Nm sendmail Ns 's
731 without falling on its face.
732 It is also prudent to run
733 .Xr sendmail 8
734 in
735 .Dq queued
736 mode
737 .Pq Fl ODeliveryMode=queued
738 and to run the daemon
739 .Pq Dq Nm sendmail Fl bd
740 separate from the queue-runs
741 .Pq Dq Nm sendmail Fl q15m .
742 If you still want real-time delivery you can run the queue
743 at a much lower interval, such as
744 .Fl q1m ,
745 but be sure to specify a reasonable
746 .Va MaxDaemonChildren
747 option for that
748 .Xr sendmail 8
749 to prevent cascade failures.
750 .Pp
751 The
752 .Xr syslogd 8
753 daemon can be attacked directly and it is strongly recommended that you use
754 the
755 .Fl s
756 option whenever possible, and the
757 .Fl a
758 option otherwise.
759 .Pp
760 You should also be fairly careful
761 with connect-back services such as tcpwrapper's reverse-identd, which can
762 be attacked directly.
763 You generally do not want to use the reverse-ident
764 feature of tcpwrappers for this reason.
765 .Pp
766 It is a very good idea to protect internal services from external access
767 by firewalling them off at your border routers.
768 The idea here is to prevent
769 saturation attacks from outside your LAN, not so much to protect internal
770 services from network-based root compromise.
771 Always configure an exclusive
772 firewall, i.e.,
773 .So
774 firewall everything
775 .Em except
776 ports A, B, C, D, and M-Z
777 .Sc .
778 This
779 way you can firewall off all of your low ports except for certain specific
780 services such as
781 .Xr named 8
782 (if you are primary for a zone),
783 .Xr talkd 8 ,
784 .Xr sendmail 8 ,
785 and other internet-accessible services.
786 If you try to configure the firewall the other
787 way \(em as an inclusive or permissive firewall, there is a good chance that you
788 will forget to
789 .Dq close
790 a couple of services or that you will add a new internal
791 service and forget to update the firewall.
792 You can still open up the
793 high-numbered port range on the firewall to allow permissive-like operation
794 without compromising your low ports.
795 Also take note that
796 .Fx
797 allows you to
798 control the range of port numbers used for dynamic binding via the various
799 .Va net.inet.ip.portrange
800 sysctl's
801 .Pq Dq Li "sysctl net.inet.ip.portrange" ,
802 which can also
803 ease the complexity of your firewall's configuration.
804 I usually use a normal
805 first/last range of 4000 to 5000, and a hiport range of 49152 to 65535, then
806 block everything under 4000 off in my firewall
807 (except for certain specific
808 internet-accessible ports, of course).
809 .Pp
810 Another common DoS attack is called a springboard attack \(em to attack a server
811 in a manner that causes the server to generate responses which then overload
812 the server, the local network, or some other machine.
813 The most common attack
814 of this nature is the ICMP PING BROADCAST attack.
815 The attacker spoofs ping
816 packets sent to your LAN's broadcast address with the source IP address set
817 to the actual machine they wish to attack.
818 If your border routers are not
819 configured to stomp on ping's to broadcast addresses, your LAN winds up
820 generating sufficient responses to the spoofed source address to saturate the
821 victim, especially when the attacker uses the same trick on several dozen
822 broadcast addresses over several dozen different networks at once.
823 Broadcast attacks of over a hundred and twenty megabits have been measured.
824 A second common springboard attack is against the ICMP error reporting system.
825 By
826 constructing packets that generate ICMP error responses, an attacker can
827 saturate a server's incoming network and cause the server to saturate its
828 outgoing network with ICMP responses.
829 This type of attack can also crash the
830 server by running it out of
831 .Vt mbuf Ns 's ,
832 especially if the server cannot drain the
833 ICMP responses it generates fast enough.
834 The
835 .Fx
836 kernel has a new kernel
837 compile option called
838 .Dv ICMP_BANDLIM
839 which limits the effectiveness of these
840 sorts of attacks.
841 The last major class of springboard attacks is related to
842 certain internal
843 .Xr inetd 8
844 services such as the UDP echo service.
845 An attacker
846 simply spoofs a UDP packet with the source address being server A's echo port,
847 and the destination address being server B's echo port, where server A and B
848 are both on your LAN.
849 The two servers then bounce this one packet back and
850 forth between each other.
851 The attacker can overload both servers and their
852 LANs simply by injecting a few packets in this manner.
853 Similar problems
854 exist with the internal chargen port.
855 A competent sysadmin will turn off all
856 of these
857 .Xr inetd 8 Ns -internal
858 test services.
859 .Pp
860 Spoofed packet attacks may also be used to overload the kernel route cache.
861 Refer to the
862 .Va net.inet.ip.rtexpire , net.inet.ip.rtminexpire ,
863 and
864 .Va net.inet.ip.rtmaxcache
865 .Xr sysctl 8
866 variables.
867 A spoofed packet attack that uses a random source IP will cause
868 the kernel to generate a temporary cached route in the route table, viewable
869 with
870 .Dq Li "netstat -rna | fgrep W3" .
871 These routes typically timeout in 1600
872 seconds or so.
873 If the kernel detects that the cached route table has gotten
874 too big it will dynamically reduce the
875 .Va rtexpire
876 but will never decrease it to
877 less than
878 .Va rtminexpire .
879 There are two problems: (1) The kernel does not react
880 quickly enough when a lightly loaded server is suddenly attacked, and (2) The
881 .Va rtminexpire
882 is not low enough for the kernel to survive a sustained attack.
883 If your servers are connected to the internet via a T3 or better it may be
884 prudent to manually override both
885 .Va rtexpire
886 and
887 .Va rtminexpire
888 via
889 .Xr sysctl 8 .
890 Never set either parameter to zero
891 (unless you want to crash the machine :-)).
892 Setting both parameters to 2 seconds should be sufficient to protect the route
893 table from attack.
894 .Sh ACCESS ISSUES WITH KERBEROS AND SSH
895 There are a few issues with both Kerberos and SSH that need to be addressed
896 if you intend to use them.
897 Kerberos5 is an excellent authentication
898 protocol but the kerberized
899 .Xr telnet 1
900 and
901 .Xr rlogin 1
902 suck rocks.
903 There are bugs that make them unsuitable for dealing with binary streams.
904 Also, by default
905 Kerberos does not encrypt a session unless you use the
906 .Fl x
907 option.
908 SSH encrypts everything by default.
909 .Pp
910 SSH works quite well in every respect except when it is set up to
911 forward encryption keys.
912 What this means is that if you have a secure workstation holding
913 keys that give you access to the rest of the system, and you
914 .Xr ssh 1
915 to an
916 unsecure machine, your keys become exposed.
917 The actual keys themselves are
918 not exposed, but
919 .Xr ssh 1
920 installs a forwarding port for the duration of your
921 login and if an attacker has broken root on the unsecure machine he can utilize
922 that port to use your keys to gain access to any other machine that your
923 keys unlock.
924 .Pp
925 We recommend that you use SSH in combination with Kerberos whenever possible
926 for staff logins.
927 SSH can be compiled with Kerberos support.
928 This reduces
929 your reliance on potentially exposable SSH keys while at the same time
930 protecting passwords via Kerberos.
931 SSH keys
932 should only be used for automated tasks from secure machines (something
933 that Kerberos is unsuited to).
934 We also recommend that you either turn off
935 key-forwarding in the SSH configuration, or that you make use of the
936 .Va from Ns = Ns Ar IP/DOMAIN
937 option that SSH allows in its
938 .Pa authorized_keys
939 file to make the key only usable to entities logging in from specific
940 machines.
941 .Sh SEE ALSO
942 .Xr chflags 1 ,
943 .Xr find 1 ,
944 .Xr md5 1 ,
945 .Xr netstat 1 ,
946 .Xr openssl 1 ,
947 .Xr ssh 1 ,
948 .Xr xdm 1 ,
949 .Xr group 5 ,
950 .Xr ttys 5 ,
951 .Xr accton 8 ,
952 .Xr init 8 ,
953 .Xr sshd 8 ,
954 .Xr sysctl 8 ,
955 .Xr syslogd 8 ,
956 .Xr vipw 8
957 .Sh HISTORY
958 The
959 .Nm
960 manual page was originally written by
961 .An Matthew Dillon
962 and first appeared
963 in
964 .Fx 3.1 ,
965 December 1998.