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 13f063d76aSMatthew Dillon.\" must display the following acknowledgement: 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 33f063d76aSMatthew Dillon.\" $Id: security.1,v 1.3 1998/12/20 20:05:44 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 48f063d76aSMatthew Dillonone of the single largest undertakings of the sysad. 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, 51f063d76aSMatthew Dillonin general, are capable of running a huge number of simultanious 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 64f063d76aSMatthew DillonRoot Hacks through accessible servers 65f063d76aSMatthew Dillon.It 66f063d76aSMatthew DillonRoot Hacks 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 81f063d76aSMatthew Dillonsysops 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 87f063d76aSMatthew Dillonhis remote access logs occassionally 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 119f063d76aSMatthew DillonChecking file integrity: binaries, config 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 134f063d76aSMatthew Dillonsecure by default on most systems, but a good sysad always checks to make sure. 135f063d76aSMatthew Dillon.Pp 136f063d76aSMatthew DillonOf course, as a sysad you have to be able to get to root, so we open up 137f063d76aSMatthew Dillona few holes. But we make sure these holes require additional password 138f063d76aSMatthew Dillonverification to operate. One way to make root accessible is to add appropriate 139f063d76aSMatthew Dillonstaff accounts to the wheel group (in /etc/group). The staff members placed 140f063d76aSMatthew Dillonin the wheel group are allowed to 'su' to root. You should never give staff 141f063d76aSMatthew Dillonmembers native wheel access via their entry in the password file... put staff 142f063d76aSMatthew Dillonin a 'staff' group or something and only add those that really need root to 143f063d76aSMatthew Dillonthe wheel group. Unfortunately the wheel mechanism still allows a hacker to 144f063d76aSMatthew Dillonbreak root if the hacker has gotten hold of your password file - he need only 145f063d76aSMatthew Dillonbreak the root password and the password of one of the staff accounts that 146f063d76aSMatthew Dillonhappens to be in the wheel group. So while the wheel mechanism is useable, 147f063d76aSMatthew Dillonit isn't much safer then not having a wheel group at all. 148f063d76aSMatthew Dillon.Pp 149f063d76aSMatthew DillonAn indirect way to secure the root account is to secure your staff accounts 150f063d76aSMatthew Dillonby using an alternative login access method and *'ing out the crypted password 151f063d76aSMatthew Dillonfor the staff accounts. This way a hacker may be able to steal the password 152f063d76aSMatthew Dillonfile but will not be able to break into any staff accounts (or, indirectly, 153f063d76aSMatthew Dillonroot, even if root has a crypted password associated with it). Staff members 154f063d76aSMatthew Dillonget into their staff accounts through a secure login mechanism such as 155f063d76aSMatthew Dillonkerberos(1) or ssh(1) (see /usr/ports/security/ssh) using a private/public 156f063d76aSMatthew Dillonkeypair. When you use something like kerberos you generally must secure 157f063d76aSMatthew Dillonthe machines which run the kerberos servers and your desktop workstation. 158f063d76aSMatthew DillonWhen you use a public/private keypair with ssh, you must generally secure 159f063d76aSMatthew Dillonthe machine you are logging in FROM (typically your workstation), but you can 160f063d76aSMatthew Dillonalso add an additional layer of protection to the keypair by password 161f063d76aSMatthew Dillonprotecting the keypair when you create it with ssh-keygen(1). Being able 162f063d76aSMatthew Dillonto *-out the passwords for staff accounts also guarentees that staff members 163f063d76aSMatthew Dilloncan only login through secure access methods that you have setup. You can 164f063d76aSMatthew Dillonthus force all staff members to use secure, encrypted connections for 165f063d76aSMatthew Dillonall their sessions which closes an important hole used by many hackers: That 166f063d76aSMatthew Dillonof sniffing the network from an unrelated, less secure machine. 167f063d76aSMatthew Dillon.Pp 168f063d76aSMatthew DillonThe more indirect security mechanisms also assume that you are logging in 169f063d76aSMatthew Dillonfrom a more restrictive server to a less restrictive server. For example, 170f063d76aSMatthew Dillonif your main box is running all sorts of servers, your workstation shouldn't 171f063d76aSMatthew Dillon be running any. In order for your workstation to be reasonably secure 172f063d76aSMatthew Dillonyou should run as few servers as possible, up to and including no servers 173f063d76aSMatthew Dillonat all, and you should run a password-protected screen blanker. 174f063d76aSMatthew Dillon Of course, given physical access to 175f063d76aSMatthew Dillona workstation an attacker can break any sort of security you put on it. 176f063d76aSMatthew DillonThis is definitely a problem that you should consider but you should also 177f063d76aSMatthew Dillonconsider the fact that the vast majority of breakins occur remotely, over 178f063d76aSMatthew Dillona network, from peopl who do not have physical access to your workstation or 179f063d76aSMatthew Dillonservers. 180f063d76aSMatthew Dillon.Pp 181f063d76aSMatthew DillonUsing something like kerberos also gives you the ability to disable or 182f063d76aSMatthew Dillonchange the password for a staff account in one place and have it immediately 183f063d76aSMatthew Dilloneffect all the machine the staff member may have an account on. If a staff 184f063d76aSMatthew Dillonmember's account gets compromised, the ability to instantly change his 185f063d76aSMatthew Dillonpassword on all machines should not be underrated. With discrete passwords, 186f063d76aSMatthew Dillonchanging a password on N machines can be a mess. You can also impose 187f063d76aSMatthew Dillonre-passwording restrictions with kerberos: not only can a kerberos ticket 188f063d76aSMatthew Dillonbe made to timeout after a while, but the kerberos system can require that 189f063d76aSMatthew Dillonthe user choose a new password after a certain period of time (say, once a 190f063d76aSMatthew Dillonmonth). 191f063d76aSMatthew Dillon.Sh SECURING ROOT - ROOT-RUN SERVERS AND SUID/SGID BINARIES 192f063d76aSMatthew Dillon.Pp 193f063d76aSMatthew DillonThe prudent sysop only runs the servers he needs to, no more, no less. Be 194f063d76aSMatthew Dillonaware that third party servers are often the most bug-prone. For example, 195f063d76aSMatthew Dillonrunning an old version of imapd or popper is like giving a universal root 196f063d76aSMatthew Dillonticket out to the entire world. Never run a server that you have not checked 197f063d76aSMatthew Dillonout carefully. Many servers do not need to be run as root. For example, 198f063d76aSMatthew Dillonthe ntalk, comsat, and finger daemons can be run in special user 'sandboxes'. 199f063d76aSMatthew DillonA sandbox isn't perfect unless you go to a hellofalot of trouble, but the 200f063d76aSMatthew Dillononion approach to security still stands: If someone is able to break in 201f063d76aSMatthew Dillonthrough a server running in a sandbox, they still have to break out of the 202f063d76aSMatthew Dillonsandbox. The more layers the attacker must break through, the lower the 203f063d76aSMatthew Dillonlikelihood of his success. Root holes have historically been found in 204f063d76aSMatthew Dillonvirtually every server ever run as root, including basic system servers. 205f063d76aSMatthew DillonIf you are running a machine through which people only login via sshd and 206f063d76aSMatthew Dillonnever login via telnetd or rshd or rlogind, then turn off those services! 207f063d76aSMatthew Dillon.Pp 208f063d76aSMatthew DillonFreeBSD now defaults to running ntalkd, comsat, and finger in a sandbox. 209f063d76aSMatthew DillonAnother program which may be a candidate for running in a sandbox is 210f063d76aSMatthew Dillonnamed(8). The default rc.conf includes the arguments necessary to run 211f063d76aSMatthew Dillonnamed in a sandbox in a commented-out form. Depending on whether you 212f063d76aSMatthew Dillonare installing a new system or upgrading an existing system, the special 213f063d76aSMatthew Dillonuser accounts used by these sandboxes may not be installed. The prudent 214f063d76aSMatthew Dillonsysop would research and implement sandboxes for servers whenever possible. 215f063d76aSMatthew Dillon.Pp 216f063d76aSMatthew DillonThere are a number of other servers that typically do not run in sandboxes: 217f063d76aSMatthew Dillonsendmail, popper, imapd, ftpd, and others. There are alternatives to 218f063d76aSMatthew Dillonsome of these, but installing them may require more work then you are willing 219f063d76aSMatthew Dillonto put (the convenience factor strikes again). You may have to run these 220f063d76aSMatthew Dillonservers as root and rely on other mechanisms to detect breakins that might 221f063d76aSMatthew Dillonoccur through them. 222f063d76aSMatthew Dillon.Pp 223f063d76aSMatthew DillonThe other big potential root hole in a system are the suid-root and sgid 224f063d76aSMatthew Dillonbinaries installed on the system. Most of these binaries, such as rlogin, 225f063d76aSMatthew Dillonreside in /bin, /sbin, /usr/bin, or /usr/sbin. While nothing is 100% safe, 226f063d76aSMatthew Dillonthe system-default suid and sgid binaries can be considered reasonably safe. 227f063d76aSMatthew DillonStill, root holes are occassionaly found in these binaries. A root hole 228f063d76aSMatthew Dillonwas found in Xlib in 1998 that made xterm (which is typically suid) vulnerable. 229f063d76aSMatthew DillonIt is better to be safe then sorry and the prudent sysad will restrict suid 230f063d76aSMatthew Dillonbinaries that only staff should run to a special group that only staff can 231f063d76aSMatthew Dillonaccess, and get rid of (chmod 000) any suid binaries that nobody uses. A 232f063d76aSMatthew Dillonserver with no display generally does not need an xterm binary. Sgid binaries 233f063d76aSMatthew Dilloncan be almost as dangerous. If a hacker can break an sgid-kmem binary the 234f063d76aSMatthew Dillonhacker might be able to read /dev/kmem and thus read the crypted password 235f063d76aSMatthew Dillonfile, potentially compromising any passworded account. A hacker that breaks 236f063d76aSMatthew Dillonthe tty group can write to almost user's tty. If a user is running a terminal 237f063d76aSMatthew Dillonprogram or emulator with a talk-back feature, the hacker can potentially 238f063d76aSMatthew Dillongenerate a data stream that causes the user's terminal to echo a command, which 239f063d76aSMatthew Dillonis then run as that user. 240f063d76aSMatthew Dillon.Sh SECURING USER ACCOUNTS 241f063d76aSMatthew Dillon.Pp 242f063d76aSMatthew DillonUser accounts are usually the most difficult to secure. While you can impose 243f063d76aSMatthew Dillondraconian access restrictions on your staff and *-out their passwords, you 244f063d76aSMatthew Dillonmay not be able to do so with any general user accounts you might have. If 245f063d76aSMatthew Dillonyou do have sufficient control then you may win out and be able to secure the 246f063d76aSMatthew Dillonuser accounts properly. If not, you simply have to be more vigilant in your 247f063d76aSMatthew Dillonmonitoring of those accounts. Use of ssh and kerberos for user accounts is 248f063d76aSMatthew Dillonmore problematic, but still a very good solution compared to a crypted 249f063d76aSMatthew Dillonpassword. 250f063d76aSMatthew Dillon.Sh SECURING THE PASSWORD FILE 251f063d76aSMatthew Dillon.Pp 252f063d76aSMatthew DillonThe only sure fire way is to *-out as many passwords as you can and 253f063d76aSMatthew Dillonuse ssh or kerberos for access to those accounts. Even though the 254f063d76aSMatthew Dilloncrypted password file (/etc/spwd.db) can only be read by root, it may 255f063d76aSMatthew Dillonbe possible for a hacker to obtain read access to that file even if the 256f063d76aSMatthew Dillonattacker cannot obtain root-write access. 257f063d76aSMatthew Dillon.Pp 258f063d76aSMatthew DillonYour security scripts should always check for and report changes to 259f063d76aSMatthew Dillonthe password file (see 'Checking file integrity' below). 260f063d76aSMatthew Dillon.Sh SECURING THE KERNEL CORE, RAW DEVICES, AND FILESYSTEMS 261f063d76aSMatthew Dillon.Pp 262f063d76aSMatthew DillonIf an attacker breaks root he can do just about anything, but there 263f063d76aSMatthew Dillonare certain conveniences. For example, most modern kernels have a 264f063d76aSMatthew Dillonpacket sniffing device driver built in. Under FreeBSD it is called 265f063d76aSMatthew Dillonthe 'bpf' device. A hacker will commonly attempt to run a packet sniffer 266f063d76aSMatthew Dillonon a compromised machine. You do not need to give the hacker the 267f063d76aSMatthew Dilloncapability and most systems should not have the bpf device compiled in. 268f063d76aSMatthew DillonUnfortunately, there is another kernel feature called the Loadable Kernel 269f063d76aSMatthew DillonModule interface. An enterprising hacker can use an LKM to install 270f063d76aSMatthew Dillonhis own bpf device or other sniffing device on a running kernel. If you 271f063d76aSMatthew Dillondo not need to use the module loader, turn it off in the kernel config 272f063d76aSMatthew Dillonwith the NO_LKM option. 273f063d76aSMatthew Dillon.Pp 274f063d76aSMatthew DillonBut even if you turn off the bpf device, and turn off the module loader, 275f063d76aSMatthew Dillonyou still have /dev/mem and /dev/kmem to worry about. For that matter, 276f063d76aSMatthew Dillonthe hacker can still write raw devices. To avoid this you have to run 277f063d76aSMatthew Dillonthe kernel at a higher secure level... at least securelevel 1. The securelevel 278f063d76aSMatthew Dilloncan be set with a sysctl on the kern.securelevel variable. Once you have 279f063d76aSMatthew Dillonset the securelevel to 1, write access to raw devices will be denied and 280f063d76aSMatthew Dillonspecial chflags flags, such as 'schg', will be enforced. You must also ensure 281f063d76aSMatthew Dillonthat the 'schg' flag is set on critical startup binaries, directories, and 282f063d76aSMatthew Dillonscript files - everything that gets run up to the point where the securelevel 283f063d76aSMatthew Dillonis set. This might be overdoing it, and upgrading the system is much more 284f063d76aSMatthew Dillondifficult when you operate at a higher secure level. You may compromise and 285f063d76aSMatthew Dillonrun the system at a higher secure level but not set the schg flag for every 286f063d76aSMatthew Dillonsystem file and directory under the sun. 287f063d76aSMatthew Dillon.Sh CHECKING FILE INTEGRITY: BINARIES, CONFIG FILES, ETC 288f063d76aSMatthew Dillon.Pp 289f063d76aSMatthew DillonWhen it comes right down to it, you can only protect your core system 290f063d76aSMatthew Dillonconfiguration and control files so much before the convenience factor 291f063d76aSMatthew Dillonrears its ugly head. The last layer of your security onion is perhaps 292f063d76aSMatthew Dillonthe most important - detection. 293f063d76aSMatthew Dillon.Pp 294f063d76aSMatthew DillonThe only correct way to check a system's file integrity is via another, 295f063d76aSMatthew Dillonmore secure system. It is fairly easy to setup a 'secure' system: you 296f063d76aSMatthew Dillonsimply do not run any services on it. With a secure system in place you 297f063d76aSMatthew Dilloncan then give it access to other system's root spaces via ssh. This may 298f063d76aSMatthew Dillonseem like a security breech, but you have to put your trust somewhere and 299f063d76aSMatthew Dillonas long as you don't do something stupid like run random servers it really 300f063d76aSMatthew Dillonis possible to build a secure machine. When I say 'secure' here, I assuming 301f063d76aSMatthew Dillonphysical access security as well, of course. Given a secure machine with 302f063d76aSMatthew Dillonroot access on all your other machines, you can then write security scripts 303f063d76aSMatthew DillonON the secure machine to check the other machines on the system. The most 304f063d76aSMatthew Dilloncommon way of checking is to have the security script scp(1) over a find 305f063d76aSMatthew Dillonand md5 binary and then ssh a shell command to the remote machine to md5 306f063d76aSMatthew Dillonall the files in the system (or, at least, the /, /var, and /usr partitions!). 307f063d76aSMatthew DillonThe security machine copies the results to a file and diff's them against 308f063d76aSMatthew Dillonresults from a previous run (or compares the results against its own 309f063d76aSMatthew Dillonbinaries), then emails each staff member a daily report of differences. 310f063d76aSMatthew Dillon.Pp 311f063d76aSMatthew DillonAnother way to do this sort of check is to NFS export the major filesystems 312f063d76aSMatthew Dillonfrom every other machine to the security machine. This is somewhat more 313f063d76aSMatthew Dillonnetwork intensive but also virtually impossible for a hacker to detect 314f063d76aSMatthew Dillonor spoof. 315f063d76aSMatthew Dillon.Pp 316f063d76aSMatthew DillonA good security script will also check for changes to user and staff members 317f063d76aSMatthew Dillonaccess configuration files: .rhosts, .shosts, .ssh/authorized_keys, and 318f063d76aSMatthew Dillonso forth... files that might fall outside the pervue of the MD5 check. 319f063d76aSMatthew Dillon.Pp 320f063d76aSMatthew DillonA good security script will check for suid and sgid binaries on all 321f063d76aSMatthew Dillonfilesystems and report their absolute existance as well as a diff against 322f063d76aSMatthew Dillonthe previous report or some baseline (say, make a baseline once a week). 323f063d76aSMatthew DillonWhile you can turn off the ability to run suid and sgid binaries on certain 324f063d76aSMatthew Dillonfilesystems through the 'nosuid' option in fstab/mount, you cannot turn this 325f063d76aSMatthew Dillonoff on root and anyone who breaks root can just install their binary their. 326f063d76aSMatthew DillonIf you have a huge amount of user disk space, though, it may be useful to 327f063d76aSMatthew Dillondisallow suid binaries and devices ('nodev' option) on the user partitions 328f063d76aSMatthew Dillonso you do not have to scan them for such. I would scan them anyway, though, 329f063d76aSMatthew Dillonat least once a week, since the object of this onion layer is detection of 330f063d76aSMatthew Dillona breakin. 331f063d76aSMatthew Dillon.Pp 332f063d76aSMatthew DillonProcess accounting (see accton(1)) is a relatively low-overhead feature of 333f063d76aSMatthew Dillonthe operating system which I recommend using as a post-breakin evaluation 334f063d76aSMatthew Dillonmechanism. It is especially useful in tracking down how a hacker has 335f063d76aSMatthew Dillonactually broken root on a system, assuming the file is still intact after 336f063d76aSMatthew Dillonthe breakin occurs. 337f063d76aSMatthew Dillon.Pp 338f063d76aSMatthew DillonFinally, security scripts should process the log files and the logs themselves 339f063d76aSMatthew Dillonshould be generated in as secured a manner as possible - remote syslog can be 340f063d76aSMatthew Dillonvery useful. A hacker tries to cover his tracks, and log files are critical 341f063d76aSMatthew Dillonto the sysop trying to track down the time and method of the initial breakin. 342f063d76aSMatthew Dillon.Sh PARANOIA 343f063d76aSMatthew Dillon.Pp 344f063d76aSMatthew DillonA little paranoia never hurts. As a rule, a sysop can add any number 345f063d76aSMatthew Dillonof security features as long as they do not effect convenience, and 346f063d76aSMatthew Dilloncan add security features that do effect convenience with some added 347f063d76aSMatthew Dillonthought. 348f063d76aSMatthew Dillon.Sh SPECIAL SECTION ON D.O.S. ATTACKS 349f063d76aSMatthew Dillon.Pp 350f063d76aSMatthew DillonThis section covers Dential of Service attacks. A DOS attack is typically 351f063d76aSMatthew Dillona packet attack. While there isn't much you can do about modern spoofed 352f063d76aSMatthew Dillonpacket attacks that saturate your network, you can generally limit the damage 353f063d76aSMatthew Dillonby ensuring that the attacks cannot take down your servers. 354f063d76aSMatthew Dillon.Bl -enum -offset indent 355f063d76aSMatthew Dillon.It 356f063d76aSMatthew DillonLimiting server forks 357f063d76aSMatthew Dillon.It 358f063d76aSMatthew DillonLimiting springboard attacks (ICMP response attacks, ping broadcast, etc...) 359f063d76aSMatthew Dillon.It 360f063d76aSMatthew DillonKernel Route Cache 361f063d76aSMatthew Dillon.El 362f063d76aSMatthew Dillon.Pp 363f063d76aSMatthew DillonA common DOS attack is against a forking server that attempts to cause the 364f063d76aSMatthew Dillonserver to eat processes, file descirptors, and memory until the machine 365f063d76aSMatthew Dillondies. Inetd (see inetd(8)) has several options to limit this sort of attack. 366f063d76aSMatthew DillonIt should be noted that while it is possible to prevent a machine from going 367f063d76aSMatthew Dillondown it is not generally possible to prevent a service from being disrupted 368f063d76aSMatthew Dillonby the attack. Read the inetd manual page carefully and pay specific attention 369f063d76aSMatthew Dillonto the -c, -C, and -R options. Note that spoofed-IP attacks will circumvent 370f063d76aSMatthew Dillonthe -C option to inetd, so typically a combination of options must be used. 371f063d76aSMatthew DillonSome standalone servers have self-fork-limitation parameters. 372f063d76aSMatthew Dillon.Pp 373f063d76aSMatthew DillonSendmail has its -OMaxDaemonChildren option which tends to work much 374f063d76aSMatthew Dillonbetter then trying to use sendmail's load limiting options due to the 375f063d76aSMatthew Dillonload lag. You should specify a MaxDaemonChildren parameter when you start 376f063d76aSMatthew Dillonsendmail high enough to handle your expected load but no so high that the 377f063d76aSMatthew Dilloncomputer cannot handle that number of sendmails without falling on its face. 378f063d76aSMatthew DillonIt is also prudent to run sendmail in queued mode (-ODeliveryMode=queued) 379f063d76aSMatthew Dillonand to run the daemon (sendmail -bd) separate from the queue-runs 380f063d76aSMatthew Dillon(sendmail -q15m). If you still want realtime delivery you can run the queue 381f063d76aSMatthew Dillonat a much lower interval, such as -q1m, but be sure to specify a reasonable 382f063d76aSMatthew DillonMaxDaemonChildren option for that sendmail to prevent cascade failures. 383f063d76aSMatthew Dillon.Pp 384f063d76aSMatthew DillonSyslogd can be attacked directly and it is strongly recommended that you use 385f063d76aSMatthew Dillonthe -s option whenever possible, and the -a option otherwise. 386f063d76aSMatthew Dillon.Pp 387f063d76aSMatthew DillonYou should also be fairly careful 388f063d76aSMatthew Dillonwith connect-back services such as tcpwrapper's reverse-identd, which can 389f063d76aSMatthew Dillonbe attacked directly. You generally do not want to use the reverse-ident 390f063d76aSMatthew Dillonfeature of tcpwrappers for this reason. 391f063d76aSMatthew Dillon.Pp 392f063d76aSMatthew DillonIt is a very good idea to protect internal services from external access 393f063d76aSMatthew Dillonby firewalling them off at your border routers. The idea here is to prevent 394f063d76aSMatthew Dillonsaturation attacks from outside your LAN, not so much to protect internal 395f063d76aSMatthew Dillonservices from root network-based root hacks. Always configure an exclusive 396f063d76aSMatthew Dillonfirewall, i.e. 'firewall everything *except* ports A, B, C, D, and M-Z'. This 397f063d76aSMatthew Dillonway you can firewall off all of your low ports except for certain specific 398f063d76aSMatthew Dillonservices such as named (if you are primary for a zone), ntalkd, sendmail, 399f063d76aSMatthew Dillonand other internet-accessible services. 400f063d76aSMatthew DillonIf you try to configure the firewall the other 401f063d76aSMatthew Dillonway - as an inclusive or permissive firewall, there is a good chance that you 402f063d76aSMatthew Dillonwill forget to 'close' a couple of services or that you will add a new internal 403f063d76aSMatthew Dillonservice and forget to update the firewall. You can still open up the 404f063d76aSMatthew Dillonhigh-numbered port range on the firewall to allow permissive-like operation 405f063d76aSMatthew Dillonwithout compromising your low ports. Also take note that FreeBSD allows you to 406f063d76aSMatthew Dilloncontrol the range of port numbers used for dynamic binding via the various 407f063d76aSMatthew Dillonnet.inet.ip.portrange sysctl's (sysctl -a | fgrep portrange), which can also 408f063d76aSMatthew Dillonease the complexity of your firewall's configuration. I usually use a normal 409f063d76aSMatthew Dillonfirst/last range of 4000 to 5000, and a hiport range of 49152 to 65535, then 410f063d76aSMatthew Dillonblock everything under 4000 off in my firewall ( except for certain specific 411f063d76aSMatthew Dilloninternet-accessible ports, of course ). 412f063d76aSMatthew Dillon.Pp 413f063d76aSMatthew DillonAnother common DOS attack is called a springboard attack - to attack a server 414f063d76aSMatthew Dillonin a manner that causes the server to generate responses which then overload 415f063d76aSMatthew Dillonthe server, the local network, or some other machine. The most common attack 416f063d76aSMatthew Dillonof this nature is the ICMP PING BROADCAST attack. The attacker spoofed ping 417f063d76aSMatthew Dillonpackets sent to your LAN's broadcast address with the source IP address set 418f063d76aSMatthew Dillonto the actual machine they wish to attack. If your border routers are not 419f063d76aSMatthew Dillonconfigured to stomp on ping's to broadcast addresses, your LAN winds up 420f063d76aSMatthew Dillongenerating sufficient responses to the spoofed source address to saturate the 421f063d76aSMatthew Dillonvictim, especially when the attacker uses the same trick on several dozen 422f063d76aSMatthew Dillonbroadcast addresses over several dozen different networks at once. Broadcast 423f063d76aSMatthew Dillonattacks of over a hundred and twenty megabits have been measured. A second 424f063d76aSMatthew Dilloncommon springboard attack is against the ICMP error reporting system. By 425f063d76aSMatthew Dillonconstructing packets that generate ICMP error responses, an attacker can 426f063d76aSMatthew Dillonsaturate a server's incoming network and cause the server to saturate its 427f063d76aSMatthew Dillonoutgoing network with ICMP responses. This type of attack can also crash the 428f063d76aSMatthew Dillonserver by running it out of mbuf's, especially if the server cannot drain the 429f063d76aSMatthew DillonICMP responses it generates fast enough. The FreeBSD kernel has a new kernel 430f063d76aSMatthew Dilloncompile option called ICMP_BANDLIM which limits the effectiveness of these 431f063d76aSMatthew Dillonsorts of attacks. The last major class of springboard attacks is related to 432f063d76aSMatthew Dilloncertain internal inetd services such as the udp echo service. An attacker 433f063d76aSMatthew Dillonsimply spoofs a UDP packet with the source address being server A's echo port, 434f063d76aSMatthew Dillonand the destination address being server B's echo port, where server A and B 435f063d76aSMatthew Dillonare both on your LAN. The two servers then bounce this one packet back and 436f063d76aSMatthew Dillonforth between each other. The attacker can overload both servers and their 437f063d76aSMatthew DillonLANs simply by injecting a few packets in this manner. Similar problems 438f063d76aSMatthew Dillonexist with the internal chargen port. A competent sysad will turn off all 439f063d76aSMatthew Dillonof these inetd-internal test services. 440f063d76aSMatthew Dillon.Pp 441f063d76aSMatthew DillonSpoofed packet attacks may also be used to overload the kernel route cache. 442f063d76aSMatthew DillonRefer to the net.inet.ip.rtexpire, rtminexpire, and rtmaxcache sysctl 443f063d76aSMatthew Dillonparameters. A spoofed packet attack that uses a random source IP will cause 444f063d76aSMatthew Dillonthe kernel to generate a temporary cached route in the route table, viewable 445f063d76aSMatthew Dillonwith 'netstat -rna | fgrep W3'. These routes typically timeout in 1600 446f063d76aSMatthew Dillonseconds or so. If the kernel detects that the cached route table has gotten 447f063d76aSMatthew Dillontoo big it will dynamically reduce the rtexpire but will never decrease it to 448f063d76aSMatthew Dillonless then rtminexpire. There are two problems: (1) The kernel does not react 449f063d76aSMatthew Dillonquickly enough when a lightly loaded server is suddenly attacked, and (2) The 450f063d76aSMatthew Dillonrtminexpire is not low enough for the kernel to survive a sustained attack. 451f063d76aSMatthew DillonIf your servers are connected to the internet via a T3 or better it may be 452f063d76aSMatthew Dillonprudent to manually override both rtexpire and rtminexpire via sysctl(8). 453f063d76aSMatthew DillonNever set either parameter to zero (unless you want to crash the machine :-)). 454f063d76aSMatthew DillonSetting both parameters to 2 seconds should be sufficient to protect the route 455f063d76aSMatthew Dillontable from attack. 456f063d76aSMatthew Dillon 457f063d76aSMatthew Dillon.Sh SEE ALSO 458f063d76aSMatthew Dillon.Pp 459f063d76aSMatthew Dillon.Xr ssh 1 , 460f063d76aSMatthew Dillon.Xr sshd 1 , 461f063d76aSMatthew Dillon.Xr kerberos 1 , 462f063d76aSMatthew Dillon.Xr accton 1 , 463f063d76aSMatthew Dillon.Xr xdm 1 , 464f063d76aSMatthew Dillon.Xr syslogd 1 , 465f063d76aSMatthew Dillon.Xr chflags 1 , 466f063d76aSMatthew Dillon.Xr find 1 , 467f063d76aSMatthew Dillon.Xr md5 1 , 468f063d76aSMatthew Dillon.Xr sysctl 8 469f063d76aSMatthew Dillon.Sh HISTORY 470f063d76aSMatthew DillonThe 471f063d76aSMatthew Dillon.Nm 472f063d76aSMatthew Dillonmanual page was originally written by Matthew Dillon and first appeared 473f063d76aSMatthew Dillonin FreeBSD-3.0.1, December 1998. 474f063d76aSMatthew Dillon 475