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