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