xref: /freebsd/share/man/man7/security.7 (revision f05cddf9)
1.\" Copyright (C) 1998 Matthew Dillon. All rights reserved.
2.\"
3.\" Redistribution and use in source and binary forms, with or without
4.\" modification, are permitted provided that the following conditions
5.\" are met:
6.\" 1. Redistributions of source code must retain the above copyright
7.\"    notice, this list of conditions and the following disclaimer.
8.\" 2. Redistributions in binary form must reproduce the above copyright
9.\"    notice, this list of conditions and the following disclaimer in the
10.\"    documentation and/or other materials provided with the distribution.
11.\"
12.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15.\" ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
16.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22.\" SUCH DAMAGE.
23.\"
24.\" $FreeBSD$
25.\"
26.Dd February 8, 2012
27.Dt SECURITY 7
28.Os
29.Sh NAME
30.Nm security
31.Nd introduction to security under FreeBSD
32.Sh DESCRIPTION
33Security is a function that begins and ends with the system administrator.
34While all
35.Bx
36multi-user systems have some inherent security, the job of building and
37maintaining additional security mechanisms to keep users
38.Dq honest
39is probably
40one of the single largest undertakings of the sysadmin.
41Machines are
42only as secure as you make them, and security concerns are ever competing
43with the human necessity for convenience.
44.Ux
45systems,
46in general, are capable of running a huge number of simultaneous processes
47and many of these processes operate as servers \(em meaning that external
48entities can connect and talk to them.
49As yesterday's mini-computers and mainframes
50become today's desktops, and as computers become networked and internetworked,
51security becomes an ever bigger issue.
52.Pp
53Security is best implemented through a layered onion approach.
54In a nutshell,
55what you want to do is to create as many layers of security as are convenient
56and then carefully monitor the system for intrusions.
57.Pp
58System security also pertains to dealing with various forms of attacks,
59including attacks that attempt to crash or otherwise make a system unusable
60but do not attempt to break root.
61Security concerns can be split up into
62several categories:
63.Bl -enum -offset indent
64.It
65Denial of Service attacks (DoS)
66.It
67User account compromises
68.It
69Root compromise through accessible servers
70.It
71Root compromise via user accounts
72.It
73Backdoor creation
74.El
75.Pp
76A denial of service attack is an action that deprives the machine of needed
77resources.
78Typically, DoS attacks are brute-force mechanisms that attempt
79to crash or otherwise make a machine unusable by overwhelming its servers or
80network stack.
81Some DoS attacks try to take advantages of bugs in the
82networking stack to crash a machine with a single packet.
83The latter can
84only be fixed by applying a bug fix to the kernel.
85Attacks on servers can
86often be fixed by properly specifying options to limit the load the servers
87incur on the system under adverse conditions.
88Brute-force network attacks are harder to deal with.
89A spoofed-packet attack, for example, is
90nearly impossible to stop short of cutting your system off from the Internet.
91It may not be able to take your machine down, but it can fill up your Internet
92pipe.
93.Pp
94A user account compromise is even more common than a DoS attack.
95Many
96sysadmins still run standard
97.Xr telnetd 8 ,
98.Xr rlogind 8 ,
99.Xr rshd 8 ,
100and
101.Xr ftpd 8
102servers on their machines.
103These servers, by default, do not operate over encrypted
104connections.
105The result is that if you have any moderate-sized user base,
106one or more of your users logging into your system from a remote location
107(which is the most common and convenient way to log in to a system)
108will have his or her password sniffed.
109The attentive system administrator will analyze
110his remote access logs looking for suspicious source addresses
111even for successful logins.
112.Pp
113One must always assume that once an attacker has access to a user account,
114the attacker can break root.
115However, the reality is that in a well secured
116and maintained system, access to a user account does not necessarily give the
117attacker access to root.
118The distinction is important because without access
119to root the attacker cannot generally hide his tracks and may, at best, be
120able to do nothing more than mess with the user's files or crash the machine.
121User account compromises are very common because users tend not to take the
122precautions that sysadmins take.
123.Pp
124System administrators must keep in mind that there are potentially many ways
125to break root on a machine.
126The attacker may know the root password,
127the attacker
128may find a bug in a root-run server and be able to break root over a network
129connection to that server, or the attacker may know of a bug in an SUID-root
130program that allows the attacker to break root once he has broken into a
131user's account.
132If an attacker has found a way to break root on a machine,
133the attacker may not have a need to install a backdoor.
134Many of the root holes found and closed to date involve a considerable amount
135of work by the attacker to clean up after himself, so most attackers do install
136backdoors.
137This gives you a convenient way to detect the attacker.
138Making
139it impossible for an attacker to install a backdoor may actually be detrimental
140to your security because it will not close off the hole the attacker used to
141break in originally.
142.Pp
143Security remedies should always be implemented with a multi-layered
144.Dq onion peel
145approach and can be categorized as follows:
146.Bl -enum -offset indent
147.It
148Securing root and staff accounts
149.It
150Securing root \(em root-run servers and SUID/SGID binaries
151.It
152Securing user accounts
153.It
154Securing the password file
155.It
156Securing the kernel core, raw devices, and file systems
157.It
158Quick detection of inappropriate changes made to the system
159.It
160Paranoia
161.El
162.Sh SECURING THE ROOT ACCOUNT AND SECURING STAFF ACCOUNTS
163Do not bother securing staff accounts if you have not secured the root
164account.
165Most systems have a password assigned to the root account.
166The
167first thing you do is assume that the password is
168.Em always
169compromised.
170This does not mean that you should remove the password.
171The
172password is almost always necessary for console access to the machine.
173What it does mean is that you should not make it possible to use the password
174outside of the console or possibly even with a
175.Xr su 1
176utility.
177For example, make sure that your PTYs are specified as being
178.Dq Li insecure
179in the
180.Pa /etc/ttys
181file
182so that direct root logins via
183.Xr telnet 1
184or
185.Xr rlogin 1
186are disallowed.
187If using
188other login services such as
189.Xr sshd 8 ,
190make sure that direct root logins are
191disabled there as well.
192Consider every access method \(em services such as
193.Xr ftp 1
194often fall through the cracks.
195Direct root logins should only be allowed
196via the system console.
197.Pp
198Of course, as a sysadmin you have to be able to get to root, so we open up
199a few holes.
200But we make sure these holes require additional password
201verification to operate.
202One way to make root accessible is to add appropriate
203staff accounts to the
204.Dq Li wheel
205group (in
206.Pa /etc/group ) .
207The staff members placed in the
208.Li wheel
209group are allowed to
210.Xr su 1
211to root.
212You should never give staff
213members native
214.Li wheel
215access by putting them in the
216.Li wheel
217group in their password entry.
218Staff accounts should be placed in a
219.Dq Li staff
220group, and then added to the
221.Li wheel
222group via the
223.Pa /etc/group
224file.
225Only those staff members who actually need to have root access
226should be placed in the
227.Li wheel
228group.
229It is also possible, when using an
230authentication method such as Kerberos, to use Kerberos's
231.Pa .k5login
232file in the root account to allow a
233.Xr ksu 1
234to root without having to place anyone at all in the
235.Li wheel
236group.
237This
238may be the better solution since the
239.Li wheel
240mechanism still allows an
241intruder to break root if the intruder has gotten hold of your password
242file and can break into a staff account.
243While having the
244.Li wheel
245mechanism
246is better than having nothing at all, it is not necessarily the safest
247option.
248.Pp
249An indirect way to secure the root account is to secure your staff accounts
250by using an alternative login access method and *'ing out the crypted password
251for the staff accounts.
252This way an intruder may be able to steal the password
253file but will not be able to break into any staff accounts or root, even if
254root has a crypted password associated with it (assuming, of course, that
255you have limited root access to the console).
256Staff members
257get into their staff accounts through a secure login mechanism such as
258.Xr kerberos 8
259or
260.Xr ssh 1
261using a private/public
262key pair.
263When you use something like Kerberos you generally must secure
264the machines which run the Kerberos servers and your desktop workstation.
265When you use a public/private key pair with SSH, you must generally secure
266the machine you are logging in
267.Em from
268(typically your workstation),
269but you can
270also add an additional layer of protection to the key pair by password
271protecting the keypair when you create it with
272.Xr ssh-keygen 1 .
273Being able
274to *-out the passwords for staff accounts also guarantees that staff members
275can only log in through secure access methods that you have set up.
276You can
277thus force all staff members to use secure, encrypted connections for
278all their sessions which closes an important hole used by many intruders: that
279of sniffing the network from an unrelated, less secure machine.
280.Pp
281The more indirect security mechanisms also assume that you are logging in
282from a more restrictive server to a less restrictive server.
283For example,
284if your main box is running all sorts of servers, your workstation should not
285be running any.
286In order for your workstation to be reasonably secure
287you should run as few servers as possible, up to and including no servers
288at all, and you should run a password-protected screen blanker.
289Of course, given physical access to
290a workstation, an attacker can break any sort of security you put on it.
291This is definitely a problem that you should consider but you should also
292consider the fact that the vast majority of break-ins occur remotely, over
293a network, from people who do not have physical access to your workstation or
294servers.
295.Pp
296Using something like Kerberos also gives you the ability to disable or
297change the password for a staff account in one place and have it immediately
298affect all the machines the staff member may have an account on.
299If a staff
300member's account gets compromised, the ability to instantly change his
301password on all machines should not be underrated.
302With discrete passwords, changing a password on N machines can be a mess.
303You can also impose
304re-passwording restrictions with Kerberos: not only can a Kerberos ticket
305be made to timeout after a while, but the Kerberos system can require that
306the user choose a new password after a certain period of time
307(say, once a month).
308.Sh SECURING ROOT \(em ROOT-RUN SERVERS AND SUID/SGID BINARIES
309The prudent sysadmin only runs the servers he needs to, no more, no less.
310Be aware that third party servers are often the most bug-prone.
311For example,
312running an old version of
313.Xr imapd 8
314or
315.Xr popper 8 Pq Pa ports/mail/popper
316is like giving a universal root
317ticket out to the entire world.
318Never run a server that you have not checked
319out carefully.
320Many servers do not need to be run as root.
321For example,
322the
323.Xr talkd 8 ,
324.Xr comsat 8 ,
325and
326.Xr fingerd 8
327daemons can be run in special user
328.Dq sandboxes .
329A sandbox is not perfect unless you go to a large amount of trouble, but the
330onion approach to security still stands: if someone is able to break in
331through a server running in a sandbox, they still have to break out of the
332sandbox.
333The more layers the attacker must break through, the lower the
334likelihood of his success.
335Root holes have historically been found in
336virtually every server ever run as root, including basic system servers.
337If you are running a machine through which people only log in via
338.Xr sshd 8
339and never log in via
340.Xr telnetd 8 ,
341.Xr rshd 8 ,
342or
343.Xr rlogind 8 ,
344then turn off those services!
345.Pp
346.Fx
347now defaults to running
348.Xr talkd 8 ,
349.Xr comsat 8 ,
350and
351.Xr fingerd 8
352in a sandbox.
353Another program which may be a candidate for running in a sandbox is
354.Xr named 8 .
355The default
356.Pa rc.conf
357includes the arguments necessary to run
358.Xr named 8
359in a sandbox in a commented-out form.
360Depending on whether you
361are installing a new system or upgrading an existing system, the special
362user accounts used by these sandboxes may not be installed.
363The prudent
364sysadmin would research and implement sandboxes for servers whenever possible.
365.Pp
366There are a number of other servers that typically do not run in sandboxes:
367.Xr sendmail 8 ,
368.Xr popper 8 ,
369.Xr imapd 8 ,
370.Xr ftpd 8 ,
371and others.
372There are alternatives to
373some of these, but installing them may require more work than you are willing
374to put
375(the convenience factor strikes again).
376You may have to run these
377servers as root and rely on other mechanisms to detect break-ins that might
378occur through them.
379.Pp
380The other big potential root hole in a system are the SUID-root and SGID
381binaries installed on the system.
382Most of these binaries, such as
383.Xr rlogin 1 ,
384reside in
385.Pa /bin , /sbin , /usr/bin ,
386or
387.Pa /usr/sbin .
388While nothing is 100% safe,
389the system-default SUID and SGID binaries can be considered reasonably safe.
390Still, root holes are occasionally found in these binaries.
391A root hole
392was found in Xlib in 1998 that made
393.Xr xterm 1 Pq Pa ports/x11/xterm
394(which is typically SUID)
395vulnerable.
396It is better to be safe than sorry and the prudent sysadmin will restrict SUID
397binaries that only staff should run to a special group that only staff can
398access, and get rid of
399.Pq Dq Li "chmod 000"
400any SUID binaries that nobody uses.
401A server with no display generally does not need an
402.Xr xterm 1
403binary.
404SGID binaries can be almost as dangerous.
405If an intruder can break an SGID-kmem binary the
406intruder might be able to read
407.Pa /dev/kmem
408and thus read the crypted password
409file, potentially compromising any passworded account.
410Alternatively an
411intruder who breaks group
412.Dq Li kmem
413can monitor keystrokes sent through PTYs,
414including PTYs used by users who log in through secure methods.
415An intruder
416that breaks the
417.Dq Li tty
418group can write to almost any user's TTY.
419If a user
420is running a terminal
421program or emulator with a keyboard-simulation feature, the intruder can
422potentially
423generate a data stream that causes the user's terminal to echo a command, which
424is then run as that user.
425.Sh SECURING USER ACCOUNTS
426User accounts are usually the most difficult to secure.
427While you can impose
428draconian access restrictions on your staff and *-out their passwords, you
429may not be able to do so with any general user accounts you might have.
430If
431you do have sufficient control then you may win out and be able to secure the
432user accounts properly.
433If not, you simply have to be more vigilant in your
434monitoring of those accounts.
435Use of SSH and Kerberos for user accounts is
436more problematic due to the extra administration and technical support
437required, but still a very good solution compared to a crypted password
438file.
439.Sh SECURING THE PASSWORD FILE
440The only sure fire way is to *-out as many passwords as you can and
441use SSH or Kerberos for access to those accounts.
442Even though the
443crypted password file
444.Pq Pa /etc/spwd.db
445can only be read by root, it may
446be possible for an intruder to obtain read access to that file even if the
447attacker cannot obtain root-write access.
448.Pp
449Your security scripts should always check for and report changes to
450the password file
451(see
452.Sx CHECKING FILE INTEGRITY
453below).
454.Sh SECURING THE KERNEL CORE, RAW DEVICES, AND FILE SYSTEMS
455If an attacker breaks root he can do just about anything, but there
456are certain conveniences.
457For example, most modern kernels have a packet sniffing device driver built in.
458Under
459.Fx
460it is called
461the
462.Xr bpf 4
463device.
464An intruder will commonly attempt to run a packet sniffer
465on a compromised machine.
466You do not need to give the intruder the
467capability and most systems should not have the
468.Xr bpf 4
469device compiled in.
470.Pp
471But even if you turn off the
472.Xr bpf 4
473device, you still have
474.Pa /dev/mem
475and
476.Pa /dev/kmem
477to worry about.
478For that matter,
479the intruder can still write to raw disk devices.
480Also, there is another kernel feature called the module loader,
481.Xr kldload 8 .
482An enterprising intruder can use a KLD module to install
483his own
484.Xr bpf 4
485device or other sniffing device on a running kernel.
486To avoid these problems you have to run
487the kernel at a higher security level, at least level 1.
488The security level can be set with a
489.Xr sysctl 8
490on the
491.Va kern.securelevel
492variable.
493Once you have
494set the security level to 1, write access to raw devices will be denied and
495special
496.Xr chflags 1
497flags, such as
498.Cm schg ,
499will be enforced.
500You must also ensure
501that the
502.Cm schg
503flag is set on critical startup binaries, directories, and
504script files \(em everything that gets run
505up to the point where the security level is set.
506This might be overdoing it, and upgrading the system is much more
507difficult when you operate at a higher security level.
508You may compromise and
509run the system at a higher security level but not set the
510.Cm schg
511flag for every
512system file and directory under the sun.
513Another possibility is to simply
514mount
515.Pa /
516and
517.Pa /usr
518read-only.
519It should be noted that being too draconian in
520what you attempt to protect may prevent the all-important detection of an
521intrusion.
522.Pp
523The kernel runs with five different security levels.
524Any super-user process can raise the level, but no process
525can lower it.
526The security levels are:
527.Bl -tag -width flag
528.It Ic -1
529Permanently insecure mode \- always run the system in insecure mode.
530This is the default initial value.
531.It Ic 0
532Insecure mode \- immutable and append-only flags may be turned off.
533All devices may be read or written subject to their permissions.
534.It Ic 1
535Secure mode \- the system immutable and system append-only flags may not
536be turned off;
537disks for mounted file systems,
538.Pa /dev/mem
539and
540.Pa /dev/kmem
541may not be opened for writing;
542.Pa /dev/io
543(if your platform has it) may not be opened at all;
544kernel modules (see
545.Xr kld 4 )
546may not be loaded or unloaded.
547The kernel debugger may not be entered using the
548.Va debug.kdb.enter
549sysctl.
550A panic or trap cannot be forced using the
551.Va debug.kdb.panic
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 named 8
829(if you are primary for a zone),
830.Xr talkd 8 ,
831.Xr sendmail 8 ,
832and other internet-accessible services.
833If you try to configure the firewall the other
834way \(em as an inclusive or permissive firewall, there is a good chance that you
835will forget to
836.Dq close
837a couple of services or that you will add a new internal
838service and forget to update the firewall.
839You can still open up the
840high-numbered port range on the firewall to allow permissive-like operation
841without compromising your low ports.
842Also take note that
843.Fx
844allows you to
845control the range of port numbers used for dynamic binding via the various
846.Va net.inet.ip.portrange
847sysctl's
848.Pq Dq Li "sysctl net.inet.ip.portrange" ,
849which can also
850ease the complexity of your firewall's configuration.
851I usually use a normal
852first/last range of 4000 to 5000, and a hiport range of 49152 to 65535, then
853block everything under 4000 off in my firewall
854(except for certain specific
855internet-accessible ports, of course).
856.Pp
857Another common DoS attack is called a springboard attack \(em to attack a server
858in a manner that causes the server to generate responses which then overload
859the server, the local network, or some other machine.
860The most common attack
861of this nature is the ICMP PING BROADCAST attack.
862The attacker spoofs ping
863packets sent to your LAN's broadcast address with the source IP address set
864to the actual machine they wish to attack.
865If your border routers are not
866configured to stomp on ping's to broadcast addresses, your LAN winds up
867generating sufficient responses to the spoofed source address to saturate the
868victim, especially when the attacker uses the same trick on several dozen
869broadcast addresses over several dozen different networks at once.
870Broadcast attacks of over a hundred and twenty megabits have been measured.
871A second common springboard attack is against the ICMP error reporting system.
872By
873constructing packets that generate ICMP error responses, an attacker can
874saturate a server's incoming network and cause the server to saturate its
875outgoing network with ICMP responses.
876This type of attack can also crash the
877server by running it out of
878.Vt mbuf Ns 's ,
879especially if the server cannot drain the
880ICMP responses it generates fast enough.
881The
882.Fx
883kernel has a new kernel
884compile option called
885.Dv ICMP_BANDLIM
886which limits the effectiveness of these
887sorts of attacks.
888The last major class of springboard attacks is related to
889certain internal
890.Xr inetd 8
891services such as the UDP echo service.
892An attacker
893simply spoofs a UDP packet with the source address being server A's echo port,
894and the destination address being server B's echo port, where server A and B
895are both on your LAN.
896The two servers then bounce this one packet back and
897forth between each other.
898The attacker can overload both servers and their
899LANs simply by injecting a few packets in this manner.
900Similar problems
901exist with the internal chargen port.
902A competent sysadmin will turn off all
903of these
904.Xr inetd 8 Ns -internal
905test services.
906.Pp
907Spoofed packet attacks may also be used to overload the kernel route cache.
908Refer to the
909.Va net.inet.ip.rtexpire , net.inet.ip.rtminexpire ,
910and
911.Va net.inet.ip.rtmaxcache
912.Xr sysctl 8
913variables.
914A spoofed packet attack that uses a random source IP will cause
915the kernel to generate a temporary cached route in the route table, viewable
916with
917.Dq Li "netstat -rna | fgrep W3" .
918These routes typically timeout in 1600
919seconds or so.
920If the kernel detects that the cached route table has gotten
921too big it will dynamically reduce the
922.Va rtexpire
923but will never decrease it to
924less than
925.Va rtminexpire .
926There are two problems: (1) The kernel does not react
927quickly enough when a lightly loaded server is suddenly attacked, and (2) The
928.Va rtminexpire
929is not low enough for the kernel to survive a sustained attack.
930If your servers are connected to the internet via a T3 or better it may be
931prudent to manually override both
932.Va rtexpire
933and
934.Va rtminexpire
935via
936.Xr sysctl 8 .
937Never set either parameter to zero
938(unless you want to crash the machine :-)).
939Setting both parameters to 2 seconds should be sufficient to protect the route
940table from attack.
941.Sh ACCESS ISSUES WITH KERBEROS AND SSH
942There are a few issues with both Kerberos and SSH that need to be addressed
943if you intend to use them.
944Kerberos5 is an excellent authentication
945protocol but the kerberized
946.Xr telnet 1
947and
948.Xr rlogin 1
949suck rocks.
950There are bugs that make them unsuitable for dealing with binary streams.
951Also, by default
952Kerberos does not encrypt a session unless you use the
953.Fl x
954option.
955SSH encrypts everything by default.
956.Pp
957SSH works quite well in every respect except when it is set up to
958forward encryption keys.
959What this means is that if you have a secure workstation holding
960keys that give you access to the rest of the system, and you
961.Xr ssh 1
962to an
963unsecure machine, your keys become exposed.
964The actual keys themselves are
965not exposed, but
966.Xr ssh 1
967installs a forwarding port for the duration of your
968login and if an attacker has broken root on the unsecure machine he can utilize
969that port to use your keys to gain access to any other machine that your
970keys unlock.
971.Pp
972We recommend that you use SSH in combination with Kerberos whenever possible
973for staff logins.
974SSH can be compiled with Kerberos support.
975This reduces
976your reliance on potentially exposable SSH keys while at the same time
977protecting passwords via Kerberos.
978SSH keys
979should only be used for automated tasks from secure machines (something
980that Kerberos is unsuited to).
981We also recommend that you either turn off
982key-forwarding in the SSH configuration, or that you make use of the
983.Va from Ns = Ns Ar IP/DOMAIN
984option that SSH allows in its
985.Pa authorized_keys
986file to make the key only usable to entities logging in from specific
987machines.
988.Sh SEE ALSO
989.Xr chflags 1 ,
990.Xr find 1 ,
991.Xr md5 1 ,
992.Xr netstat 1 ,
993.Xr openssl 1 ,
994.Xr ssh 1 ,
995.Xr xdm 1 Pq Pa ports/x11/xorg-clients ,
996.Xr group 5 ,
997.Xr ttys 5 ,
998.Xr accton 8 ,
999.Xr init 8 ,
1000.Xr sshd 8 ,
1001.Xr sysctl 8 ,
1002.Xr syslogd 8 ,
1003.Xr vipw 8
1004.Sh HISTORY
1005The
1006.Nm
1007manual page was originally written by
1008.An Matthew Dillon
1009and first appeared
1010in
1011.Fx 3.1 ,
1012December 1998.
1013