13128fa34SMatthew Dillon.\" Copyright (c) 1998, Matthew Dillon. Terms and conditions are those of 23128fa34SMatthew Dillon.\" the BSD Copyright as specified in the file "/usr/src/COPYRIGHT" in 33128fa34SMatthew Dillon.\" the source tree. 4f063d76aSMatthew Dillon.\" 57f3dea24SPeter Wemm.\" $FreeBSD$ 6f063d76aSMatthew Dillon.\" 73128fa34SMatthew Dillon.Dd December 20, 1998 8f063d76aSMatthew Dillon.Dt SECURITY 7 9f063d76aSMatthew Dillon.Os 10f063d76aSMatthew Dillon.Sh NAME 11f063d76aSMatthew Dillon.Nm security 12f063d76aSMatthew Dillon.Nd introduction to security under FreeBSD 13f063d76aSMatthew Dillon.Sh DESCRIPTION 14f063d76aSMatthew Dillon.Pp 15f063d76aSMatthew DillonSecurity is a function that begins and ends with the system administrator. 16f063d76aSMatthew DillonWhile all 17f063d76aSMatthew Dillon.Bx 18f063d76aSMatthew Dillonsystems are inherently multi-user capable, the job of building and 19568e4cbbSGuy Helmermaintaining security mechanisms to keep those users 20568e4cbbSGuy Helmer.Sq honest 21568e4cbbSGuy Helmeris probably 226ac7e896SDavid E. O'Brienone of the single largest undertakings of the sysadmin. Machines are 23f063d76aSMatthew Dillononly as secure as you make them, and security concerns are ever competing 24568e4cbbSGuy Helmerwith the human necessity for convenience. 25568e4cbbSGuy Helmer.Ux 26568e4cbbSGuy Helmersystems, 276ac7e896SDavid E. O'Brienin general, are capable of running a huge number of simultaneous processes 28f063d76aSMatthew Dillonand many of these processes operate as servers - meaning that external entities 29f063d76aSMatthew Dilloncan connect and talk to them. As yesterday's mini-computers and mainframes 30f063d76aSMatthew Dillonbecome today's desktops, and as computers become networked and internetworked, 31f063d76aSMatthew Dillonsecurity becomes an ever bigger issue. 32f063d76aSMatthew Dillon.Pp 33f063d76aSMatthew DillonSecurity concerns can be split up into several categories: 34f063d76aSMatthew Dillon.Bl -enum -offset indent 35f063d76aSMatthew Dillon.It 36f063d76aSMatthew DillonDenial of service attacks 37f063d76aSMatthew Dillon.It 38f063d76aSMatthew DillonUser account compromises 39f063d76aSMatthew Dillon.It 406ac7e896SDavid E. O'BrienRoot compromise through accessible servers 41f063d76aSMatthew Dillon.It 426ac7e896SDavid E. O'BrienRoot compromise via user accounts 43f063d76aSMatthew Dillon.El 44f063d76aSMatthew Dillon.Pp 45f063d76aSMatthew DillonA denial of service attack is an action that deprives the machine of needed 46f063d76aSMatthew Dillonresources. Typically, D.O.S. attacks are brute-force mechanisms that attempt 47f063d76aSMatthew Dillonto crash or otherwise make a machine unusable by overwhelming its servers or 48f063d76aSMatthew Dillonnetwork stack. Some D.O.S. attacks try to take advantages of bugs in the 49f063d76aSMatthew Dillonnetworking stack to crash a machine with a single packet. The latter can 50f063d76aSMatthew Dillononly be fixed by applying a bug fix to the kernel. Attacks on servers can 51f063d76aSMatthew Dillonoften be fixed by properly specifying options to servers to limit the load 52f063d76aSMatthew Dillonthey incur on the system under adverse conditions. Brute-force network 53f063d76aSMatthew Dillonattacks are harder to deal with. A spoofed-packet attack, for example, is 54f063d76aSMatthew Dillonnearly impossible to stop short of cutting your system off from the internet. 55f063d76aSMatthew Dillon.Pp 56f063d76aSMatthew DillonA user account compromise is even more common then a D.O.S. attack. Many 576ac7e896SDavid E. O'Briensysadmins still run standard telnetd, rlogind, rshd, and ftpd servers on their 58f063d76aSMatthew Dillonmachines. These servers, by default, do not operate over encrypted 59f063d76aSMatthew Dillonconnections. The result is that if you have any moderate-sized user base, 60f063d76aSMatthew Dillonone or more of your users logging into your system from a remote location 61568e4cbbSGuy Helmer.Po 62568e4cbbSGuy Helmerwhich is the most common and convenient way to login to a system 63568e4cbbSGuy Helmer.Pc 64568e4cbbSGuy Helmerwill 65f063d76aSMatthew Dillonhave his or her password sniffed. The attentive system admin will analyze 666ac7e896SDavid E. O'Brienhis remote access logs occasionally looking for suspicious source addresses 67f063d76aSMatthew Dilloneven for successful logins. 68f063d76aSMatthew Dillon.Pp 69f063d76aSMatthew DillonOne must always assume that once an attacker has access to a user account, 70f063d76aSMatthew Dillonthe attacker can break root. However, the reality is that in a well secured 71f063d76aSMatthew Dillonand maintained system, access to a user account does not necessarily give the 72f063d76aSMatthew Dillonattacker access to root. The distinction is important because without access 73f063d76aSMatthew Dillonto root the attacker cannot generally hide his tracks and may, at best, be 74f063d76aSMatthew Dillonable to remove that user's files and crash the machine, but not touch anyone 75f063d76aSMatthew Dillonelse's files. 76f063d76aSMatthew Dillon.Pp 77f063d76aSMatthew DillonSystem administrators must keep in mind that there are several ways to break 78f063d76aSMatthew Dillonroot on a machine. The attacker may know the root password, the attacker 79f063d76aSMatthew Dillonmay find a bug in a root-run server and be able to break root over a network 80f063d76aSMatthew Dillonconnection to that server, or the attacker may know of a bug in an suid-root 81f063d76aSMatthew Dillonprogram that allows the attacker to break root once he has broken into a 82f063d76aSMatthew Dillonuser's account. 83f063d76aSMatthew Dillon.Pp 84568e4cbbSGuy HelmerSecurity remedies are always implemented in a multi-layered 85568e4cbbSGuy Helmer.Sq onion peel 86f063d76aSMatthew Dillonapproach and can be categorized as follows: 87f063d76aSMatthew Dillon.Bl -enum -offset indent 88f063d76aSMatthew Dillon.It 89f063d76aSMatthew DillonSecuring root and staff accounts 90f063d76aSMatthew Dillon.It 91f063d76aSMatthew DillonSecuring root - root-run servers and suid/sgid binaries 92f063d76aSMatthew Dillon.It 93f063d76aSMatthew DillonSecuring user accounts 94f063d76aSMatthew Dillon.It 95f063d76aSMatthew DillonSecuring the password file 96f063d76aSMatthew Dillon.It 97f063d76aSMatthew DillonSecuring the kernel core, raw devices, and filesystems 98f063d76aSMatthew Dillon.It 996ac7e896SDavid E. O'BrienChecking file integrity: binaries, configuration files, and so forth 100f063d76aSMatthew Dillon.It 101f063d76aSMatthew DillonParanoia 102f063d76aSMatthew Dillon.El 103f063d76aSMatthew Dillon.Sh SECURING THE ROOT ACCOUNT AND SECURING STAFF ACCOUNTS 104f063d76aSMatthew Dillon.Pp 105f063d76aSMatthew DillonDon't bother securing staff accounts if you haven't secured the root 106f063d76aSMatthew Dillonaccount. Most systems have a password assigned to the root account. The 107568e4cbbSGuy Helmerfirst thing you do is assume that the password is 108568e4cbbSGuy Helmer.Sq always 109568e4cbbSGuy Helmercompromised. 110f063d76aSMatthew DillonTo secure the root account you make sure that it is not possible to login 111f063d76aSMatthew Dillonto the root account using the root password from a random user account or 112f063d76aSMatthew Dillonover the network. If you haven't already, configure telnetd, rlogind, and 113f063d76aSMatthew Dillonall other servers that handle login operations to refuse root logins, period, 114f063d76aSMatthew Dillonwhether the right password is given or not. Allow direct root logins only 115568e4cbbSGuy Helmervia the system console. The 116568e4cbbSGuy Helmer.Sq Pa /etc/ttys 117568e4cbbSGuy Helmerfile comes in handy here and is 1187626ae52SMatthew Dillonsecure by default on most systems, but a good sysadmin always checks to make 1197626ae52SMatthew Dillonsure. 120f063d76aSMatthew Dillon.Pp 1217626ae52SMatthew DillonOf course, as a sysadmin you have to be able to get to root, so we open up 122f063d76aSMatthew Dillona few holes. But we make sure these holes require additional password 123f063d76aSMatthew Dillonverification to operate. One way to make root accessible is to add appropriate 124568e4cbbSGuy Helmerstaff accounts to the wheel group 125568e4cbbSGuy Helmer.Pq in Pa /etc/group . 126568e4cbbSGuy HelmerThe staff members placed 127568e4cbbSGuy Helmerin the wheel group are allowed to 128568e4cbbSGuy Helmer.Sq su 129568e4cbbSGuy Helmerto root. You should never give staff 130f063d76aSMatthew Dillonmembers native wheel access via their entry in the password file... put staff 131568e4cbbSGuy Helmerin a 132568e4cbbSGuy Helmer.Sq staff 133568e4cbbSGuy Helmergroup or something and only add those that really need root to 1346ac7e896SDavid E. O'Brienthe wheel group. Unfortunately the wheel mechanism still allows an intruder to 1356ac7e896SDavid E. O'Brienbreak root if the intruder has gotten hold of your password file - he need only 136f063d76aSMatthew Dillonbreak the root password and the password of one of the staff accounts that 1376ac7e896SDavid E. O'Brienhappens to be in the wheel group. So while the wheel mechanism is usable, 138f063d76aSMatthew Dillonit isn't much safer then not having a wheel group at all. 139f063d76aSMatthew Dillon.Pp 140f063d76aSMatthew DillonAn indirect way to secure the root account is to secure your staff accounts 141f063d76aSMatthew Dillonby using an alternative login access method and *'ing out the crypted password 1426ac7e896SDavid E. O'Brienfor the staff accounts. This way an intruder may be able to steal the password 143f063d76aSMatthew Dillonfile but will not be able to break into any staff accounts (or, indirectly, 144f063d76aSMatthew Dillonroot, even if root has a crypted password associated with it). Staff members 145f063d76aSMatthew Dillonget into their staff accounts through a secure login mechanism such as 146568e4cbbSGuy Helmer.Xr kerberos 1 147568e4cbbSGuy Helmeror 148568e4cbbSGuy Helmer.Xr ssh 1 149568e4cbbSGuy Helmer.Po 150568e4cbbSGuy Helmersee 151568e4cbbSGuy Helmer.Pa /usr/ports/security/ssh 152568e4cbbSGuy Helmer.Pc 153568e4cbbSGuy Helmerusing a private/public 154f063d76aSMatthew Dillonkey pair. When you use something like kerberos you generally must secure 155f063d76aSMatthew Dillonthe machines which run the kerberos servers and your desktop workstation. 156f063d76aSMatthew DillonWhen you use a public/private key pair with ssh, you must generally secure 157568e4cbbSGuy Helmerthe machine you are logging in FROM 158568e4cbbSGuy Helmer.Pq typically your workstation , 159568e4cbbSGuy Helmerbut you can 160f063d76aSMatthew Dillonalso add an additional layer of protection to the key pair by password 161568e4cbbSGuy Helmerprotecting the keypair when you create it with 162568e4cbbSGuy Helmer.Xr ssh-keygen 1 . 163568e4cbbSGuy HelmerBeing able 1646ac7e896SDavid E. O'Briento *-out the passwords for staff accounts also guarantees that staff members 165f063d76aSMatthew Dilloncan only login through secure access methods that you have setup. You can 166f063d76aSMatthew Dillonthus force all staff members to use secure, encrypted connections for 1676ac7e896SDavid E. O'Brienall their sessions which closes an important hole used by many intruders: That 168f063d76aSMatthew Dillonof sniffing the network from an unrelated, less secure machine. 169f063d76aSMatthew Dillon.Pp 170f063d76aSMatthew DillonThe more indirect security mechanisms also assume that you are logging in 171f063d76aSMatthew Dillonfrom a more restrictive server to a less restrictive server. For example, 172f063d76aSMatthew Dillonif your main box is running all sorts of servers, your workstation shouldn't 173f063d76aSMatthew Dillonbe running any. In order for your workstation to be reasonably secure 174f063d76aSMatthew Dillonyou should run as few servers as possible, up to and including no servers 175f063d76aSMatthew Dillonat all, and you should run a password-protected screen blanker. 176f063d76aSMatthew DillonOf course, given physical access to 177f063d76aSMatthew Dillona workstation an attacker can break any sort of security you put on it. 178f063d76aSMatthew DillonThis is definitely a problem that you should consider but you should also 1796ac7e896SDavid E. O'Brienconsider the fact that the vast majority of break-ins occur remotely, over 1807626ae52SMatthew Dillona network, from people who do not have physical access to your workstation or 181f063d76aSMatthew Dillonservers. 182f063d76aSMatthew Dillon.Pp 183f063d76aSMatthew DillonUsing something like kerberos also gives you the ability to disable or 184f063d76aSMatthew Dillonchange the password for a staff account in one place and have it immediately 185f063d76aSMatthew Dilloneffect all the machine the staff member may have an account on. If a staff 186f063d76aSMatthew Dillonmember's account gets compromised, the ability to instantly change his 187f063d76aSMatthew Dillonpassword on all machines should not be underrated. With discrete passwords, 188f063d76aSMatthew Dillonchanging a password on N machines can be a mess. You can also impose 189f063d76aSMatthew Dillonre-passwording restrictions with kerberos: not only can a kerberos ticket 190f063d76aSMatthew Dillonbe made to timeout after a while, but the kerberos system can require that 191568e4cbbSGuy Helmerthe user choose a new password after a certain period of time 192568e4cbbSGuy Helmer.Pq say, once a month . 193f063d76aSMatthew Dillon.Sh SECURING ROOT - ROOT-RUN SERVERS AND SUID/SGID BINARIES 194f063d76aSMatthew Dillon.Pp 1957626ae52SMatthew DillonThe prudent sysadmin only runs the servers he needs to, no more, no less. Be 196f063d76aSMatthew Dillonaware that third party servers are often the most bug-prone. For example, 197f063d76aSMatthew Dillonrunning an old version of imapd or popper is like giving a universal root 198f063d76aSMatthew Dillonticket out to the entire world. Never run a server that you have not checked 199f063d76aSMatthew Dillonout carefully. Many servers do not need to be run as root. For example, 200568e4cbbSGuy Helmerthe ntalk, comsat, and finger daemons can be run in special user 201568e4cbbSGuy Helmer.Sq sandboxes . 2026ac7e896SDavid E. O'BrienA sandbox isn't perfect unless you go to a large amount of trouble, but the 203f063d76aSMatthew Dillononion approach to security still stands: If someone is able to break in 204f063d76aSMatthew Dillonthrough a server running in a sandbox, they still have to break out of the 205f063d76aSMatthew Dillonsandbox. The more layers the attacker must break through, the lower the 206f063d76aSMatthew Dillonlikelihood of his success. Root holes have historically been found in 207f063d76aSMatthew Dillonvirtually every server ever run as root, including basic system servers. 208f063d76aSMatthew DillonIf you are running a machine through which people only login via sshd and 209f063d76aSMatthew Dillonnever login via telnetd or rshd or rlogind, then turn off those services! 210f063d76aSMatthew Dillon.Pp 211f6f8f44dSAlexey Zelkin.Fx 212568e4cbbSGuy Helmernow defaults to running ntalkd, comsat, and finger in a sandbox. 213f063d76aSMatthew DillonAnother program which may be a candidate for running in a sandbox is 214568e4cbbSGuy Helmer.Xr named 8 . 215568e4cbbSGuy HelmerThe default rc.conf includes the arguments necessary to run 216f063d76aSMatthew Dillonnamed in a sandbox in a commented-out form. Depending on whether you 217f063d76aSMatthew Dillonare installing a new system or upgrading an existing system, the special 218f063d76aSMatthew Dillonuser accounts used by these sandboxes may not be installed. The prudent 2197626ae52SMatthew Dillonsysadmin would research and implement sandboxes for servers whenever possible. 220f063d76aSMatthew Dillon.Pp 221f063d76aSMatthew DillonThere are a number of other servers that typically do not run in sandboxes: 222f063d76aSMatthew Dillonsendmail, popper, imapd, ftpd, and others. There are alternatives to 223f063d76aSMatthew Dillonsome of these, but installing them may require more work then you are willing 224568e4cbbSGuy Helmerto put 225568e4cbbSGuy Helmer.Pq the convenience factor strikes again . 226568e4cbbSGuy HelmerYou may have to run these 2276ac7e896SDavid E. O'Brienservers as root and rely on other mechanisms to detect break-ins that might 228f063d76aSMatthew Dillonoccur through them. 229f063d76aSMatthew Dillon.Pp 230f063d76aSMatthew DillonThe other big potential root hole in a system are the suid-root and sgid 231f063d76aSMatthew Dillonbinaries installed on the system. Most of these binaries, such as rlogin, 232568e4cbbSGuy Helmerreside in 233568e4cbbSGuy Helmer.Pa /bin , 234568e4cbbSGuy Helmer.Pa /sbin , 235568e4cbbSGuy Helmer.Pa /usr/bin , 236568e4cbbSGuy Helmeror 237568e4cbbSGuy Helmer.Pa /usr/sbin . 238568e4cbbSGuy HelmerWhile nothing is 100% safe, 239f063d76aSMatthew Dillonthe system-default suid and sgid binaries can be considered reasonably safe. 2406ac7e896SDavid E. O'BrienStill, root holes are occasionally found in these binaries. A root hole 241568e4cbbSGuy Helmerwas found in Xlib in 1998 that made xterm 242568e4cbbSGuy Helmer.Pq which is typically suid 243568e4cbbSGuy Helmervulnerable. 2447626ae52SMatthew DillonIt is better to be safe then sorry and the prudent sysadmin will restrict suid 245f063d76aSMatthew Dillonbinaries that only staff should run to a special group that only staff can 246568e4cbbSGuy Helmeraccess, and get rid of 247568e4cbbSGuy Helmer.Pq chmod 000 248568e4cbbSGuy Helmerany suid binaries that nobody uses. A 249f063d76aSMatthew Dillonserver with no display generally does not need an xterm binary. Sgid binaries 2506ac7e896SDavid E. O'Briencan be almost as dangerous. If an intruder can break an sgid-kmem binary the 251568e4cbbSGuy Helmerintruder might be able to read 252568e4cbbSGuy Helmer.Pa /dev/kmem 253568e4cbbSGuy Helmerand thus read the crypted password 2546ac7e896SDavid E. O'Brienfile, potentially compromising any passworded account. An intruder that breaks 255f6c24291SGuy Helmerthe tty group can write to almost any user's tty. If a user is running a terminal 2566ac7e896SDavid E. O'Brienprogram or emulator with a talk-back feature, the intruder can potentially 257f063d76aSMatthew Dillongenerate a data stream that causes the user's terminal to echo a command, which 258f063d76aSMatthew Dillonis then run as that user. 259f063d76aSMatthew Dillon.Sh SECURING USER ACCOUNTS 260f063d76aSMatthew Dillon.Pp 261f063d76aSMatthew DillonUser accounts are usually the most difficult to secure. While you can impose 2626ac7e896SDavid E. O'BrienDraconian access restrictions on your staff and *-out their passwords, you 263f063d76aSMatthew Dillonmay not be able to do so with any general user accounts you might have. If 264f063d76aSMatthew Dillonyou do have sufficient control then you may win out and be able to secure the 265f063d76aSMatthew Dillonuser accounts properly. If not, you simply have to be more vigilant in your 266f063d76aSMatthew Dillonmonitoring of those accounts. Use of ssh and kerberos for user accounts is 267f063d76aSMatthew Dillonmore problematic, but still a very good solution compared to a crypted 268f063d76aSMatthew Dillonpassword. 269f063d76aSMatthew Dillon.Sh SECURING THE PASSWORD FILE 270f063d76aSMatthew Dillon.Pp 271f063d76aSMatthew DillonThe only sure fire way is to *-out as many passwords as you can and 272f063d76aSMatthew Dillonuse ssh or kerberos for access to those accounts. Even though the 273568e4cbbSGuy Helmercrypted password file 274568e4cbbSGuy Helmer.Pq Pa /etc/spwd.db 275568e4cbbSGuy Helmercan only be read by root, it may 276568e4cbbSGuy Helmerbe possible for an intruder to obtain read access to that file even if the 277f063d76aSMatthew Dillonattacker cannot obtain root-write access. 278f063d76aSMatthew Dillon.Pp 279f063d76aSMatthew DillonYour security scripts should always check for and report changes to 280568e4cbbSGuy Helmerthe password file 281568e4cbbSGuy Helmer.Po 282568e4cbbSGuy Helmersee 283568e4cbbSGuy Helmer.Sq Checking file integrity 284568e4cbbSGuy Helmerbelow 285568e4cbbSGuy Helmer.Pc . 286f063d76aSMatthew Dillon.Sh SECURING THE KERNEL CORE, RAW DEVICES, AND FILESYSTEMS 287f063d76aSMatthew Dillon.Pp 288f063d76aSMatthew DillonIf an attacker breaks root he can do just about anything, but there 289f063d76aSMatthew Dillonare certain conveniences. For example, most modern kernels have a 290568e4cbbSGuy Helmerpacket sniffing device driver built in. Under 291f6f8f44dSAlexey Zelkin.Fx 292568e4cbbSGuy Helmerit is called 293568e4cbbSGuy Helmerthe 294568e4cbbSGuy Helmer.Sq bpf 295568e4cbbSGuy Helmerdevice. An intruder will commonly attempt to run a packet sniffer 2966ac7e896SDavid E. O'Brienon a compromised machine. You do not need to give the intruder the 297f063d76aSMatthew Dilloncapability and most systems should not have the bpf device compiled in. 298f063d76aSMatthew Dillon.Pp 299568e4cbbSGuy HelmerBut even if you turn off the bpf device, 300568e4cbbSGuy Helmeryou still have 301568e4cbbSGuy Helmer.Pa /dev/mem 302568e4cbbSGuy Helmerand 303568e4cbbSGuy Helmer.Pa /dev/kmem 304568e4cbbSGuy Helmerto worry about. For that matter, 305568e4cbbSGuy Helmerthe intruder can still write raw devices. 306568e4cbbSGuy HelmerAlso, there is another kernel feature called 307568e4cbbSGuy Helmer.Xr kldload 8 . 308568e4cbbSGuy HelmerAn enterprising intruder can use a KLD module to install 309568e4cbbSGuy Helmerhis own bpf device or other sniffing device on a running kernel. 310568e4cbbSGuy HelmerTo avoid these problems you have to run 311568e4cbbSGuy Helmerthe kernel at a higher secure level, at least securelevel 1. The securelevel 312f063d76aSMatthew Dilloncan be set with a sysctl on the kern.securelevel variable. Once you have 313f063d76aSMatthew Dillonset the securelevel to 1, write access to raw devices will be denied and 314568e4cbbSGuy Helmerspecial chflags flags, such as 315568e4cbbSGuy Helmer.Sq schg , 316568e4cbbSGuy Helmerwill be enforced. You must also ensure 317568e4cbbSGuy Helmerthat the 318568e4cbbSGuy Helmer.Sq schg 319568e4cbbSGuy Helmerflag is set on critical startup binaries, directories, and 320f063d76aSMatthew Dillonscript files - everything that gets run up to the point where the securelevel 321f063d76aSMatthew Dillonis set. This might be overdoing it, and upgrading the system is much more 322f063d76aSMatthew Dillondifficult when you operate at a higher secure level. You may compromise and 323f063d76aSMatthew Dillonrun the system at a higher secure level but not set the schg flag for every 324f063d76aSMatthew Dillonsystem file and directory under the sun. 325f063d76aSMatthew Dillon.Sh CHECKING FILE INTEGRITY: BINARIES, CONFIG FILES, ETC 326f063d76aSMatthew Dillon.Pp 327f063d76aSMatthew DillonWhen it comes right down to it, you can only protect your core system 328f063d76aSMatthew Dillonconfiguration and control files so much before the convenience factor 329f063d76aSMatthew Dillonrears its ugly head. The last layer of your security onion is perhaps 330f063d76aSMatthew Dillonthe most important - detection. 331f063d76aSMatthew Dillon.Pp 332f063d76aSMatthew DillonThe only correct way to check a system's file integrity is via another, 333568e4cbbSGuy Helmermore secure system. It is fairly easy to setup a 334568e4cbbSGuy Helmer.Sq secure 335568e4cbbSGuy Helmersystem: you 336f063d76aSMatthew Dillonsimply do not run any services on it. With a secure system in place you 337f063d76aSMatthew Dilloncan then give it access to other system's root spaces via ssh. This may 338f063d76aSMatthew Dillonseem like a security breech, but you have to put your trust somewhere and 339f063d76aSMatthew Dillonas long as you don't do something stupid like run random servers it really 340568e4cbbSGuy Helmeris possible to build a secure machine. When I say 341568e4cbbSGuy Helmer.Sq secure 342568e4cbbSGuy Helmerhere, I assuming 343f063d76aSMatthew Dillonphysical access security as well, of course. Given a secure machine with 344f063d76aSMatthew Dillonroot access on all your other machines, you can then write security scripts 345f063d76aSMatthew DillonON the secure machine to check the other machines on the system. The most 346568e4cbbSGuy Helmercommon way of checking is to have the security script 347568e4cbbSGuy Helmer.Xr scp 1 348568e4cbbSGuy Helmerover a find 349f063d76aSMatthew Dillonand md5 binary and then ssh a shell command to the remote machine to md5 350568e4cbbSGuy Helmerall the files in the system 351568e4cbbSGuy Helmer.Po 352568e4cbbSGuy Helmeror, at least, the 353568e4cbbSGuy Helmer.Pa / , 354568e4cbbSGuy Helmer.Pa /var , 355568e4cbbSGuy Helmerand 356568e4cbbSGuy Helmer.Pa /usr 357568e4cbbSGuy Helmerpartitions! 358568e4cbbSGuy Helmer.Pc . 359f063d76aSMatthew DillonThe security machine copies the results to a file and diff's them against 360f063d76aSMatthew Dillonresults from a previous run (or compares the results against its own 361f063d76aSMatthew Dillonbinaries), then emails each staff member a daily report of differences. 362f063d76aSMatthew Dillon.Pp 363f063d76aSMatthew DillonAnother way to do this sort of check is to NFS export the major filesystems 364f063d76aSMatthew Dillonfrom every other machine to the security machine. This is somewhat more 3656ac7e896SDavid E. O'Briennetwork intensive but also virtually impossible for an intruder to detect 366f063d76aSMatthew Dillonor spoof. 367f063d76aSMatthew Dillon.Pp 368f063d76aSMatthew DillonA good security script will also check for changes to user and staff members 369f063d76aSMatthew Dillonaccess configuration files: .rhosts, .shosts, .ssh/authorized_keys, and 370568e4cbbSGuy Helmerso forth... files that might fall outside the purview of the MD5 check. 371f063d76aSMatthew Dillon.Pp 372f063d76aSMatthew DillonA good security script will check for suid and sgid binaries on all 3736ac7e896SDavid E. O'Brienfilesystems and report their absolute existence as well as a diff against 374568e4cbbSGuy Helmerthe previous report or some baseline 375568e4cbbSGuy Helmer.Pq say, make a baseline once a week . 376f063d76aSMatthew DillonWhile you can turn off the ability to run suid and sgid binaries on certain 377568e4cbbSGuy Helmerfilesystems through the 378568e4cbbSGuy Helmer.Sq nosuid 379568e4cbbSGuy Helmeroption in fstab/mount, you cannot turn this 380568e4cbbSGuy Helmeroff on root and anyone who breaks root can just install their binary there. 381f063d76aSMatthew DillonIf you have a huge amount of user disk space, though, it may be useful to 382568e4cbbSGuy Helmerdisallow suid binaries and devices 383568e4cbbSGuy Helmer.Po 384568e4cbbSGuy Helmer.Sq nodev 385568e4cbbSGuy Helmeroption 386568e4cbbSGuy Helmer.Pc 387568e4cbbSGuy Helmeron the user partitions 388f063d76aSMatthew Dillonso you do not have to scan them for such. I would scan them anyway, though, 389f063d76aSMatthew Dillonat least once a week, since the object of this onion layer is detection of 3906ac7e896SDavid E. O'Briena break-in. 391f063d76aSMatthew Dillon.Pp 392568e4cbbSGuy HelmerProcess accounting 393568e4cbbSGuy Helmer.Po 394568e4cbbSGuy Helmersee 395f437b38cSChris Costello.Xr accton 8 396568e4cbbSGuy Helmer.Pc 397568e4cbbSGuy Helmeris a relatively low-overhead feature of 3986ac7e896SDavid E. O'Brienthe operating system which I recommend using as a post-break-in evaluation 3996ac7e896SDavid E. O'Brienmechanism. It is especially useful in tracking down how an intruder has 400f063d76aSMatthew Dillonactually broken root on a system, assuming the file is still intact after 4016ac7e896SDavid E. O'Brienthe break-in occurs. 402f063d76aSMatthew Dillon.Pp 403f063d76aSMatthew DillonFinally, security scripts should process the log files and the logs themselves 404f063d76aSMatthew Dillonshould be generated in as secured a manner as possible - remote syslog can be 4056ac7e896SDavid E. O'Brienvery useful. An intruder tries to cover his tracks, and log files are critical 4066ac7e896SDavid E. O'Briento the sysadmin trying to track down the time and method of the initial break-in. 407f063d76aSMatthew Dillon.Sh PARANOIA 408f063d76aSMatthew Dillon.Pp 4097626ae52SMatthew DillonA little paranoia never hurts. As a rule, a sysadmin can add any number 410f063d76aSMatthew Dillonof security features as long as they do not effect convenience, and 411f063d76aSMatthew Dilloncan add security features that do effect convenience with some added 412f063d76aSMatthew Dillonthought. 413f063d76aSMatthew Dillon.Sh SPECIAL SECTION ON D.O.S. ATTACKS 414f063d76aSMatthew Dillon.Pp 4156ac7e896SDavid E. O'BrienThis section covers Denial of Service attacks. A DOS attack is typically 416f063d76aSMatthew Dillona packet attack. While there isn't much you can do about modern spoofed 417f063d76aSMatthew Dillonpacket attacks that saturate your network, you can generally limit the damage 418f063d76aSMatthew Dillonby ensuring that the attacks cannot take down your servers. 419f063d76aSMatthew Dillon.Bl -enum -offset indent 420f063d76aSMatthew Dillon.It 421f063d76aSMatthew DillonLimiting server forks 422f063d76aSMatthew Dillon.It 423f063d76aSMatthew DillonLimiting springboard attacks (ICMP response attacks, ping broadcast, etc...) 424f063d76aSMatthew Dillon.It 425f063d76aSMatthew DillonKernel Route Cache 426f063d76aSMatthew Dillon.El 427f063d76aSMatthew Dillon.Pp 428f063d76aSMatthew DillonA common DOS attack is against a forking server that attempts to cause the 4296ac7e896SDavid E. O'Brienserver to eat processes, file descriptors, and memory until the machine 430568e4cbbSGuy Helmerdies. Inetd 431568e4cbbSGuy Helmer.Po 432568e4cbbSGuy Helmersee 433568e4cbbSGuy Helmer.Xr inetd 8 434568e4cbbSGuy Helmer.Pc 435568e4cbbSGuy Helmerhas several options to limit this sort of attack. 436f063d76aSMatthew DillonIt should be noted that while it is possible to prevent a machine from going 437f063d76aSMatthew Dillondown it is not generally possible to prevent a service from being disrupted 438f063d76aSMatthew Dillonby the attack. Read the inetd manual page carefully and pay specific attention 439568e4cbbSGuy Helmerto the 440568e4cbbSGuy Helmer.Fl c , 441568e4cbbSGuy Helmer.Fl C , 442568e4cbbSGuy Helmerand 443568e4cbbSGuy Helmer.Fl R 444568e4cbbSGuy Helmeroptions. Note that spoofed-IP attacks will circumvent 445568e4cbbSGuy Helmerthe 446568e4cbbSGuy Helmer.Fl C 447568e4cbbSGuy Helmeroption to inetd, so typically a combination of options must be used. 448f063d76aSMatthew DillonSome standalone servers have self-fork-limitation parameters. 449f063d76aSMatthew Dillon.Pp 450568e4cbbSGuy HelmerSendmail has its 451568e4cbbSGuy Helmer.Fl OMaxDaemonChildren 452568e4cbbSGuy Helmeroption which tends to work much 453f6c24291SGuy Helmerbetter than trying to use sendmail's load limiting options due to the 454568e4cbbSGuy Helmerload lag. You should specify a 455568e4cbbSGuy Helmer.Cm MaxDaemonChildren 456568e4cbbSGuy Helmerparameter when you start 457f063d76aSMatthew Dillonsendmail high enough to handle your expected load but no so high that the 458f063d76aSMatthew Dilloncomputer cannot handle that number of sendmails without falling on its face. 459568e4cbbSGuy HelmerIt is also prudent to run sendmail in queued mode 460568e4cbbSGuy Helmer.Pq Fl ODeliveryMode=queued 461568e4cbbSGuy Helmerand to run the daemon 462568e4cbbSGuy Helmer.Pq Cm sendmail -bd 463568e4cbbSGuy Helmerseparate from the queue-runs 464568e4cbbSGuy Helmer.Pq Cm sendmail -q15m . 465568e4cbbSGuy HelmerIf you still want realtime delivery you can run the queue 466568e4cbbSGuy Helmerat a much lower interval, such as 467568e4cbbSGuy Helmer.Fl q1m , 468568e4cbbSGuy Helmerbut be sure to specify a reasonable 469568e4cbbSGuy Helmer.Cm MaxDaemonChildren 470568e4cbbSGuy Helmeroption for that sendmail to prevent cascade failures. 471f063d76aSMatthew Dillon.Pp 472f063d76aSMatthew DillonSyslogd can be attacked directly and it is strongly recommended that you use 473568e4cbbSGuy Helmerthe 474568e4cbbSGuy Helmer.Fl s 475568e4cbbSGuy Helmeroption whenever possible, and the 476568e4cbbSGuy Helmer.Fl a 477568e4cbbSGuy Helmeroption otherwise. 478f063d76aSMatthew Dillon.Pp 479f063d76aSMatthew DillonYou should also be fairly careful 480f063d76aSMatthew Dillonwith connect-back services such as tcpwrapper's reverse-identd, which can 481f063d76aSMatthew Dillonbe attacked directly. You generally do not want to use the reverse-ident 482f063d76aSMatthew Dillonfeature of tcpwrappers for this reason. 483f063d76aSMatthew Dillon.Pp 484f063d76aSMatthew DillonIt is a very good idea to protect internal services from external access 485f063d76aSMatthew Dillonby firewalling them off at your border routers. The idea here is to prevent 486f063d76aSMatthew Dillonsaturation attacks from outside your LAN, not so much to protect internal 48785752545SGuy Helmerservices from network-based root compromise. Always configure an exclusive 488568e4cbbSGuy Helmerfirewall, i.e. 489568e4cbbSGuy Helmer.So 490568e4cbbSGuy Helmerfirewall everything *except* ports A, B, C, D, and M-Z 491568e4cbbSGuy Helmer.Sc . 492568e4cbbSGuy HelmerThis 493f063d76aSMatthew Dillonway you can firewall off all of your low ports except for certain specific 494568e4cbbSGuy Helmerservices such as named 495568e4cbbSGuy Helmer.Pq if you are primary for a zone , 496568e4cbbSGuy Helmerntalkd, sendmail, 497f063d76aSMatthew Dillonand other internet-accessible services. 498f063d76aSMatthew DillonIf you try to configure the firewall the other 499f063d76aSMatthew Dillonway - as an inclusive or permissive firewall, there is a good chance that you 500568e4cbbSGuy Helmerwill forget to 501568e4cbbSGuy Helmer.Sq close 502568e4cbbSGuy Helmera couple of services or that you will add a new internal 503f063d76aSMatthew Dillonservice and forget to update the firewall. You can still open up the 504f063d76aSMatthew Dillonhigh-numbered port range on the firewall to allow permissive-like operation 505568e4cbbSGuy Helmerwithout compromising your low ports. Also take note that 506f6f8f44dSAlexey Zelkin.Fx 507568e4cbbSGuy Helmerallows you to 508f063d76aSMatthew Dilloncontrol the range of port numbers used for dynamic binding via the various 509568e4cbbSGuy Helmernet.inet.ip.portrange sysctl's 510568e4cbbSGuy Helmer.Pq sysctl -a \&| fgrep portrange , 511568e4cbbSGuy Helmerwhich can also 512f063d76aSMatthew Dillonease the complexity of your firewall's configuration. I usually use a normal 513f063d76aSMatthew Dillonfirst/last range of 4000 to 5000, and a hiport range of 49152 to 65535, then 514568e4cbbSGuy Helmerblock everything under 4000 off in my firewall 515568e4cbbSGuy Helmer.Po 516568e4cbbSGuy Helmerexcept for certain specific 517568e4cbbSGuy Helmerinternet-accessible ports, of course 518568e4cbbSGuy Helmer.Pc . 519f063d76aSMatthew Dillon.Pp 520f063d76aSMatthew DillonAnother common DOS attack is called a springboard attack - to attack a server 521f063d76aSMatthew Dillonin a manner that causes the server to generate responses which then overload 522f063d76aSMatthew Dillonthe server, the local network, or some other machine. The most common attack 523568e4cbbSGuy Helmerof this nature is the ICMP PING BROADCAST attack. The attacker spoofs ping 524f063d76aSMatthew Dillonpackets sent to your LAN's broadcast address with the source IP address set 525f063d76aSMatthew Dillonto the actual machine they wish to attack. If your border routers are not 526f063d76aSMatthew Dillonconfigured to stomp on ping's to broadcast addresses, your LAN winds up 527f063d76aSMatthew Dillongenerating sufficient responses to the spoofed source address to saturate the 528f063d76aSMatthew Dillonvictim, especially when the attacker uses the same trick on several dozen 529f063d76aSMatthew Dillonbroadcast addresses over several dozen different networks at once. Broadcast 530f063d76aSMatthew Dillonattacks of over a hundred and twenty megabits have been measured. A second 531f063d76aSMatthew Dilloncommon springboard attack is against the ICMP error reporting system. By 532f063d76aSMatthew Dillonconstructing packets that generate ICMP error responses, an attacker can 533f063d76aSMatthew Dillonsaturate a server's incoming network and cause the server to saturate its 534f063d76aSMatthew Dillonoutgoing network with ICMP responses. This type of attack can also crash the 535f063d76aSMatthew Dillonserver by running it out of mbuf's, especially if the server cannot drain the 536568e4cbbSGuy HelmerICMP responses it generates fast enough. The 537f6f8f44dSAlexey Zelkin.Fx 538568e4cbbSGuy Helmerkernel has a new kernel 539f063d76aSMatthew Dilloncompile option called ICMP_BANDLIM which limits the effectiveness of these 540f063d76aSMatthew Dillonsorts of attacks. The last major class of springboard attacks is related to 541f063d76aSMatthew Dilloncertain internal inetd services such as the udp echo service. An attacker 542f063d76aSMatthew Dillonsimply spoofs a UDP packet with the source address being server A's echo port, 543f063d76aSMatthew Dillonand the destination address being server B's echo port, where server A and B 544f063d76aSMatthew Dillonare both on your LAN. The two servers then bounce this one packet back and 545f063d76aSMatthew Dillonforth between each other. The attacker can overload both servers and their 546f063d76aSMatthew DillonLANs simply by injecting a few packets in this manner. Similar problems 5477626ae52SMatthew Dillonexist with the internal chargen port. A competent sysadmin will turn off all 548f063d76aSMatthew Dillonof these inetd-internal test services. 549f063d76aSMatthew Dillon.Pp 550f063d76aSMatthew DillonSpoofed packet attacks may also be used to overload the kernel route cache. 551f063d76aSMatthew DillonRefer to the net.inet.ip.rtexpire, rtminexpire, and rtmaxcache sysctl 552f063d76aSMatthew Dillonparameters. A spoofed packet attack that uses a random source IP will cause 553f063d76aSMatthew Dillonthe kernel to generate a temporary cached route in the route table, viewable 554568e4cbbSGuy Helmerwith 555568e4cbbSGuy Helmer.Sq netstat -rna \&| fgrep W3 . 556568e4cbbSGuy HelmerThese routes typically timeout in 1600 557f063d76aSMatthew Dillonseconds or so. If the kernel detects that the cached route table has gotten 558f063d76aSMatthew Dillontoo big it will dynamically reduce the rtexpire but will never decrease it to 559f063d76aSMatthew Dillonless then rtminexpire. There are two problems: (1) The kernel does not react 560f063d76aSMatthew Dillonquickly enough when a lightly loaded server is suddenly attacked, and (2) The 561f063d76aSMatthew Dillonrtminexpire is not low enough for the kernel to survive a sustained attack. 562f063d76aSMatthew DillonIf your servers are connected to the internet via a T3 or better it may be 56385752545SGuy Helmerprudent to manually override both rtexpire and rtminexpire via 56485752545SGuy Helmer.Xr sysctl 8 . 565568e4cbbSGuy HelmerNever set either parameter to zero 566568e4cbbSGuy Helmer.Pq unless you want to crash the machine :-) . 567f063d76aSMatthew DillonSetting both parameters to 2 seconds should be sufficient to protect the route 568f063d76aSMatthew Dillontable from attack. 569f063d76aSMatthew Dillon 570f063d76aSMatthew Dillon.Sh SEE ALSO 571f063d76aSMatthew Dillon.Pp 572f063d76aSMatthew Dillon.Xr accton 1 , 573f063d76aSMatthew Dillon.Xr chflags 1 , 574f063d76aSMatthew Dillon.Xr find 1 , 5756ac7e896SDavid E. O'Brien.Xr kerberos 1 , 576f063d76aSMatthew Dillon.Xr md5 1 , 577f6f8f44dSAlexey Zelkin.Xr netstat 1 , 5786ac7e896SDavid E. O'Brien.Xr syslogd 1 , 5796ac7e896SDavid E. O'Brien.Xr xdm 1 , 580f063d76aSMatthew Dillon.Xr sysctl 8 581f6f8f44dSAlexey Zelkin 582f6f8f44dSAlexey ZelkinThe following are part of security ports collection: 583f6f8f44dSAlexey Zelkin 584f6f8f44dSAlexey Zelkin.Xr ssh 1 , 585f6f8f44dSAlexey Zelkin.Xr sshd 1 586f063d76aSMatthew Dillon.Sh HISTORY 587f063d76aSMatthew DillonThe 588f063d76aSMatthew Dillon.Nm 589568e4cbbSGuy Helmermanual page was originally written by 590568e4cbbSGuy Helmer.An Matthew Dillon 591568e4cbbSGuy Helmerand first appeared 592568e4cbbSGuy Helmerin 59385752545SGuy Helmer.Fx 3.1 , 594568e4cbbSGuy HelmerDecember 1998. 595