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