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