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