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