1f063d76aSMatthew Dillon.\" Copyright (c) 1991, 1993 2f063d76aSMatthew Dillon.\" The Regents of the University of California. All rights reserved. 3f063d76aSMatthew Dillon.\" 4f063d76aSMatthew Dillon.\" Redistribution and use in source and binary forms, with or without 5f063d76aSMatthew Dillon.\" modification, are permitted provided that the following conditions 6f063d76aSMatthew Dillon.\" are met: 7f063d76aSMatthew Dillon.\" 1. Redistributions of source code must retain the above copyright 8f063d76aSMatthew Dillon.\" notice, this list of conditions and the following disclaimer. 9f063d76aSMatthew Dillon.\" 2. Redistributions in binary form must reproduce the above copyright 10f063d76aSMatthew Dillon.\" notice, this list of conditions and the following disclaimer in the 11f063d76aSMatthew Dillon.\" documentation and/or other materials provided with the distribution. 12f063d76aSMatthew Dillon.\" 3. All advertising materials mentioning features or use of this software 136ac7e896SDavid E. O'Brien.\" must display the following acknowledgment: 14f063d76aSMatthew Dillon.\" This product includes software developed by the University of 15f063d76aSMatthew Dillon.\" California, Berkeley and its contributors. 16f063d76aSMatthew Dillon.\" 4. Neither the name of the University nor the names of its contributors 17f063d76aSMatthew Dillon.\" may be used to endorse or promote products derived from this software 18f063d76aSMatthew Dillon.\" without specific prior written permission. 19f063d76aSMatthew Dillon.\" 20f063d76aSMatthew Dillon.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21f063d76aSMatthew Dillon.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22f063d76aSMatthew Dillon.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23f063d76aSMatthew Dillon.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24f063d76aSMatthew Dillon.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25f063d76aSMatthew Dillon.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26f063d76aSMatthew Dillon.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27f063d76aSMatthew Dillon.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28f063d76aSMatthew Dillon.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29f063d76aSMatthew Dillon.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30f063d76aSMatthew Dillon.\" SUCH DAMAGE. 31f063d76aSMatthew Dillon.\" 32f063d76aSMatthew Dillon.\" @(#)security.1 8.2 (Berkeley) 12/30/93 336ac7e896SDavid E. O'Brien.\" $Id: security.7,v 1.2 1998/12/22 19:02:51 dillon Exp $ 34f063d76aSMatthew Dillon.\" 35f063d76aSMatthew Dillon.Dd December 30, 1993 36f063d76aSMatthew Dillon.Dt SECURITY 7 37f063d76aSMatthew Dillon.Os 38f063d76aSMatthew Dillon.Sh NAME 39f063d76aSMatthew Dillon.Nm security 40f063d76aSMatthew Dillon.Nd introduction to security under FreeBSD 41f063d76aSMatthew Dillon.Sh DESCRIPTION 42f063d76aSMatthew Dillon.Pp 43f063d76aSMatthew DillonSecurity is a function that begins and ends with the system administrator. 44f063d76aSMatthew DillonWhile all 45f063d76aSMatthew Dillon.Bx 46f063d76aSMatthew Dillonsystems are inherently multi-user capable, the job of building and 47f063d76aSMatthew Dillonmaintaining security mechanisms to keep those users 'honest' is probably 486ac7e896SDavid E. O'Brienone of the single largest undertakings of the sysadmin. Machines are 49f063d76aSMatthew Dillononly as secure as you make them, and security concerns are ever competing 50f063d76aSMatthew Dillonwith the human necessity for convenience. UNIX systems, 516ac7e896SDavid E. O'Brienin general, are capable of running a huge number of simultaneous processes 52f063d76aSMatthew Dillonand many of these processes operate as servers - meaning that external entities 53f063d76aSMatthew Dilloncan connect and talk to them. As yesterday's mini-computers and mainframes 54f063d76aSMatthew Dillonbecome today's desktops, and as computers become networked and internetworked, 55f063d76aSMatthew Dillonsecurity becomes an ever bigger issue. 56f063d76aSMatthew Dillon.Pp 57f063d76aSMatthew DillonSecurity concerns can be split up into several categories: 58f063d76aSMatthew Dillon.Bl -enum -offset indent 59f063d76aSMatthew Dillon.It 60f063d76aSMatthew DillonDenial of service attacks 61f063d76aSMatthew Dillon.It 62f063d76aSMatthew DillonUser account compromises 63f063d76aSMatthew Dillon.It 646ac7e896SDavid E. O'BrienRoot compromise through accessible servers 65f063d76aSMatthew Dillon.It 666ac7e896SDavid E. O'BrienRoot compromise via user accounts 67f063d76aSMatthew Dillon.El 68f063d76aSMatthew Dillon.Pp 69f063d76aSMatthew DillonA denial of service attack is an action that deprives the machine of needed 70f063d76aSMatthew Dillonresources. Typically, D.O.S. attacks are brute-force mechanisms that attempt 71f063d76aSMatthew Dillonto crash or otherwise make a machine unusable by overwhelming its servers or 72f063d76aSMatthew Dillonnetwork stack. Some D.O.S. attacks try to take advantages of bugs in the 73f063d76aSMatthew Dillonnetworking stack to crash a machine with a single packet. The latter can 74f063d76aSMatthew Dillononly be fixed by applying a bug fix to the kernel. Attacks on servers can 75f063d76aSMatthew Dillonoften be fixed by properly specifying options to servers to limit the load 76f063d76aSMatthew Dillonthey incur on the system under adverse conditions. Brute-force network 77f063d76aSMatthew Dillonattacks are harder to deal with. A spoofed-packet attack, for example, is 78f063d76aSMatthew Dillonnearly impossible to stop short of cutting your system off from the internet. 79f063d76aSMatthew Dillon.Pp 80f063d76aSMatthew DillonA user account compromise is even more common then a D.O.S. attack. Many 816ac7e896SDavid E. O'Briensysadmins still run standard telnetd, rlogind, rshd, and ftpd servers on their 82f063d76aSMatthew Dillonmachines. These servers, by default, do not operate over encrypted 83f063d76aSMatthew Dillonconnections. The result is that if you have any moderate-sized user base, 84f063d76aSMatthew Dillonone or more of your users logging into your system from a remote location 85f063d76aSMatthew Dillon(which is the most common and convenient way to login to a system) will 86f063d76aSMatthew Dillonhave his or her password sniffed. The attentive system admin will analyze 876ac7e896SDavid E. O'Brienhis remote access logs occasionally looking for suspicious source addresses 88f063d76aSMatthew Dilloneven for successful logins. 89f063d76aSMatthew Dillon.Pp 90f063d76aSMatthew DillonOne must always assume that once an attacker has access to a user account, 91f063d76aSMatthew Dillonthe attacker can break root. However, the reality is that in a well secured 92f063d76aSMatthew Dillonand maintained system, access to a user account does not necessarily give the 93f063d76aSMatthew Dillonattacker access to root. The distinction is important because without access 94f063d76aSMatthew Dillonto root the attacker cannot generally hide his tracks and may, at best, be 95f063d76aSMatthew Dillonable to remove that user's files and crash the machine, but not touch anyone 96f063d76aSMatthew Dillonelse's files. 97f063d76aSMatthew Dillon.Pp 98f063d76aSMatthew DillonSystem administrators must keep in mind that there are several ways to break 99f063d76aSMatthew Dillonroot on a machine. The attacker may know the root password, the attacker 100f063d76aSMatthew Dillonmay find a bug in a root-run server and be able to break root over a network 101f063d76aSMatthew Dillonconnection to that server, or the attacker may know of a bug in an suid-root 102f063d76aSMatthew Dillonprogram that allows the attacker to break root once he has broken into a 103f063d76aSMatthew Dillonuser's account. 104f063d76aSMatthew Dillon.Pp 105f063d76aSMatthew DillonSecurity remedies are always implemented in a multi-layered 'onion peel' 106f063d76aSMatthew Dillonapproach and can be categorized as follows: 107f063d76aSMatthew Dillon.Bl -enum -offset indent 108f063d76aSMatthew Dillon.It 109f063d76aSMatthew DillonSecuring root and staff accounts 110f063d76aSMatthew Dillon.It 111f063d76aSMatthew DillonSecuring root - root-run servers and suid/sgid binaries 112f063d76aSMatthew Dillon.It 113f063d76aSMatthew DillonSecuring user accounts 114f063d76aSMatthew Dillon.It 115f063d76aSMatthew DillonSecuring the password file 116f063d76aSMatthew Dillon.It 117f063d76aSMatthew DillonSecuring the kernel core, raw devices, and filesystems 118f063d76aSMatthew Dillon.It 1196ac7e896SDavid E. O'BrienChecking file integrity: binaries, configuration files, and so forth 120f063d76aSMatthew Dillon.It 121f063d76aSMatthew DillonParanoia 122f063d76aSMatthew Dillon.El 123f063d76aSMatthew Dillon.Sh SECURING THE ROOT ACCOUNT AND SECURING STAFF ACCOUNTS 124f063d76aSMatthew Dillon.Pp 125f063d76aSMatthew DillonDon't bother securing staff accounts if you haven't secured the root 126f063d76aSMatthew Dillonaccount. Most systems have a password assigned to the root account. The 127f063d76aSMatthew Dillonfirst thing you do is assume that the password is 'always' compromised. 128f063d76aSMatthew DillonTo secure the root account you make sure that it is not possible to login 129f063d76aSMatthew Dillonto the root account using the root password from a random user account or 130f063d76aSMatthew Dillonover the network. If you haven't already, configure telnetd, rlogind, and 131f063d76aSMatthew Dillonall other servers that handle login operations to refuse root logins, period, 132f063d76aSMatthew Dillonwhether the right password is given or not. Allow direct root logins only 133f063d76aSMatthew Dillonvia the system console. The '/etc/ttys' file comes in handy here and is 1347626ae52SMatthew Dillonsecure by default on most systems, but a good sysadmin always checks to make 1357626ae52SMatthew Dillonsure. 136f063d76aSMatthew Dillon.Pp 1377626ae52SMatthew DillonOf course, as a sysadmin you have to be able to get to root, so we open up 138f063d76aSMatthew Dillona few holes. But we make sure these holes require additional password 139f063d76aSMatthew Dillonverification to operate. One way to make root accessible is to add appropriate 140f063d76aSMatthew Dillonstaff accounts to the wheel group (in /etc/group). The staff members placed 141f063d76aSMatthew Dillonin the wheel group are allowed to 'su' to root. You should never give staff 142f063d76aSMatthew Dillonmembers native wheel access via their entry in the password file... put staff 143f063d76aSMatthew Dillonin a 'staff' group or something and only add those that really need root to 1446ac7e896SDavid E. O'Brienthe wheel group. Unfortunately the wheel mechanism still allows an intruder to 1456ac7e896SDavid E. O'Brienbreak root if the intruder has gotten hold of your password file - he need only 146f063d76aSMatthew Dillonbreak the root password and the password of one of the staff accounts that 1476ac7e896SDavid E. O'Brienhappens to be in the wheel group. So while the wheel mechanism is usable, 148f063d76aSMatthew Dillonit isn't much safer then not having a wheel group at all. 149f063d76aSMatthew Dillon.Pp 150f063d76aSMatthew DillonAn indirect way to secure the root account is to secure your staff accounts 151f063d76aSMatthew Dillonby using an alternative login access method and *'ing out the crypted password 1526ac7e896SDavid E. O'Brienfor the staff accounts. This way an intruder may be able to steal the password 153f063d76aSMatthew Dillonfile but will not be able to break into any staff accounts (or, indirectly, 154f063d76aSMatthew Dillonroot, even if root has a crypted password associated with it). Staff members 155f063d76aSMatthew Dillonget into their staff accounts through a secure login mechanism such as 156f063d76aSMatthew Dillonkerberos(1) or ssh(1) (see /usr/ports/security/ssh) using a private/public 157f063d76aSMatthew Dillonkey pair. When you use something like kerberos you generally must secure 158f063d76aSMatthew Dillonthe machines which run the kerberos servers and your desktop workstation. 159f063d76aSMatthew DillonWhen you use a public/private key pair with ssh, you must generally secure 160f063d76aSMatthew Dillonthe machine you are logging in FROM (typically your workstation), but you can 161f063d76aSMatthew Dillonalso add an additional layer of protection to the key pair by password 162f063d76aSMatthew Dillonprotecting the key pair when you create it with ssh-keygen(1). Being able 1636ac7e896SDavid E. O'Briento *-out the passwords for staff accounts also guarantees that staff members 164f063d76aSMatthew Dilloncan only login through secure access methods that you have setup. You can 165f063d76aSMatthew Dillonthus force all staff members to use secure, encrypted connections for 1666ac7e896SDavid E. O'Brienall their sessions which closes an important hole used by many intruders: That 167f063d76aSMatthew Dillonof sniffing the network from an unrelated, less secure machine. 168f063d76aSMatthew Dillon.Pp 169f063d76aSMatthew DillonThe more indirect security mechanisms also assume that you are logging in 170f063d76aSMatthew Dillonfrom a more restrictive server to a less restrictive server. For example, 171f063d76aSMatthew Dillonif your main box is running all sorts of servers, your workstation shouldn't 172f063d76aSMatthew Dillon be running any. In order for your workstation to be reasonably secure 173f063d76aSMatthew Dillonyou should run as few servers as possible, up to and including no servers 174f063d76aSMatthew Dillonat all, and you should run a password-protected screen blanker. 175f063d76aSMatthew Dillon Of course, given physical access to 176f063d76aSMatthew Dillona workstation an attacker can break any sort of security you put on it. 177f063d76aSMatthew DillonThis is definitely a problem that you should consider but you should also 1786ac7e896SDavid E. O'Brienconsider the fact that the vast majority of break-ins occur remotely, over 1797626ae52SMatthew Dillona network, from people who do not have physical access to your workstation or 180f063d76aSMatthew Dillonservers. 181f063d76aSMatthew Dillon.Pp 182f063d76aSMatthew DillonUsing something like kerberos also gives you the ability to disable or 183f063d76aSMatthew Dillonchange the password for a staff account in one place and have it immediately 184f063d76aSMatthew Dilloneffect all the machine the staff member may have an account on. If a staff 185f063d76aSMatthew Dillonmember's account gets compromised, the ability to instantly change his 186f063d76aSMatthew Dillonpassword on all machines should not be underrated. With discrete passwords, 187f063d76aSMatthew Dillonchanging a password on N machines can be a mess. You can also impose 188f063d76aSMatthew Dillonre-passwording restrictions with kerberos: not only can a kerberos ticket 189f063d76aSMatthew Dillonbe made to timeout after a while, but the kerberos system can require that 190f063d76aSMatthew Dillonthe user choose a new password after a certain period of time (say, once a 191f063d76aSMatthew Dillonmonth). 192f063d76aSMatthew Dillon.Sh SECURING ROOT - ROOT-RUN SERVERS AND SUID/SGID BINARIES 193f063d76aSMatthew Dillon.Pp 1947626ae52SMatthew DillonThe prudent sysadmin only runs the servers he needs to, no more, no less. Be 195f063d76aSMatthew Dillonaware that third party servers are often the most bug-prone. For example, 196f063d76aSMatthew Dillonrunning an old version of imapd or popper is like giving a universal root 197f063d76aSMatthew Dillonticket out to the entire world. Never run a server that you have not checked 198f063d76aSMatthew Dillonout carefully. Many servers do not need to be run as root. For example, 199f063d76aSMatthew Dillonthe ntalk, comsat, and finger daemons can be run in special user 'sandboxes'. 2006ac7e896SDavid E. O'BrienA sandbox isn't perfect unless you go to a large amount of trouble, but the 201f063d76aSMatthew Dillononion approach to security still stands: If someone is able to break in 202f063d76aSMatthew Dillonthrough a server running in a sandbox, they still have to break out of the 203f063d76aSMatthew Dillonsandbox. The more layers the attacker must break through, the lower the 204f063d76aSMatthew Dillonlikelihood of his success. Root holes have historically been found in 205f063d76aSMatthew Dillonvirtually every server ever run as root, including basic system servers. 206f063d76aSMatthew DillonIf you are running a machine through which people only login via sshd and 207f063d76aSMatthew Dillonnever login via telnetd or rshd or rlogind, then turn off those services! 208f063d76aSMatthew Dillon.Pp 209f063d76aSMatthew DillonFreeBSD now defaults to running ntalkd, comsat, and finger in a sandbox. 210f063d76aSMatthew DillonAnother program which may be a candidate for running in a sandbox is 211f063d76aSMatthew Dillonnamed(8). The default rc.conf includes the arguments necessary to run 212f063d76aSMatthew Dillonnamed in a sandbox in a commented-out form. Depending on whether you 213f063d76aSMatthew Dillonare installing a new system or upgrading an existing system, the special 214f063d76aSMatthew Dillonuser accounts used by these sandboxes may not be installed. The prudent 2157626ae52SMatthew Dillonsysadmin would research and implement sandboxes for servers whenever possible. 216f063d76aSMatthew Dillon.Pp 217f063d76aSMatthew DillonThere are a number of other servers that typically do not run in sandboxes: 218f063d76aSMatthew Dillonsendmail, popper, imapd, ftpd, and others. There are alternatives to 219f063d76aSMatthew Dillonsome of these, but installing them may require more work then you are willing 220f063d76aSMatthew Dillonto put (the convenience factor strikes again). You may have to run these 2216ac7e896SDavid E. O'Brienservers as root and rely on other mechanisms to detect break-ins that might 222f063d76aSMatthew Dillonoccur through them. 223f063d76aSMatthew Dillon.Pp 224f063d76aSMatthew DillonThe other big potential root hole in a system are the suid-root and sgid 225f063d76aSMatthew Dillonbinaries installed on the system. Most of these binaries, such as rlogin, 226f063d76aSMatthew Dillonreside in /bin, /sbin, /usr/bin, or /usr/sbin. While nothing is 100% safe, 227f063d76aSMatthew Dillonthe system-default suid and sgid binaries can be considered reasonably safe. 2286ac7e896SDavid E. O'BrienStill, root holes are occasionally found in these binaries. A root hole 229f063d76aSMatthew Dillonwas found in Xlib in 1998 that made xterm (which is typically suid) vulnerable. 2307626ae52SMatthew DillonIt is better to be safe then sorry and the prudent sysadmin will restrict suid 231f063d76aSMatthew Dillonbinaries that only staff should run to a special group that only staff can 232f063d76aSMatthew Dillonaccess, and get rid of (chmod 000) any suid binaries that nobody uses. A 233f063d76aSMatthew Dillonserver with no display generally does not need an xterm binary. Sgid binaries 2346ac7e896SDavid E. O'Briencan be almost as dangerous. If an intruder can break an sgid-kmem binary the 2356ac7e896SDavid E. O'Brienintruder might be able to read /dev/kmem and thus read the crypted password 2366ac7e896SDavid E. O'Brienfile, potentially compromising any passworded account. An intruder that breaks 237f063d76aSMatthew Dillonthe tty group can write to almost user's tty. If a user is running a terminal 2386ac7e896SDavid E. O'Brienprogram or emulator with a talk-back feature, the intruder can potentially 239f063d76aSMatthew Dillongenerate a data stream that causes the user's terminal to echo a command, which 240f063d76aSMatthew Dillonis then run as that user. 241f063d76aSMatthew Dillon.Sh SECURING USER ACCOUNTS 242f063d76aSMatthew Dillon.Pp 243f063d76aSMatthew DillonUser accounts are usually the most difficult to secure. While you can impose 2446ac7e896SDavid E. O'BrienDraconian access restrictions on your staff and *-out their passwords, you 245f063d76aSMatthew Dillonmay not be able to do so with any general user accounts you might have. If 246f063d76aSMatthew Dillonyou do have sufficient control then you may win out and be able to secure the 247f063d76aSMatthew Dillonuser accounts properly. If not, you simply have to be more vigilant in your 248f063d76aSMatthew Dillonmonitoring of those accounts. Use of ssh and kerberos for user accounts is 249f063d76aSMatthew Dillonmore problematic, but still a very good solution compared to a crypted 250f063d76aSMatthew Dillonpassword. 251f063d76aSMatthew Dillon.Sh SECURING THE PASSWORD FILE 252f063d76aSMatthew Dillon.Pp 253f063d76aSMatthew DillonThe only sure fire way is to *-out as many passwords as you can and 254f063d76aSMatthew Dillonuse ssh or kerberos for access to those accounts. Even though the 255f063d76aSMatthew Dilloncrypted password file (/etc/spwd.db) can only be read by root, it may 2566ac7e896SDavid E. O'Brienbe possible for a intruder to obtain read access to that file even if the 257f063d76aSMatthew Dillonattacker cannot obtain root-write access. 258f063d76aSMatthew Dillon.Pp 259f063d76aSMatthew DillonYour security scripts should always check for and report changes to 260f063d76aSMatthew Dillonthe password file (see 'Checking file integrity' below). 261f063d76aSMatthew Dillon.Sh SECURING THE KERNEL CORE, RAW DEVICES, AND FILESYSTEMS 262f063d76aSMatthew Dillon.Pp 263f063d76aSMatthew DillonIf an attacker breaks root he can do just about anything, but there 264f063d76aSMatthew Dillonare certain conveniences. For example, most modern kernels have a 265f063d76aSMatthew Dillonpacket sniffing device driver built in. Under FreeBSD it is called 2666ac7e896SDavid E. O'Brienthe 'bpf' device. A intruder will commonly attempt to run a packet sniffer 2676ac7e896SDavid E. O'Brienon a compromised machine. You do not need to give the intruder the 268f063d76aSMatthew Dilloncapability and most systems should not have the bpf device compiled in. 269f063d76aSMatthew DillonUnfortunately, there is another kernel feature called the Loadable Kernel 2706ac7e896SDavid E. O'BrienModule interface. An enterprising intruder can use an LKM to install 271f063d76aSMatthew Dillonhis own bpf device or other sniffing device on a running kernel. If you 2726ac7e896SDavid E. O'Briendo not need to use the module loader, turn it off in the kernel configuration 273f063d76aSMatthew Dillonwith the NO_LKM option. 274f063d76aSMatthew Dillon.Pp 275f063d76aSMatthew DillonBut even if you turn off the bpf device, and turn off the module loader, 276f063d76aSMatthew Dillonyou still have /dev/mem and /dev/kmem to worry about. For that matter, 2776ac7e896SDavid E. O'Brienthe intruder can still write raw devices. To avoid this you have to run 278f063d76aSMatthew Dillonthe kernel at a higher secure level... at least securelevel 1. The securelevel 279f063d76aSMatthew Dilloncan be set with a sysctl on the kern.securelevel variable. Once you have 280f063d76aSMatthew Dillonset the securelevel to 1, write access to raw devices will be denied and 281f063d76aSMatthew Dillonspecial chflags flags, such as 'schg', will be enforced. You must also ensure 282f063d76aSMatthew Dillonthat the 'schg' flag is set on critical startup binaries, directories, and 283f063d76aSMatthew Dillonscript files - everything that gets run up to the point where the securelevel 284f063d76aSMatthew Dillonis set. This might be overdoing it, and upgrading the system is much more 285f063d76aSMatthew Dillondifficult when you operate at a higher secure level. You may compromise and 286f063d76aSMatthew Dillonrun the system at a higher secure level but not set the schg flag for every 287f063d76aSMatthew Dillonsystem file and directory under the sun. 288f063d76aSMatthew Dillon.Sh CHECKING FILE INTEGRITY: BINARIES, CONFIG FILES, ETC 289f063d76aSMatthew Dillon.Pp 290f063d76aSMatthew DillonWhen it comes right down to it, you can only protect your core system 291f063d76aSMatthew Dillonconfiguration and control files so much before the convenience factor 292f063d76aSMatthew Dillonrears its ugly head. The last layer of your security onion is perhaps 293f063d76aSMatthew Dillonthe most important - detection. 294f063d76aSMatthew Dillon.Pp 295f063d76aSMatthew DillonThe only correct way to check a system's file integrity is via another, 296f063d76aSMatthew Dillonmore secure system. It is fairly easy to setup a 'secure' system: you 297f063d76aSMatthew Dillonsimply do not run any services on it. With a secure system in place you 298f063d76aSMatthew Dilloncan then give it access to other system's root spaces via ssh. This may 299f063d76aSMatthew Dillonseem like a security breech, but you have to put your trust somewhere and 300f063d76aSMatthew Dillonas long as you don't do something stupid like run random servers it really 301f063d76aSMatthew Dillonis possible to build a secure machine. When I say 'secure' here, I assuming 302f063d76aSMatthew Dillonphysical access security as well, of course. Given a secure machine with 303f063d76aSMatthew Dillonroot access on all your other machines, you can then write security scripts 304f063d76aSMatthew DillonON the secure machine to check the other machines on the system. The most 305f063d76aSMatthew Dilloncommon way of checking is to have the security script scp(1) over a find 306f063d76aSMatthew Dillonand md5 binary and then ssh a shell command to the remote machine to md5 307f063d76aSMatthew Dillonall the files in the system (or, at least, the /, /var, and /usr partitions!). 308f063d76aSMatthew DillonThe security machine copies the results to a file and diff's them against 309f063d76aSMatthew Dillonresults from a previous run (or compares the results against its own 310f063d76aSMatthew Dillonbinaries), then emails each staff member a daily report of differences. 311f063d76aSMatthew Dillon.Pp 312f063d76aSMatthew DillonAnother way to do this sort of check is to NFS export the major filesystems 313f063d76aSMatthew Dillonfrom every other machine to the security machine. This is somewhat more 3146ac7e896SDavid E. O'Briennetwork intensive but also virtually impossible for an intruder to detect 315f063d76aSMatthew Dillonor spoof. 316f063d76aSMatthew Dillon.Pp 317f063d76aSMatthew DillonA good security script will also check for changes to user and staff members 318f063d76aSMatthew Dillonaccess configuration files: .rhosts, .shosts, .ssh/authorized_keys, and 3196ac7e896SDavid E. O'Brienso forth... files that might fall outside the prevue of the MD5 check. 320f063d76aSMatthew Dillon.Pp 321f063d76aSMatthew DillonA good security script will check for suid and sgid binaries on all 3226ac7e896SDavid E. O'Brienfilesystems and report their absolute existence as well as a diff against 323f063d76aSMatthew Dillonthe previous report or some baseline (say, make a baseline once a week). 324f063d76aSMatthew DillonWhile you can turn off the ability to run suid and sgid binaries on certain 325f063d76aSMatthew Dillonfilesystems through the 'nosuid' option in fstab/mount, you cannot turn this 326f063d76aSMatthew Dillonoff on root and anyone who breaks root can just install their binary their. 327f063d76aSMatthew DillonIf you have a huge amount of user disk space, though, it may be useful to 328f063d76aSMatthew Dillondisallow suid binaries and devices ('nodev' option) on the user partitions 329f063d76aSMatthew Dillonso you do not have to scan them for such. I would scan them anyway, though, 330f063d76aSMatthew Dillonat least once a week, since the object of this onion layer is detection of 3316ac7e896SDavid E. O'Briena break-in. 332f063d76aSMatthew Dillon.Pp 333f063d76aSMatthew DillonProcess accounting (see accton(1)) is a relatively low-overhead feature of 3346ac7e896SDavid E. O'Brienthe operating system which I recommend using as a post-break-in evaluation 3356ac7e896SDavid E. O'Brienmechanism. It is especially useful in tracking down how an intruder has 336f063d76aSMatthew Dillonactually broken root on a system, assuming the file is still intact after 3376ac7e896SDavid E. O'Brienthe break-in occurs. 338f063d76aSMatthew Dillon.Pp 339f063d76aSMatthew DillonFinally, security scripts should process the log files and the logs themselves 340f063d76aSMatthew Dillonshould be generated in as secured a manner as possible - remote syslog can be 3416ac7e896SDavid E. O'Brienvery useful. An intruder tries to cover his tracks, and log files are critical 3426ac7e896SDavid E. O'Briento the sysadmin trying to track down the time and method of the initial break-in. 343f063d76aSMatthew Dillon.Sh PARANOIA 344f063d76aSMatthew Dillon.Pp 3457626ae52SMatthew DillonA little paranoia never hurts. As a rule, a sysadmin can add any number 346f063d76aSMatthew Dillonof security features as long as they do not effect convenience, and 347f063d76aSMatthew Dilloncan add security features that do effect convenience with some added 348f063d76aSMatthew Dillonthought. 349f063d76aSMatthew Dillon.Sh SPECIAL SECTION ON D.O.S. ATTACKS 350f063d76aSMatthew Dillon.Pp 3516ac7e896SDavid E. O'BrienThis section covers Denial of Service attacks. A DOS attack is typically 352f063d76aSMatthew Dillona packet attack. While there isn't much you can do about modern spoofed 353f063d76aSMatthew Dillonpacket attacks that saturate your network, you can generally limit the damage 354f063d76aSMatthew Dillonby ensuring that the attacks cannot take down your servers. 355f063d76aSMatthew Dillon.Bl -enum -offset indent 356f063d76aSMatthew Dillon.It 357f063d76aSMatthew DillonLimiting server forks 358f063d76aSMatthew Dillon.It 359f063d76aSMatthew DillonLimiting springboard attacks (ICMP response attacks, ping broadcast, etc...) 360f063d76aSMatthew Dillon.It 361f063d76aSMatthew DillonKernel Route Cache 362f063d76aSMatthew Dillon.El 363f063d76aSMatthew Dillon.Pp 364f063d76aSMatthew DillonA common DOS attack is against a forking server that attempts to cause the 3656ac7e896SDavid E. O'Brienserver to eat processes, file descriptors, and memory until the machine 366f063d76aSMatthew Dillondies. Inetd (see inetd(8)) has several options to limit this sort of attack. 367f063d76aSMatthew DillonIt should be noted that while it is possible to prevent a machine from going 368f063d76aSMatthew Dillondown it is not generally possible to prevent a service from being disrupted 369f063d76aSMatthew Dillonby the attack. Read the inetd manual page carefully and pay specific attention 370f063d76aSMatthew Dillonto the -c, -C, and -R options. Note that spoofed-IP attacks will circumvent 371f063d76aSMatthew Dillonthe -C option to inetd, so typically a combination of options must be used. 372f063d76aSMatthew DillonSome standalone servers have self-fork-limitation parameters. 373f063d76aSMatthew Dillon.Pp 374f063d76aSMatthew DillonSendmail has its -OMaxDaemonChildren option which tends to work much 375f063d76aSMatthew Dillonbetter then trying to use sendmail's load limiting options due to the 376f063d76aSMatthew Dillonload lag. You should specify a MaxDaemonChildren parameter when you start 377f063d76aSMatthew Dillonsendmail high enough to handle your expected load but no so high that the 378f063d76aSMatthew Dilloncomputer cannot handle that number of sendmails without falling on its face. 379f063d76aSMatthew DillonIt is also prudent to run sendmail in queued mode (-ODeliveryMode=queued) 380f063d76aSMatthew Dillonand to run the daemon (sendmail -bd) separate from the queue-runs 381f063d76aSMatthew Dillon(sendmail -q15m). If you still want realtime delivery you can run the queue 382f063d76aSMatthew Dillonat a much lower interval, such as -q1m, but be sure to specify a reasonable 383f063d76aSMatthew DillonMaxDaemonChildren option for that sendmail to prevent cascade failures. 384f063d76aSMatthew Dillon.Pp 385f063d76aSMatthew DillonSyslogd can be attacked directly and it is strongly recommended that you use 386f063d76aSMatthew Dillonthe -s option whenever possible, and the -a option otherwise. 387f063d76aSMatthew Dillon.Pp 388f063d76aSMatthew DillonYou should also be fairly careful 389f063d76aSMatthew Dillonwith connect-back services such as tcpwrapper's reverse-identd, which can 390f063d76aSMatthew Dillonbe attacked directly. You generally do not want to use the reverse-ident 391f063d76aSMatthew Dillonfeature of tcpwrappers for this reason. 392f063d76aSMatthew Dillon.Pp 393f063d76aSMatthew DillonIt is a very good idea to protect internal services from external access 394f063d76aSMatthew Dillonby firewalling them off at your border routers. The idea here is to prevent 395f063d76aSMatthew Dillonsaturation attacks from outside your LAN, not so much to protect internal 3966ac7e896SDavid E. O'Brienservices from root network-based root compromise. Always configure an exclusive 397f063d76aSMatthew Dillonfirewall, i.e. 'firewall everything *except* ports A, B, C, D, and M-Z'. This 398f063d76aSMatthew Dillonway you can firewall off all of your low ports except for certain specific 399f063d76aSMatthew Dillonservices such as named (if you are primary for a zone), ntalkd, sendmail, 400f063d76aSMatthew Dillonand other internet-accessible services. 401f063d76aSMatthew DillonIf you try to configure the firewall the other 402f063d76aSMatthew Dillonway - as an inclusive or permissive firewall, there is a good chance that you 403f063d76aSMatthew Dillonwill forget to 'close' a couple of services or that you will add a new internal 404f063d76aSMatthew Dillonservice and forget to update the firewall. You can still open up the 405f063d76aSMatthew Dillonhigh-numbered port range on the firewall to allow permissive-like operation 406f063d76aSMatthew Dillonwithout compromising your low ports. Also take note that FreeBSD allows you to 407f063d76aSMatthew Dilloncontrol the range of port numbers used for dynamic binding via the various 408f063d76aSMatthew Dillonnet.inet.ip.portrange sysctl's (sysctl -a | fgrep portrange), which can also 409f063d76aSMatthew Dillonease the complexity of your firewall's configuration. I usually use a normal 410f063d76aSMatthew Dillonfirst/last range of 4000 to 5000, and a hiport range of 49152 to 65535, then 411f063d76aSMatthew Dillonblock everything under 4000 off in my firewall ( except for certain specific 412f063d76aSMatthew Dilloninternet-accessible ports, of course ). 413f063d76aSMatthew Dillon.Pp 414f063d76aSMatthew DillonAnother common DOS attack is called a springboard attack - to attack a server 415f063d76aSMatthew Dillonin a manner that causes the server to generate responses which then overload 416f063d76aSMatthew Dillonthe server, the local network, or some other machine. The most common attack 417f063d76aSMatthew Dillonof this nature is the ICMP PING BROADCAST attack. The attacker spoofed ping 418f063d76aSMatthew Dillonpackets sent to your LAN's broadcast address with the source IP address set 419f063d76aSMatthew Dillonto the actual machine they wish to attack. If your border routers are not 420f063d76aSMatthew Dillonconfigured to stomp on ping's to broadcast addresses, your LAN winds up 421f063d76aSMatthew Dillongenerating sufficient responses to the spoofed source address to saturate the 422f063d76aSMatthew Dillonvictim, especially when the attacker uses the same trick on several dozen 423f063d76aSMatthew Dillonbroadcast addresses over several dozen different networks at once. Broadcast 424f063d76aSMatthew Dillonattacks of over a hundred and twenty megabits have been measured. A second 425f063d76aSMatthew Dilloncommon springboard attack is against the ICMP error reporting system. By 426f063d76aSMatthew Dillonconstructing packets that generate ICMP error responses, an attacker can 427f063d76aSMatthew Dillonsaturate a server's incoming network and cause the server to saturate its 428f063d76aSMatthew Dillonoutgoing network with ICMP responses. This type of attack can also crash the 429f063d76aSMatthew Dillonserver by running it out of mbuf's, especially if the server cannot drain the 430f063d76aSMatthew DillonICMP responses it generates fast enough. The FreeBSD kernel has a new kernel 431f063d76aSMatthew Dilloncompile option called ICMP_BANDLIM which limits the effectiveness of these 432f063d76aSMatthew Dillonsorts of attacks. The last major class of springboard attacks is related to 433f063d76aSMatthew Dilloncertain internal inetd services such as the udp echo service. An attacker 434f063d76aSMatthew Dillonsimply spoofs a UDP packet with the source address being server A's echo port, 435f063d76aSMatthew Dillonand the destination address being server B's echo port, where server A and B 436f063d76aSMatthew Dillonare both on your LAN. The two servers then bounce this one packet back and 437f063d76aSMatthew Dillonforth between each other. The attacker can overload both servers and their 438f063d76aSMatthew DillonLANs simply by injecting a few packets in this manner. Similar problems 4397626ae52SMatthew Dillonexist with the internal chargen port. A competent sysadmin will turn off all 440f063d76aSMatthew Dillonof these inetd-internal test services. 441f063d76aSMatthew Dillon.Pp 442f063d76aSMatthew DillonSpoofed packet attacks may also be used to overload the kernel route cache. 443f063d76aSMatthew DillonRefer to the net.inet.ip.rtexpire, rtminexpire, and rtmaxcache sysctl 444f063d76aSMatthew Dillonparameters. A spoofed packet attack that uses a random source IP will cause 445f063d76aSMatthew Dillonthe kernel to generate a temporary cached route in the route table, viewable 446f063d76aSMatthew Dillonwith 'netstat -rna | fgrep W3'. These routes typically timeout in 1600 447f063d76aSMatthew Dillonseconds or so. If the kernel detects that the cached route table has gotten 448f063d76aSMatthew Dillontoo big it will dynamically reduce the rtexpire but will never decrease it to 449f063d76aSMatthew Dillonless then rtminexpire. There are two problems: (1) The kernel does not react 450f063d76aSMatthew Dillonquickly enough when a lightly loaded server is suddenly attacked, and (2) The 451f063d76aSMatthew Dillonrtminexpire is not low enough for the kernel to survive a sustained attack. 452f063d76aSMatthew DillonIf your servers are connected to the internet via a T3 or better it may be 453f063d76aSMatthew Dillonprudent to manually override both rtexpire and rtminexpire via sysctl(8). 454f063d76aSMatthew DillonNever set either parameter to zero (unless you want to crash the machine :-)). 455f063d76aSMatthew DillonSetting both parameters to 2 seconds should be sufficient to protect the route 456f063d76aSMatthew Dillontable from attack. 457f063d76aSMatthew Dillon 458f063d76aSMatthew Dillon.Sh SEE ALSO 459f063d76aSMatthew Dillon.Pp 460f063d76aSMatthew Dillon.Xr accton 1 , 461f063d76aSMatthew Dillon.Xr chflags 1 , 462f063d76aSMatthew Dillon.Xr find 1 , 4636ac7e896SDavid E. O'Brien.Xr kerberos 1 , 464f063d76aSMatthew Dillon.Xr md5 1 , 4656ac7e896SDavid E. O'Brien.Xr ssh 1 , 4666ac7e896SDavid E. O'Brien.Xr sshd 1 , 4676ac7e896SDavid E. O'Brien.Xr syslogd 1 , 4686ac7e896SDavid E. O'Brien.Xr xdm 1 , 469f063d76aSMatthew Dillon.Xr sysctl 8 470f063d76aSMatthew Dillon.Sh HISTORY 471f063d76aSMatthew DillonThe 472f063d76aSMatthew Dillon.Nm 473f063d76aSMatthew Dillonmanual page was originally written by Matthew Dillon and first appeared 474f063d76aSMatthew Dillonin FreeBSD-3.0.1, December 1998. 475