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