xref: /freebsd/share/man/man7/security.7 (revision 8ddb146abcdf061be9f2c0db7e391697dafad85c)
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 January 14, 2022
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 Pq Pa ports/x11/xterm
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 ,
543.Va debug.kdb.panic_str
544and other sysctl's.
545.It Ic 2
546Highly secure mode \- same as secure mode, plus disks may not be
547opened for writing (except by
548.Xr mount 2 )
549whether mounted or not.
550This level precludes tampering with file systems by unmounting them,
551but also inhibits running
552.Xr newfs 8
553while the system is multi-user.
554.Pp
555In addition, kernel time changes are restricted to less than or equal to one
556second.
557Attempts to change the time by more than this will log the message
558.Dq Time adjustment clamped to +1 second .
559.It Ic 3
560Network secure mode \- same as highly secure mode, plus
561IP packet filter rules (see
562.Xr ipfw 8 ,
563.Xr ipfirewall 4
564and
565.Xr pfctl 8 )
566cannot be changed and
567.Xr dummynet 4
568or
569.Xr pf 4
570configuration cannot be adjusted.
571.El
572.Pp
573The security level can be configured with variables documented in
574.Xr rc.conf 5 .
575.Sh CHECKING FILE INTEGRITY: BINARIES, CONFIG FILES, ETC
576When it comes right down to it, you can only protect your core system
577configuration and control files so much before the convenience factor
578rears its ugly head.
579For example, using
580.Xr chflags 1
581to set the
582.Cm schg
583bit on most of the files in
584.Pa /
585and
586.Pa /usr
587is probably counterproductive because
588while it may protect the files, it also closes a detection window.
589The
590last layer of your security onion is perhaps the most important \(em detection.
591The rest of your security is pretty much useless (or, worse, presents you with
592a false sense of safety) if you cannot detect potential incursions.
593Half
594the job of the onion is to slow down the attacker rather than stop him
595in order to give the detection layer a chance to catch him in
596the act.
597.Pp
598The best way to detect an incursion is to look for modified, missing, or
599unexpected files.
600The best
601way to look for modified files is from another (often centralized)
602limited-access system.
603Writing your security scripts on the extra-secure limited-access system
604makes them mostly invisible to potential attackers, and this is important.
605In order to take maximum advantage you generally have to give the
606limited-access box significant access to the other machines in the business,
607usually either by doing a read-only NFS export of the other machines to the
608limited-access box, or by setting up SSH keypairs to allow the limit-access
609box to SSH to the other machines.
610Except for its network traffic, NFS is
611the least visible method \(em allowing you to monitor the file systems on each
612client box virtually undetected.
613If your
614limited-access server is connected to the client boxes through a switch,
615the NFS method is often the better choice.
616If your limited-access server
617is connected to the client boxes through a hub or through several layers
618of routing, the NFS method may be too insecure (network-wise) and using SSH
619may be the better choice even with the audit-trail tracks that SSH lays.
620.Pp
621Once you give a limit-access box at least read access to the client systems
622it is supposed to monitor, you must write scripts to do the actual
623monitoring.
624Given an NFS mount, you can write scripts out of simple system
625utilities such as
626.Xr find 1
627and
628.Xr md5 1 .
629It is best to physically
630.Xr md5 1
631the client-box files boxes at least once a
632day, and to test control files such as those found in
633.Pa /etc
634and
635.Pa /usr/local/etc
636even more often.
637When mismatches are found relative to the base MD5
638information the limited-access machine knows is valid, it should scream at
639a sysadmin to go check it out.
640A good security script will also check for
641inappropriate SUID binaries and for new or deleted files on system partitions
642such as
643.Pa /
644and
645.Pa /usr .
646.Pp
647When using SSH rather than NFS, writing the security script is much more
648difficult.
649You essentially have to
650.Xr scp 1
651the scripts to the client box in order to run them, making them visible, and
652for safety you also need to
653.Xr scp 1
654the binaries (such as
655.Xr find 1 )
656that those scripts use.
657The
658.Xr sshd 8
659daemon on the client box may already be compromised.
660All in all,
661using SSH may be necessary when running over unsecure links, but it is also a
662lot harder to deal with.
663.Pp
664A good security script will also check for changes to user and staff members
665access configuration files:
666.Pa .rhosts , .shosts , .ssh/authorized_keys
667and so forth, files that might fall outside the purview of the MD5 check.
668.Pp
669If you have a huge amount of user disk space it may take too long to run
670through every file on those partitions.
671In this case, setting mount
672flags to disallow SUID binaries on those partitions is a good
673idea.
674The
675.Cm nosuid
676option
677(see
678.Xr mount 8 )
679is what you want to look into.
680I would scan them anyway at least once a
681week, since the object of this layer is to detect a break-in whether or
682not the break-in is effective.
683.Pp
684Process accounting
685(see
686.Xr accton 8 )
687is a relatively low-overhead feature of
688the operating system which I recommend using as a post-break-in evaluation
689mechanism.
690It is especially useful in tracking down how an intruder has
691actually broken into a system, assuming the file is still intact after
692the break-in occurs.
693.Pp
694Finally, security scripts should process the log files and the logs themselves
695should be generated in as secure a manner as possible \(em remote syslog can be
696very useful.
697An intruder tries to cover his tracks, and log files are critical
698to the sysadmin trying to track down the time and method of the initial
699break-in.
700One way to keep a permanent record of the log files is to run
701the system console to a serial port and collect the information on a
702continuing basis through a secure machine monitoring the consoles.
703.Sh PARANOIA
704A little paranoia never hurts.
705As a rule, a sysadmin can add any number
706of security features as long as they do not affect convenience, and
707can add security features that do affect convenience with some added
708thought.
709Even more importantly, a security administrator should mix it up
710a bit \(em if you use recommendations such as those given by this manual
711page verbatim, you give away your methodologies to the prospective
712attacker who also has access to this manual page.
713.Sh SPECIAL SECTION ON DoS ATTACKS
714This section covers Denial of Service attacks.
715A DoS attack is typically a packet attack.
716While there is not much you can do about modern spoofed
717packet attacks that saturate your network, you can generally limit the damage
718by ensuring that the attacks cannot take down your servers.
719.Bl -enum -offset indent
720.It
721Limiting server forks
722.It
723Limiting springboard attacks (ICMP response attacks, ping broadcast, etc.)
724.It
725Kernel Route Cache
726.El
727.Pp
728A common DoS attack is against a forking server that attempts to cause the
729server to eat processes, file descriptors, and memory until the machine
730dies.
731The
732.Xr inetd 8
733server
734has several options to limit this sort of attack.
735It should be noted that while it is possible to prevent a machine from going
736down it is not generally possible to prevent a service from being disrupted
737by the attack.
738Read the
739.Xr inetd 8
740manual page carefully and pay specific attention
741to the
742.Fl c , C ,
743and
744.Fl R
745options.
746Note that spoofed-IP attacks will circumvent
747the
748.Fl C
749option to
750.Xr inetd 8 ,
751so typically a combination of options must be used.
752Some standalone servers have self-fork-limitation parameters.
753.Pp
754The
755.Xr sendmail 8
756daemon has its
757.Fl OMaxDaemonChildren
758option which tends to work much
759better than trying to use
760.Xr sendmail 8 Ns 's
761load limiting options due to the
762load lag.
763You should specify a
764.Va MaxDaemonChildren
765parameter when you start
766.Xr sendmail 8
767high enough to handle your expected load but not so high that the
768computer cannot handle that number of
769.Nm sendmail Ns 's
770without falling on its face.
771It is also prudent to run
772.Xr sendmail 8
773in
774.Dq queued
775mode
776.Pq Fl ODeliveryMode=queued
777and to run the daemon
778.Pq Dq Nm sendmail Fl bd
779separate from the queue-runs
780.Pq Dq Nm sendmail Fl q15m .
781If you still want real-time delivery you can run the queue
782at a much lower interval, such as
783.Fl q1m ,
784but be sure to specify a reasonable
785.Va MaxDaemonChildren
786option for that
787.Xr sendmail 8
788to prevent cascade failures.
789.Pp
790The
791.Xr syslogd 8
792daemon can be attacked directly and it is strongly recommended that you use
793the
794.Fl s
795option whenever possible, and the
796.Fl a
797option otherwise.
798.Pp
799You should also be fairly careful
800with connect-back services such as tcpwrapper's reverse-identd, which can
801be attacked directly.
802You generally do not want to use the reverse-ident
803feature of tcpwrappers for this reason.
804.Pp
805It is a very good idea to protect internal services from external access
806by firewalling them off at your border routers.
807The idea here is to prevent
808saturation attacks from outside your LAN, not so much to protect internal
809services from network-based root compromise.
810Always configure an exclusive
811firewall, i.e.,
812.So
813firewall everything
814.Em except
815ports A, B, C, D, and M-Z
816.Sc .
817This
818way you can firewall off all of your low ports except for certain specific
819services such as
820.Xr talkd 8 ,
821.Xr sendmail 8 ,
822and other internet-accessible services.
823If you try to configure the firewall the other
824way \(em as an inclusive or permissive firewall, there is a good chance that you
825will forget to
826.Dq close
827a couple of services or that you will add a new internal
828service and forget to update the firewall.
829You can still open up the
830high-numbered port range on the firewall to allow permissive-like operation
831without compromising your low ports.
832Also take note that
833.Fx
834allows you to
835control the range of port numbers used for dynamic binding via the various
836.Va net.inet.ip.portrange
837sysctl's
838.Pq Dq Li "sysctl net.inet.ip.portrange" ,
839which can also
840ease the complexity of your firewall's configuration.
841I usually use a normal
842first/last range of 4000 to 5000, and a hiport range of 49152 to 65535, then
843block everything under 4000 off in my firewall
844(except for certain specific
845internet-accessible ports, of course).
846.Pp
847Another common DoS attack is called a springboard attack \(em to attack a server
848in a manner that causes the server to generate responses which then overload
849the server, the local network, or some other machine.
850The most common attack
851of this nature is the ICMP PING BROADCAST attack.
852The attacker spoofs ping
853packets sent to your LAN's broadcast address with the source IP address set
854to the actual machine they wish to attack.
855If your border routers are not
856configured to stomp on ping's to broadcast addresses, your LAN winds up
857generating sufficient responses to the spoofed source address to saturate the
858victim, especially when the attacker uses the same trick on several dozen
859broadcast addresses over several dozen different networks at once.
860Broadcast attacks of over a hundred and twenty megabits have been measured.
861A second common springboard attack is against the ICMP error reporting system.
862By
863constructing packets that generate ICMP error responses, an attacker can
864saturate a server's incoming network and cause the server to saturate its
865outgoing network with ICMP responses.
866This type of attack can also crash the
867server by running it out of
868.Vt mbuf Ns 's ,
869especially if the server cannot drain the
870ICMP responses it generates fast enough.
871The
872.Fx
873kernel has a new kernel
874compile option called
875.Dv ICMP_BANDLIM
876which limits the effectiveness of these
877sorts of attacks.
878The last major class of springboard attacks is related to
879certain internal
880.Xr inetd 8
881services such as the UDP echo service.
882An attacker
883simply spoofs a UDP packet with the source address being server A's echo port,
884and the destination address being server B's echo port, where server A and B
885are both on your LAN.
886The two servers then bounce this one packet back and
887forth between each other.
888The attacker can overload both servers and their
889LANs simply by injecting a few packets in this manner.
890Similar problems
891exist with the internal chargen port.
892A competent sysadmin will turn off all
893of these
894.Xr inetd 8 Ns -internal
895test services.
896.Sh ACCESS ISSUES WITH KERBEROS AND SSH
897There are a few issues with both Kerberos and SSH that need to be addressed
898if you intend to use them.
899Kerberos5 is an excellent authentication
900protocol but the kerberized
901.Xr telnet 1
902suck rocks.
903There are bugs that make them unsuitable for dealing with binary streams.
904Also, by default
905Kerberos does not encrypt a session unless you use the
906.Fl x
907option.
908SSH encrypts everything by default.
909.Pp
910SSH works quite well in every respect except when it is set up to
911forward encryption keys.
912What this means is that if you have a secure workstation holding
913keys that give you access to the rest of the system, and you
914.Xr ssh 1
915to an
916unsecure machine, your keys become exposed.
917The actual keys themselves are
918not exposed, but
919.Xr ssh 1
920installs a forwarding port for the duration of your
921login and if an attacker has broken root on the unsecure machine he can utilize
922that port to use your keys to gain access to any other machine that your
923keys unlock.
924.Pp
925We recommend that you use SSH in combination with Kerberos whenever possible
926for staff logins.
927SSH can be compiled with Kerberos support.
928This reduces
929your reliance on potentially exposable SSH keys while at the same time
930protecting passwords via Kerberos.
931SSH keys
932should only be used for automated tasks from secure machines (something
933that Kerberos is unsuited to).
934We also recommend that you either turn off
935key-forwarding in the SSH configuration, or that you make use of the
936.Va from Ns = Ns Ar IP/DOMAIN
937option that SSH allows in its
938.Pa authorized_keys
939file to make the key only usable to entities logging in from specific
940machines.
941.Sh KNOBS AND TWEAKS
942.Fx
943provides several knobs and tweak handles that make some introspection
944information access more restricted.
945Some people consider this as improving system security, so the knobs are
946briefly listed there, together with controls which enable some mitigations
947of the hardware state leaks.
948.Pp
949Hardware mitigation sysctl knobs described below have been moved under
950.Pa machdep.mitigations ,
951with backwards-compatibility shims to accept the existing names.
952A future change will rationalize the sense of the individual sysctls
953(so that enabled / true always indicates that the mitigation is active).
954For that reason the previous names remain the canonical way to set the
955mitigations, and are documented here.
956Backwards compatibility shims for the interim sysctls under
957.Pa machdep.mitigations
958will not be added.
959.Bl -tag -width security.bsd.unprivileged_proc_debug
960.It Dv security.bsd.see_other_uids
961Controls visibility of processes owned by different uid.
962The knob directly affects the
963.Dv kern.proc
964sysctls filtering of data, which results in restricted output from
965utilities like
966.Xr ps 1 .
967.It Dv security.bsd.see_other_gids
968Same, for processes owned by different gid.
969.It Dv security.bsd.see_jail_proc
970Same, for processes belonging to a jail.
971.It Dv security.bsd.conservative_signals
972When enabled, unprivileged users are only allowed to send job control
973and usual termination signals like
974.Dv SIGKILL ,
975.Dv SIGINT ,
976and
977.Dv SIGTERM ,
978to the processes executing programs with changed uids.
979.It Dv security.bsd.unprivileged_proc_debug
980Controls availability of the process debugging facilities to non-root users.
981See also
982.Xr proccontrol 1
983mode
984.Dv trace .
985.It Dv vm.pmap.pti
986Tunable, amd64-only.
987Enables mode of operation of virtual memory system where usermode page
988tables are sanitized to prevent so-called Meltdown information leak on
989some Intel CPUs.
990By default, the system detects whether the CPU needs the workaround,
991and enables it automatically.
992See also
993.Xr proccontrol 1
994mode
995.Dv kpti .
996.It Dv machdep.mitigations.flush_rsb_ctxsw
997amd64.
998Controls Return Stack Buffer flush on context switch, to prevent
999cross-process ret2spec attacks.
1000Only needed, and only enabled by default, if the machine
1001supports SMEP, otherwise IBRS would do necessary flushing on kernel
1002entry anyway.
1003.It Dv hw.mds_disable
1004amd64 and i386.
1005Controls Microarchitectural Data Sampling hardware information leak
1006mitigation.
1007.It Dv hw.spec_store_bypass_disable
1008amd64 and i386.
1009Controls Speculative Store Bypass hardware information leak mitigation.
1010.It Dv hw.ibrs_disable
1011amd64 and i386.
1012Controls Indirect Branch Restricted Speculation hardware information leak
1013mitigation.
1014.It Dv machdep.syscall_ret_flush_l1d
1015amd64.
1016Controls force-flush of L1D cache on return from syscalls which report
1017errors other than
1018.Ev EEXIST ,
1019.Ev EAGAIN ,
1020.Ev EXDEV ,
1021.Ev ENOENT ,
1022.Ev ENOTCONN ,
1023and
1024.Ev EINPROGRESS .
1025This is mostly a paranoid setting added to prevent hypothetical exploitation
1026of unknown gadgets for unknown hardware issues.
1027The error codes exclusion list is composed of the most common errors which
1028typically occurs on normal system operation.
1029.It Dv machdep.nmi_flush_l1d_sw
1030amd64.
1031Controls force-flush of L1D cache on NMI;
1032this provides software assist for bhyve mitigation of L1 terminal fault
1033hardware information leak.
1034.It Dv hw.vmm.vmx.l1d_flush
1035amd64.
1036Controls the mitigation of L1 Terminal Fault in bhyve hypervisor.
1037.It Dv vm.pmap.allow_2m_x_ept
1038amd64.
1039Allows the use of superpages for executable mappings under the EPT
1040page table format used by hypervisors on Intel CPUs to map the guest
1041physical address space to machine physical memory.
1042May be disabled to work around a CPU Erratum called
1043Machine Check Error Avoidance on Page Size Change.
1044.It Dv machdep.mitigations.rngds.enable
1045amd64 and i386.
1046Controls mitigation of Special Register Buffer Data Sampling versus
1047optimization of the MCU access.
1048When set to zero, the mitigation is disabled, and the RDSEED and RDRAND
1049instructions do not incur serialization overhead for shared buffer accesses,
1050and do not serialize off-core memory accessses.
1051.It Dv kern.elf32.aslr.enable
1052Controls system-global Address Space Layout Randomization (ASLR) for
1053normal non-PIE (Position Independent Executable) 32-bit ELF binaries.
1054See also the
1055.Xr proccontrol 1
1056.Dv aslr
1057mode, also 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) 32-bit 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.stack
1065If ASLR is enabled for a binary, a non-zero value enables randomization
1066of the stack.
1067Otherwise, the stack is mapped at a fixed location determined by the
1068process ABI.
1069.It Dv kern.elf64.aslr.enable
1070ASLR control for 64-bit ELF binaries.
1071.It Dv kern.elf64.aslr.pie_enable
1072ASLR control for 64-bit ELF PIEs.
1073.It Dv kern.elf64.aslr.honor_sbrk
1074ASLR sbrk compatibility control for 64-bit binaries.
1075.It Dv kern.elf64.aslr.stack
1076Controls stack address randomization for 64-bit binaries.
1077.It Dv kern.elf32.nxstack
1078Enables non-executable stack for 32-bit processes.
1079Enabled by default if supported by hardware and corresponding binary.
1080.It Dv kern.elf64.nxstack
1081Enables non-executable stack for 64-bit processes.
1082.It Dv kern.elf32.allow_wx
1083Enables mapping of simultaneously writable and executable pages for
108432-bit processes.
1085.It Dv kern.elf64.allow_wx
1086Enables mapping of simultaneously writable and executable pages for
108764-bit processes.
1088.El
1089.Sh SEE ALSO
1090.Xr chflags 1 ,
1091.Xr find 1 ,
1092.Xr md5 1 ,
1093.Xr netstat 1 ,
1094.Xr openssl 1 ,
1095.Xr proccontrol 1 ,
1096.Xr ps 1 ,
1097.Xr ssh 1 ,
1098.Xr xdm 1 Pq Pa ports/x11/xorg-clients ,
1099.Xr group 5 ,
1100.Xr ttys 5 ,
1101.Xr accton 8 ,
1102.Xr init 8 ,
1103.Xr sshd 8 ,
1104.Xr sysctl 8 ,
1105.Xr syslogd 8 ,
1106.Xr vipw 8
1107.Sh HISTORY
1108The
1109.Nm
1110manual page was originally written by
1111.An Matthew Dillon
1112and first appeared
1113in
1114.Fx 3.1 ,
1115December 1998.
1116