15ecb12e3SWarner Losh.\" Copyright (C) 1998 Matthew Dillon. All rights reserved. 25ecb12e3SWarner Losh.\" 35ecb12e3SWarner Losh.\" Redistribution and use in source and binary forms, with or without 45ecb12e3SWarner Losh.\" modification, are permitted provided that the following conditions 55ecb12e3SWarner Losh.\" are met: 65ecb12e3SWarner Losh.\" 1. Redistributions of source code must retain the above copyright 75ecb12e3SWarner Losh.\" notice, this list of conditions and the following disclaimer. 85ecb12e3SWarner Losh.\" 2. Redistributions in binary form must reproduce the above copyright 95ecb12e3SWarner Losh.\" notice, this list of conditions and the following disclaimer in the 105ecb12e3SWarner Losh.\" documentation and/or other materials provided with the distribution. 115ecb12e3SWarner Losh.\" 125ecb12e3SWarner Losh.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 135ecb12e3SWarner Losh.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 145ecb12e3SWarner Losh.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 155ecb12e3SWarner Losh.\" ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 165ecb12e3SWarner Losh.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 175ecb12e3SWarner Losh.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 185ecb12e3SWarner Losh.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 195ecb12e3SWarner Losh.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 205ecb12e3SWarner Losh.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 215ecb12e3SWarner Losh.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 225ecb12e3SWarner Losh.\" SUCH DAMAGE. 23f063d76aSMatthew Dillon.\" 247f3dea24SPeter Wemm.\" $FreeBSD$ 25f063d76aSMatthew Dillon.\" 26e354922cSRuslan Ermilov.Dd November 29, 2004 27f063d76aSMatthew Dillon.Dt SECURITY 7 283d45e180SRuslan Ermilov.Os 29f063d76aSMatthew Dillon.Sh NAME 30f063d76aSMatthew Dillon.Nm security 31454ba768SRuslan Ermilov.Nd introduction to security under 32454ba768SRuslan Ermilov.Fx 33f063d76aSMatthew Dillon.Sh DESCRIPTION 34f063d76aSMatthew DillonSecurity is a function that begins and ends with the system administrator. 35f063d76aSMatthew DillonWhile all 36f063d76aSMatthew Dillon.Bx 37d93b26d6SMatthew Dillonmulti-user systems have some inherent security, the job of building and 38992e4638SRobert Watsonmaintaining additional security mechanisms to keep users 39454ba768SRuslan Ermilov.Dq honest 40568e4cbbSGuy Helmeris probably 41454ba768SRuslan Ermilovone of the single largest undertakings of the sysadmin. 42454ba768SRuslan ErmilovMachines are 43f063d76aSMatthew Dillononly as secure as you make them, and security concerns are ever competing 44568e4cbbSGuy Helmerwith the human necessity for convenience. 45568e4cbbSGuy Helmer.Ux 46568e4cbbSGuy Helmersystems, 476ac7e896SDavid E. O'Brienin general, are capable of running a huge number of simultaneous processes 48454ba768SRuslan Ermilovand many of these processes operate as servers \(em meaning that external 49454ba768SRuslan Ermiloventities can connect and talk to them. 50454ba768SRuslan ErmilovAs yesterday's mini-computers and mainframes 51f063d76aSMatthew Dillonbecome today's desktops, and as computers become networked and internetworked, 52f063d76aSMatthew Dillonsecurity becomes an ever bigger issue. 53f063d76aSMatthew Dillon.Pp 54454ba768SRuslan ErmilovSecurity is best implemented through a layered onion approach. 55454ba768SRuslan ErmilovIn a nutshell, 56d93b26d6SMatthew Dillonwhat you want to do is to create as many layers of security as are convenient 57454ba768SRuslan Ermilovand then carefully monitor the system for intrusions. 58454ba768SRuslan ErmilovYou do not want to 597c86a74bSMike Pritchardoverbuild your security or you will interfere with the detection side, and 60d93b26d6SMatthew Dillondetection is one of the single most important aspects of any security 61454ba768SRuslan Ermilovmechanism. 62454ba768SRuslan ErmilovFor example, it makes little sense to set the 63454ba768SRuslan Ermilov.Cm schg 64d93b26d6SMatthew Dillonflags 65c4d9468eSRuslan Ermilov(see 66c4d9468eSRuslan Ermilov.Xr chflags 1 ) 67d93b26d6SMatthew Dillonon every system binary because while this may temporarily protect the 6847afd1f8SDaniel Harrisbinaries, it prevents an attacker who has broken in from making an 69d93b26d6SMatthew Dilloneasily detectable change that may result in your security mechanisms not 7047afd1f8SDaniel Harrisdetecting the attacker at all. 71d93b26d6SMatthew Dillon.Pp 72454ba768SRuslan ErmilovSystem security also pertains to dealing with various forms of attacks, 73d93b26d6SMatthew Dillonincluding attacks that attempt to crash or otherwise make a system unusable 74454ba768SRuslan Ermilovbut do not attempt to break root. 75454ba768SRuslan ErmilovSecurity concerns can be split up into 76d93b26d6SMatthew Dillonseveral categories: 77f063d76aSMatthew Dillon.Bl -enum -offset indent 78f063d76aSMatthew Dillon.It 79454ba768SRuslan ErmilovDenial of Service attacks (DoS) 80f063d76aSMatthew Dillon.It 81f063d76aSMatthew DillonUser account compromises 82f063d76aSMatthew Dillon.It 836ac7e896SDavid E. O'BrienRoot compromise through accessible servers 84f063d76aSMatthew Dillon.It 856ac7e896SDavid E. O'BrienRoot compromise via user accounts 86d93b26d6SMatthew Dillon.It 87d93b26d6SMatthew DillonBackdoor creation 88f063d76aSMatthew Dillon.El 89f063d76aSMatthew Dillon.Pp 90f063d76aSMatthew DillonA denial of service attack is an action that deprives the machine of needed 91454ba768SRuslan Ermilovresources. 92454ba768SRuslan ErmilovTypically, DoS attacks are brute-force mechanisms that attempt 93f063d76aSMatthew Dillonto crash or otherwise make a machine unusable by overwhelming its servers or 94454ba768SRuslan Ermilovnetwork stack. 95454ba768SRuslan ErmilovSome DoS attacks try to take advantages of bugs in the 96454ba768SRuslan Ermilovnetworking stack to crash a machine with a single packet. 97454ba768SRuslan ErmilovThe latter can 98454ba768SRuslan Ermilovonly be fixed by applying a bug fix to the kernel. 99454ba768SRuslan ErmilovAttacks on servers can 100d93b26d6SMatthew Dillonoften be fixed by properly specifying options to limit the load the servers 101454ba768SRuslan Ermilovincur on the system under adverse conditions. 102454ba768SRuslan ErmilovBrute-force network attacks are harder to deal with. 103454ba768SRuslan ErmilovA spoofed-packet attack, for example, is 1047c86a74bSMike Pritchardnearly impossible to stop short of cutting your system off from the Internet. 1057c86a74bSMike PritchardIt may not be able to take your machine down, but it can fill up Internet 106d93b26d6SMatthew Dillonpipe. 107f063d76aSMatthew Dillon.Pp 108454ba768SRuslan ErmilovA user account compromise is even more common than a DoS attack. 109454ba768SRuslan ErmilovMany 110454ba768SRuslan Ermilovsysadmins still run standard 111454ba768SRuslan Ermilov.Xr telnetd 8 , 112454ba768SRuslan Ermilov.Xr rlogind 8 , 113454ba768SRuslan Ermilov.Xr rshd 8 , 114454ba768SRuslan Ermilovand 115454ba768SRuslan Ermilov.Xr ftpd 8 116454ba768SRuslan Ermilovservers on their machines. 117454ba768SRuslan ErmilovThese servers, by default, do not operate over encrypted 118454ba768SRuslan Ermilovconnections. 119454ba768SRuslan ErmilovThe result is that if you have any moderate-sized user base, 120f063d76aSMatthew Dillonone or more of your users logging into your system from a remote location 121c4d9468eSRuslan Ermilov(which is the most common and convenient way to log in to a system) 122454ba768SRuslan Ermilovwill have his or her password sniffed. 123454ba768SRuslan ErmilovThe attentive system administrator will analyze 124d93b26d6SMatthew Dillonhis remote access logs looking for suspicious source addresses 125f063d76aSMatthew Dilloneven for successful logins. 126f063d76aSMatthew Dillon.Pp 127f063d76aSMatthew DillonOne must always assume that once an attacker has access to a user account, 128454ba768SRuslan Ermilovthe attacker can break root. 129454ba768SRuslan ErmilovHowever, the reality is that in a well secured 130f063d76aSMatthew Dillonand maintained system, access to a user account does not necessarily give the 131454ba768SRuslan Ermilovattacker access to root. 132454ba768SRuslan ErmilovThe distinction is important because without access 133f063d76aSMatthew Dillonto root the attacker cannot generally hide his tracks and may, at best, be 134b94231daSDima Dorfmanable to do nothing more than mess with the user's files or crash the machine. 135d93b26d6SMatthew DillonUser account compromises are very common because users tend not to take the 1367c86a74bSMike Pritchardprecautions that sysadmins take. 137f063d76aSMatthew Dillon.Pp 138d93b26d6SMatthew DillonSystem administrators must keep in mind that there are potentially many ways 139454ba768SRuslan Ermilovto break root on a machine. 140454ba768SRuslan ErmilovThe attacker may know the root password, 141d93b26d6SMatthew Dillonthe attacker 142f063d76aSMatthew Dillonmay find a bug in a root-run server and be able to break root over a network 143454ba768SRuslan Ermilovconnection to that server, or the attacker may know of a bug in an SUID-root 144f063d76aSMatthew Dillonprogram that allows the attacker to break root once he has broken into a 145454ba768SRuslan Ermilovuser's account. 146454ba768SRuslan ErmilovIf an attacker has found a way to break root on a machine, 147f167d7fbSSheldon Hearnthe attacker may not have a need to install a backdoor. 148d93b26d6SMatthew DillonMany of the root holes found and closed to date involve a considerable amount 14947afd1f8SDaniel Harrisof work by the attacker to clean up after himself, so most attackers do install 150454ba768SRuslan Ermilovbackdoors. 151454ba768SRuslan ErmilovThis gives you a convenient way to detect the attacker. 152454ba768SRuslan ErmilovMaking 15347afd1f8SDaniel Harrisit impossible for an attacker to install a backdoor may actually be detrimental 1544c0d8029SDaniel Harristo your security because it will not close off the hole the attacker used to 1554c0d8029SDaniel Harrisbreak in in the first place. 156f063d76aSMatthew Dillon.Pp 157d93b26d6SMatthew DillonSecurity remedies should always be implemented with a multi-layered 158454ba768SRuslan Ermilov.Dq onion peel 159f063d76aSMatthew Dillonapproach and can be categorized as follows: 160f063d76aSMatthew Dillon.Bl -enum -offset indent 161f063d76aSMatthew Dillon.It 162f063d76aSMatthew DillonSecuring root and staff accounts 163f063d76aSMatthew Dillon.It 164454ba768SRuslan ErmilovSecuring root \(em root-run servers and SUID/SGID binaries 165f063d76aSMatthew Dillon.It 166f063d76aSMatthew DillonSecuring user accounts 167f063d76aSMatthew Dillon.It 168f063d76aSMatthew DillonSecuring the password file 169f063d76aSMatthew Dillon.It 170f063d76aSMatthew DillonSecuring the kernel core, raw devices, and file systems 171f063d76aSMatthew Dillon.It 172d93b26d6SMatthew DillonQuick detection of inappropriate changes made to the system 173f063d76aSMatthew Dillon.It 174f063d76aSMatthew DillonParanoia 175f063d76aSMatthew Dillon.El 176f063d76aSMatthew Dillon.Sh SECURING THE ROOT ACCOUNT AND SECURING STAFF ACCOUNTS 177454ba768SRuslan ErmilovDo not bother securing staff accounts if you have not secured the root 178454ba768SRuslan Ermilovaccount. 179454ba768SRuslan ErmilovMost systems have a password assigned to the root account. 180454ba768SRuslan ErmilovThe 181568e4cbbSGuy Helmerfirst thing you do is assume that the password is 182454ba768SRuslan Ermilov.Em always 183454ba768SRuslan Ermilovcompromised. 184454ba768SRuslan ErmilovThis does not mean that you should remove the password. 185454ba768SRuslan ErmilovThe 186d93b26d6SMatthew Dillonpassword is almost always necessary for console access to the machine. 187d93b26d6SMatthew DillonWhat it does mean is that you should not make it possible to use the password 188d93b26d6SMatthew Dillonoutside of the console or possibly even with a 189d93b26d6SMatthew Dillon.Xr su 1 190454ba768SRuslan Ermilovutility. 191454ba768SRuslan ErmilovFor example, make sure that your PTYs are specified as being 192454ba768SRuslan Ermilov.Dq Li unsecure 193d93b26d6SMatthew Dillonin the 194454ba768SRuslan Ermilov.Pa /etc/ttys 195d93b26d6SMatthew Dillonfile 196454ba768SRuslan Ermilovso that direct root logins via 197454ba768SRuslan Ermilov.Xr telnet 1 198454ba768SRuslan Ermilovor 199454ba768SRuslan Ermilov.Xr rlogin 1 200454ba768SRuslan Ermilovare disallowed. 201454ba768SRuslan ErmilovIf using 202454ba768SRuslan Ermilovother login services such as 203454ba768SRuslan Ermilov.Xr sshd 8 , 204454ba768SRuslan Ermilovmake sure that direct root logins are 205454ba768SRuslan Ermilovdisabled there as well. 206454ba768SRuslan ErmilovConsider every access method \(em services such as 207454ba768SRuslan Ermilov.Xr ftp 1 208454ba768SRuslan Ermilovoften fall through the cracks. 209454ba768SRuslan ErmilovDirect root logins should only be allowed 210d93b26d6SMatthew Dillonvia the system console. 211f063d76aSMatthew Dillon.Pp 2127626ae52SMatthew DillonOf course, as a sysadmin you have to be able to get to root, so we open up 213454ba768SRuslan Ermilova few holes. 214454ba768SRuslan ErmilovBut we make sure these holes require additional password 215454ba768SRuslan Ermilovverification to operate. 216454ba768SRuslan ErmilovOne way to make root accessible is to add appropriate 217454ba768SRuslan Ermilovstaff accounts to the 218454ba768SRuslan Ermilov.Dq Li wheel 219454ba768SRuslan Ermilovgroup (in 220c4d9468eSRuslan Ermilov.Pa /etc/group ) . 221454ba768SRuslan ErmilovThe staff members placed in the 222454ba768SRuslan Ermilov.Li wheel 223454ba768SRuslan Ermilovgroup are allowed to 224454ba768SRuslan Ermilov.Xr su 1 225454ba768SRuslan Ermilovto root. 226454ba768SRuslan ErmilovYou should never give staff 227454ba768SRuslan Ermilovmembers native 228454ba768SRuslan Ermilov.Li wheel 229454ba768SRuslan Ermilovaccess by putting them in the 230454ba768SRuslan Ermilov.Li wheel 231454ba768SRuslan Ermilovgroup in their password entry. 232454ba768SRuslan ErmilovStaff accounts should be placed in a 233454ba768SRuslan Ermilov.Dq Li staff 234454ba768SRuslan Ermilovgroup, and then added to the 235454ba768SRuslan Ermilov.Li wheel 236454ba768SRuslan Ermilovgroup via the 237454ba768SRuslan Ermilov.Pa /etc/group 238454ba768SRuslan Ermilovfile. 239454ba768SRuslan ErmilovOnly those staff members who actually need to have root access 240454ba768SRuslan Ermilovshould be placed in the 241454ba768SRuslan Ermilov.Li wheel 242454ba768SRuslan Ermilovgroup. 243454ba768SRuslan ErmilovIt is also possible, when using an 244454ba768SRuslan Ermilovauthentication method such as Kerberos, to use Kerberos's 245454ba768SRuslan Ermilov.Pa .k5login 246d93b26d6SMatthew Dillonfile in the root account to allow a 247d93b26d6SMatthew Dillon.Xr ksu 1 248454ba768SRuslan Ermilovto root without having to place anyone at all in the 249454ba768SRuslan Ermilov.Li wheel 250454ba768SRuslan Ermilovgroup. 251454ba768SRuslan ErmilovThis 252454ba768SRuslan Ermilovmay be the better solution since the 253454ba768SRuslan Ermilov.Li wheel 254454ba768SRuslan Ermilovmechanism still allows an 255d93b26d6SMatthew Dillonintruder to break root if the intruder has gotten hold of your password 256454ba768SRuslan Ermilovfile and can break into a staff account. 257454ba768SRuslan ErmilovWhile having the 258454ba768SRuslan Ermilov.Li wheel 259454ba768SRuslan Ermilovmechanism 260454ba768SRuslan Ermilovis better than having nothing at all, it is not necessarily the safest 261d93b26d6SMatthew Dillonoption. 262f063d76aSMatthew Dillon.Pp 263f063d76aSMatthew DillonAn indirect way to secure the root account is to secure your staff accounts 264f063d76aSMatthew Dillonby using an alternative login access method and *'ing out the crypted password 265454ba768SRuslan Ermilovfor the staff accounts. 266454ba768SRuslan ErmilovThis way an intruder may be able to steal the password 26747afd1f8SDaniel Harrisfile but will not be able to break into any staff accounts or root, even if 26847afd1f8SDaniel Harrisroot has a crypted password associated with it (assuming, of course, that 269454ba768SRuslan Ermilovyou have limited root access to the console). 270454ba768SRuslan ErmilovStaff members 271f063d76aSMatthew Dillonget into their staff accounts through a secure login mechanism such as 272a3f9c9fcSRuslan Ermilov.Xr kerberos 8 273568e4cbbSGuy Helmeror 274568e4cbbSGuy Helmer.Xr ssh 1 275568e4cbbSGuy Helmerusing a private/public 276454ba768SRuslan Ermilovkey pair. 277454ba768SRuslan ErmilovWhen you use something like Kerberos you generally must secure 278454ba768SRuslan Ermilovthe machines which run the Kerberos servers and your desktop workstation. 279454ba768SRuslan ErmilovWhen you use a public/private key pair with SSH, you must generally secure 280454ba768SRuslan Ermilovthe machine you are logging in 281454ba768SRuslan Ermilov.Em from 282c4d9468eSRuslan Ermilov(typically your workstation), 283568e4cbbSGuy Helmerbut you can 284f063d76aSMatthew Dillonalso add an additional layer of protection to the key pair by password 285568e4cbbSGuy Helmerprotecting the keypair when you create it with 286568e4cbbSGuy Helmer.Xr ssh-keygen 1 . 287568e4cbbSGuy HelmerBeing able 2886ac7e896SDavid E. O'Briento *-out the passwords for staff accounts also guarantees that staff members 289454ba768SRuslan Ermilovcan only log in through secure access methods that you have set up. 290454ba768SRuslan ErmilovYou can 291f063d76aSMatthew Dillonthus force all staff members to use secure, encrypted connections for 292454ba768SRuslan Ermilovall their sessions which closes an important hole used by many intruders: that 293f063d76aSMatthew Dillonof sniffing the network from an unrelated, less secure machine. 294f063d76aSMatthew Dillon.Pp 295f063d76aSMatthew DillonThe more indirect security mechanisms also assume that you are logging in 296454ba768SRuslan Ermilovfrom a more restrictive server to a less restrictive server. 297454ba768SRuslan ErmilovFor example, 298454ba768SRuslan Ermilovif your main box is running all sorts of servers, your workstation should not 299454ba768SRuslan Ermilovbe running any. 300454ba768SRuslan ErmilovIn order for your workstation to be reasonably secure 301f063d76aSMatthew Dillonyou should run as few servers as possible, up to and including no servers 302f063d76aSMatthew Dillonat all, and you should run a password-protected screen blanker. 303f063d76aSMatthew DillonOf course, given physical access to 304454ba768SRuslan Ermilova workstation, an attacker can break any sort of security you put on it. 305f063d76aSMatthew DillonThis is definitely a problem that you should consider but you should also 3066ac7e896SDavid E. O'Brienconsider the fact that the vast majority of break-ins occur remotely, over 3077626ae52SMatthew Dillona network, from people who do not have physical access to your workstation or 308f063d76aSMatthew Dillonservers. 309f063d76aSMatthew Dillon.Pp 310454ba768SRuslan ErmilovUsing something like Kerberos also gives you the ability to disable or 311f063d76aSMatthew Dillonchange the password for a staff account in one place and have it immediately 312454ba768SRuslan Ermilovaffect all the machines the staff member may have an account on. 313454ba768SRuslan ErmilovIf a staff 314f063d76aSMatthew Dillonmember's account gets compromised, the ability to instantly change his 315454ba768SRuslan Ermilovpassword on all machines should not be underrated. 316454ba768SRuslan ErmilovWith discrete passwords, changing a password on N machines can be a mess. 317454ba768SRuslan ErmilovYou can also impose 318454ba768SRuslan Ermilovre-passwording restrictions with Kerberos: not only can a Kerberos ticket 319454ba768SRuslan Ermilovbe made to timeout after a while, but the Kerberos system can require that 320568e4cbbSGuy Helmerthe user choose a new password after a certain period of time 321c4d9468eSRuslan Ermilov(say, once a month). 32247afd1f8SDaniel Harris.Sh SECURING ROOT \(em ROOT-RUN SERVERS AND SUID/SGID BINARIES 323454ba768SRuslan ErmilovThe prudent sysadmin only runs the servers he needs to, no more, no less. 324454ba768SRuslan ErmilovBe aware that third party servers are often the most bug-prone. 325454ba768SRuslan ErmilovFor example, 326454ba768SRuslan Ermilovrunning an old version of 327454ba768SRuslan Ermilov.Xr imapd 8 328454ba768SRuslan Ermilovor 329f0ea72a0SChristian Brueffer.Xr popper 8 Pq Pa ports/mail/popper 330454ba768SRuslan Ermilovis like giving a universal root 331454ba768SRuslan Ermilovticket out to the entire world. 332454ba768SRuslan ErmilovNever run a server that you have not checked 333454ba768SRuslan Ermilovout carefully. 334454ba768SRuslan ErmilovMany servers do not need to be run as root. 335454ba768SRuslan ErmilovFor example, 336454ba768SRuslan Ermilovthe 337454ba768SRuslan Ermilov.Xr talkd 8 , 338454ba768SRuslan Ermilov.Xr comsat 8 , 339454ba768SRuslan Ermilovand 340454ba768SRuslan Ermilov.Xr fingerd 8 341454ba768SRuslan Ermilovdaemons can be run in special user 342454ba768SRuslan Ermilov.Dq sandboxes . 343454ba768SRuslan ErmilovA sandbox is not perfect unless you go to a large amount of trouble, but the 344454ba768SRuslan Ermilovonion approach to security still stands: if someone is able to break in 345f063d76aSMatthew Dillonthrough a server running in a sandbox, they still have to break out of the 346454ba768SRuslan Ermilovsandbox. 347454ba768SRuslan ErmilovThe more layers the attacker must break through, the lower the 348454ba768SRuslan Ermilovlikelihood of his success. 349454ba768SRuslan ErmilovRoot holes have historically been found in 350f063d76aSMatthew Dillonvirtually every server ever run as root, including basic system servers. 351454ba768SRuslan ErmilovIf you are running a machine through which people only log in via 352454ba768SRuslan Ermilov.Xr sshd 8 353454ba768SRuslan Ermilovand never log in via 354454ba768SRuslan Ermilov.Xr telnetd 8 , 355454ba768SRuslan Ermilov.Xr rshd 8 , 356454ba768SRuslan Ermilovor 357454ba768SRuslan Ermilov.Xr rlogind 8 , 358454ba768SRuslan Ermilovthen turn off those services! 359f063d76aSMatthew Dillon.Pp 360f6f8f44dSAlexey Zelkin.Fx 361454ba768SRuslan Ermilovnow defaults to running 362454ba768SRuslan Ermilov.Xr talkd 8 , 363454ba768SRuslan Ermilov.Xr comsat 8 , 364454ba768SRuslan Ermilovand 365454ba768SRuslan Ermilov.Xr fingerd 8 366454ba768SRuslan Ermilovin a sandbox. 367f063d76aSMatthew DillonAnother program which may be a candidate for running in a sandbox is 368568e4cbbSGuy Helmer.Xr named 8 . 369454ba768SRuslan ErmilovThe default 370454ba768SRuslan Ermilov.Pa rc.conf 371454ba768SRuslan Ermilovincludes the arguments necessary to run 372454ba768SRuslan Ermilov.Xr named 8 373454ba768SRuslan Ermilovin a sandbox in a commented-out form. 374454ba768SRuslan ErmilovDepending on whether you 375f063d76aSMatthew Dillonare installing a new system or upgrading an existing system, the special 376454ba768SRuslan Ermilovuser accounts used by these sandboxes may not be installed. 377454ba768SRuslan ErmilovThe prudent 3787626ae52SMatthew Dillonsysadmin would research and implement sandboxes for servers whenever possible. 379f063d76aSMatthew Dillon.Pp 380f063d76aSMatthew DillonThere are a number of other servers that typically do not run in sandboxes: 381454ba768SRuslan Ermilov.Xr sendmail 8 , 382454ba768SRuslan Ermilov.Xr popper 8 , 383454ba768SRuslan Ermilov.Xr imapd 8 , 384454ba768SRuslan Ermilov.Xr ftpd 8 , 385454ba768SRuslan Ermilovand others. 386454ba768SRuslan ErmilovThere are alternatives to 3879518a247SJens Schweikhardtsome of these, but installing them may require more work than you are willing 388568e4cbbSGuy Helmerto put 389c4d9468eSRuslan Ermilov(the convenience factor strikes again). 390568e4cbbSGuy HelmerYou may have to run these 3916ac7e896SDavid E. O'Brienservers as root and rely on other mechanisms to detect break-ins that might 392f063d76aSMatthew Dillonoccur through them. 393f063d76aSMatthew Dillon.Pp 394454ba768SRuslan ErmilovThe other big potential root hole in a system are the SUID-root and SGID 395454ba768SRuslan Ermilovbinaries installed on the system. 396454ba768SRuslan ErmilovMost of these binaries, such as 397454ba768SRuslan Ermilov.Xr rlogin 1 , 398568e4cbbSGuy Helmerreside in 399454ba768SRuslan Ermilov.Pa /bin , /sbin , /usr/bin , 400568e4cbbSGuy Helmeror 401568e4cbbSGuy Helmer.Pa /usr/sbin . 402568e4cbbSGuy HelmerWhile nothing is 100% safe, 403454ba768SRuslan Ermilovthe system-default SUID and SGID binaries can be considered reasonably safe. 404454ba768SRuslan ErmilovStill, root holes are occasionally found in these binaries. 405454ba768SRuslan ErmilovA root hole 406454ba768SRuslan Ermilovwas found in Xlib in 1998 that made 407f0ea72a0SChristian Brueffer.Xr xterm 1 Pq Pa ports/x11/xterm 408454ba768SRuslan Ermilov(which is typically SUID) 409568e4cbbSGuy Helmervulnerable. 410454ba768SRuslan ErmilovIt is better to be safe than sorry and the prudent sysadmin will restrict SUID 411f063d76aSMatthew Dillonbinaries that only staff should run to a special group that only staff can 412568e4cbbSGuy Helmeraccess, and get rid of 413454ba768SRuslan Ermilov.Pq Dq Li "chmod 000" 414454ba768SRuslan Ermilovany SUID binaries that nobody uses. 415454ba768SRuslan ErmilovA server with no display generally does not need an 416454ba768SRuslan Ermilov.Xr xterm 1 417454ba768SRuslan Ermilovbinary. 418454ba768SRuslan ErmilovSGID binaries can be almost as dangerous. 419454ba768SRuslan ErmilovIf an intruder can break an SGID-kmem binary the 420568e4cbbSGuy Helmerintruder might be able to read 421568e4cbbSGuy Helmer.Pa /dev/kmem 422568e4cbbSGuy Helmerand thus read the crypted password 423454ba768SRuslan Ermilovfile, potentially compromising any passworded account. 424454ba768SRuslan ErmilovAlternatively an 425454ba768SRuslan Ermilovintruder who breaks group 426454ba768SRuslan Ermilov.Dq Li kmem 427454ba768SRuslan Ermilovcan monitor keystrokes sent through PTYs, 428454ba768SRuslan Ermilovincluding PTYs used by users who log in through secure methods. 429454ba768SRuslan ErmilovAn intruder 430454ba768SRuslan Ermilovthat breaks the 431454ba768SRuslan Ermilov.Dq Li tty 432454ba768SRuslan Ermilovgroup can write to almost any user's TTY. 433454ba768SRuslan ErmilovIf a user 434d93b26d6SMatthew Dillonis running a terminal 435d93b26d6SMatthew Dillonprogram or emulator with a keyboard-simulation feature, the intruder can 436d93b26d6SMatthew Dillonpotentially 437f063d76aSMatthew Dillongenerate a data stream that causes the user's terminal to echo a command, which 438f063d76aSMatthew Dillonis then run as that user. 439f063d76aSMatthew Dillon.Sh SECURING USER ACCOUNTS 440454ba768SRuslan ErmilovUser accounts are usually the most difficult to secure. 441454ba768SRuslan ErmilovWhile you can impose 442454ba768SRuslan Ermilovdraconian access restrictions on your staff and *-out their passwords, you 443454ba768SRuslan Ermilovmay not be able to do so with any general user accounts you might have. 444454ba768SRuslan ErmilovIf 445f063d76aSMatthew Dillonyou do have sufficient control then you may win out and be able to secure the 446454ba768SRuslan Ermilovuser accounts properly. 447454ba768SRuslan ErmilovIf not, you simply have to be more vigilant in your 448454ba768SRuslan Ermilovmonitoring of those accounts. 449454ba768SRuslan ErmilovUse of SSH and Kerberos for user accounts is 450d93b26d6SMatthew Dillonmore problematic due to the extra administration and technical support 451d93b26d6SMatthew Dillonrequired, but still a very good solution compared to a crypted password 452d93b26d6SMatthew Dillonfile. 453f063d76aSMatthew Dillon.Sh SECURING THE PASSWORD FILE 454f063d76aSMatthew DillonThe only sure fire way is to *-out as many passwords as you can and 455454ba768SRuslan Ermilovuse SSH or Kerberos for access to those accounts. 456454ba768SRuslan ErmilovEven though the 457568e4cbbSGuy Helmercrypted password file 458568e4cbbSGuy Helmer.Pq Pa /etc/spwd.db 459568e4cbbSGuy Helmercan only be read by root, it may 460568e4cbbSGuy Helmerbe possible for an intruder to obtain read access to that file even if the 461f063d76aSMatthew Dillonattacker cannot obtain root-write access. 462f063d76aSMatthew Dillon.Pp 463f063d76aSMatthew DillonYour security scripts should always check for and report changes to 464568e4cbbSGuy Helmerthe password file 465c4d9468eSRuslan Ermilov(see 466454ba768SRuslan Ermilov.Sx CHECKING FILE INTEGRITY 467c4d9468eSRuslan Ermilovbelow). 468f063d76aSMatthew Dillon.Sh SECURING THE KERNEL CORE, RAW DEVICES, AND FILE SYSTEMS 469f063d76aSMatthew DillonIf an attacker breaks root he can do just about anything, but there 470454ba768SRuslan Ermilovare certain conveniences. 471454ba768SRuslan ErmilovFor example, most modern kernels have a packet sniffing device driver built in. 472454ba768SRuslan ErmilovUnder 473f6f8f44dSAlexey Zelkin.Fx 474568e4cbbSGuy Helmerit is called 475568e4cbbSGuy Helmerthe 476454ba768SRuslan Ermilov.Xr bpf 4 477454ba768SRuslan Ermilovdevice. 478454ba768SRuslan ErmilovAn intruder will commonly attempt to run a packet sniffer 479454ba768SRuslan Ermilovon a compromised machine. 480454ba768SRuslan ErmilovYou do not need to give the intruder the 481454ba768SRuslan Ermilovcapability and most systems should not have the 482454ba768SRuslan Ermilov.Xr bpf 4 483454ba768SRuslan Ermilovdevice compiled in. 484f063d76aSMatthew Dillon.Pp 485454ba768SRuslan ErmilovBut even if you turn off the 486454ba768SRuslan Ermilov.Xr bpf 4 487454ba768SRuslan Ermilovdevice, you still have 488568e4cbbSGuy Helmer.Pa /dev/mem 489568e4cbbSGuy Helmerand 490568e4cbbSGuy Helmer.Pa /dev/kmem 491454ba768SRuslan Ermilovto worry about. 492454ba768SRuslan ErmilovFor that matter, 493d93b26d6SMatthew Dillonthe intruder can still write to raw disk devices. 494d93b26d6SMatthew DillonAlso, there is another kernel feature called the module loader, 495568e4cbbSGuy Helmer.Xr kldload 8 . 496568e4cbbSGuy HelmerAn enterprising intruder can use a KLD module to install 497454ba768SRuslan Ermilovhis own 498454ba768SRuslan Ermilov.Xr bpf 4 499454ba768SRuslan Ermilovdevice or other sniffing device on a running kernel. 500568e4cbbSGuy HelmerTo avoid these problems you have to run 501e17c0e32SGary W. Swearingenthe kernel at a higher security level, at least level 1. 502e17c0e32SGary W. SwearingenThe security level can be set with a 503454ba768SRuslan Ermilov.Xr sysctl 8 504454ba768SRuslan Ermilovon the 505454ba768SRuslan Ermilov.Va kern.securelevel 506454ba768SRuslan Ermilovvariable. 507454ba768SRuslan ErmilovOnce you have 508e17c0e32SGary W. Swearingenset the security level to 1, write access to raw devices will be denied and 509454ba768SRuslan Ermilovspecial 510454ba768SRuslan Ermilov.Xr chflags 1 511454ba768SRuslan Ermilovflags, such as 512454ba768SRuslan Ermilov.Cm schg , 513454ba768SRuslan Ermilovwill be enforced. 514454ba768SRuslan ErmilovYou must also ensure 515568e4cbbSGuy Helmerthat the 516454ba768SRuslan Ermilov.Cm schg 517568e4cbbSGuy Helmerflag is set on critical startup binaries, directories, and 518e17c0e32SGary W. Swearingenscript files \(em everything that gets run 519e17c0e32SGary W. Swearingenup to the point where the security level is set. 520454ba768SRuslan ErmilovThis might be overdoing it, and upgrading the system is much more 521e17c0e32SGary W. Swearingendifficult when you operate at a higher security level. 522454ba768SRuslan ErmilovYou may compromise and 523e17c0e32SGary W. Swearingenrun the system at a higher security level but not set the 524454ba768SRuslan Ermilov.Cm schg 525454ba768SRuslan Ermilovflag for every 526454ba768SRuslan Ermilovsystem file and directory under the sun. 527454ba768SRuslan ErmilovAnother possibility is to simply 528454ba768SRuslan Ermilovmount 529454ba768SRuslan Ermilov.Pa / 530454ba768SRuslan Ermilovand 531454ba768SRuslan Ermilov.Pa /usr 532454ba768SRuslan Ermilovread-only. 533454ba768SRuslan ErmilovIt should be noted that being too draconian in 534d93b26d6SMatthew Dillonwhat you attempt to protect may prevent the all-important detection of an 535d93b26d6SMatthew Dillonintrusion. 536e17c0e32SGary W. Swearingen.Pp 537e17c0e32SGary W. SwearingenThe kernel runs with five different security levels. 538e17c0e32SGary W. SwearingenAny super-user process can raise the level, but no process 539e17c0e32SGary W. Swearingencan lower it. 540e17c0e32SGary W. SwearingenThe security levels are: 541e17c0e32SGary W. Swearingen.Bl -tag -width flag 542e17c0e32SGary W. Swearingen.It Ic -1 543e17c0e32SGary W. SwearingenPermanently insecure mode \- always run the system in insecure mode. 544e17c0e32SGary W. SwearingenThis is the default initial value. 545e17c0e32SGary W. Swearingen.It Ic 0 546e17c0e32SGary W. SwearingenInsecure mode \- immutable and append-only flags may be turned off. 547e17c0e32SGary W. SwearingenAll devices may be read or written subject to their permissions. 548e17c0e32SGary W. Swearingen.It Ic 1 549e17c0e32SGary W. SwearingenSecure mode \- the system immutable and system append-only flags may not 550e17c0e32SGary W. Swearingenbe turned off; 551e17c0e32SGary W. Swearingendisks for mounted file systems, 552e17c0e32SGary W. Swearingen.Pa /dev/mem , 553e17c0e32SGary W. Swearingen.Pa /dev/kmem 554e17c0e32SGary W. Swearingenand 555e17c0e32SGary W. Swearingen.Pa /dev/io 556e17c0e32SGary W. Swearingen(if your platform has it) may not be opened for writing; 557e17c0e32SGary W. Swearingenkernel modules (see 558e17c0e32SGary W. Swearingen.Xr kld 4 ) 559e17c0e32SGary W. Swearingenmay not be loaded or unloaded. 560e17c0e32SGary W. Swearingen.It Ic 2 561e17c0e32SGary W. SwearingenHighly secure mode \- same as secure mode, plus disks may not be 562e17c0e32SGary W. Swearingenopened for writing (except by 563e17c0e32SGary W. Swearingen.Xr mount 2 ) 564e17c0e32SGary W. Swearingenwhether mounted or not. 565e17c0e32SGary W. SwearingenThis level precludes tampering with file systems by unmounting them, 566e17c0e32SGary W. Swearingenbut also inhibits running 567e17c0e32SGary W. Swearingen.Xr newfs 8 568e17c0e32SGary W. Swearingenwhile the system is multi-user. 569e17c0e32SGary W. Swearingen.Pp 570e17c0e32SGary W. SwearingenIn addition, kernel time changes are restricted to less than or equal to one 571e17c0e32SGary W. Swearingensecond. 572e17c0e32SGary W. SwearingenAttempts to change the time by more than this will log the message 573e17c0e32SGary W. Swearingen.Dq Time adjustment clamped to +1 second . 574e17c0e32SGary W. Swearingen.It Ic 3 575e17c0e32SGary W. SwearingenNetwork secure mode \- same as highly secure mode, plus 576e17c0e32SGary W. SwearingenIP packet filter rules (see 577e17c0e32SGary W. Swearingen.Xr ipfw 8 , 578e17c0e32SGary W. Swearingen.Xr ipfirewall 4 579e17c0e32SGary W. Swearingenand 580e17c0e32SGary W. Swearingen.Xr pfctl 8 ) 581e17c0e32SGary W. Swearingencannot be changed and 582e17c0e32SGary W. Swearingen.Xr dummynet 4 583e17c0e32SGary W. Swearingenor 584e17c0e32SGary W. Swearingen.Xr pf 4 585e17c0e32SGary W. Swearingenconfiguration cannot be adjusted. 586e17c0e32SGary W. Swearingen.El 587e17c0e32SGary W. Swearingen.Pp 588e17c0e32SGary W. SwearingenThe security level is discussed further in 589e17c0e32SGary W. Swearingen.Xr init 8 590e17c0e32SGary W. Swearingenand can be configured with variables documented in 591e17c0e32SGary W. Swearingen.Xr rc.conf 8 . 592f063d76aSMatthew Dillon.Sh CHECKING FILE INTEGRITY: BINARIES, CONFIG FILES, ETC 593f063d76aSMatthew DillonWhen it comes right down to it, you can only protect your core system 594f063d76aSMatthew Dillonconfiguration and control files so much before the convenience factor 595454ba768SRuslan Ermilovrears its ugly head. 596454ba768SRuslan ErmilovFor example, using 597454ba768SRuslan Ermilov.Xr chflags 1 598454ba768SRuslan Ermilovto set the 599454ba768SRuslan Ermilov.Cm schg 600454ba768SRuslan Ermilovbit on most of the files in 601454ba768SRuslan Ermilov.Pa / 602454ba768SRuslan Ermilovand 603454ba768SRuslan Ermilov.Pa /usr 604454ba768SRuslan Ermilovis probably counterproductive because 605454ba768SRuslan Ermilovwhile it may protect the files, it also closes a detection window. 606454ba768SRuslan ErmilovThe 60747afd1f8SDaniel Harrislast layer of your security onion is perhaps the most important \(em detection. 608d93b26d6SMatthew DillonThe rest of your security is pretty much useless (or, worse, presents you with 609454ba768SRuslan Ermilova false sense of safety) if you cannot detect potential incursions. 610454ba768SRuslan ErmilovHalf 611074ad115SRuslan Ermilovthe job of the onion is to slow down the attacker rather than stop him 6124c0d8029SDaniel Harrisin order to give the detection layer a chance to catch him in 613d93b26d6SMatthew Dillonthe act. 614f063d76aSMatthew Dillon.Pp 615d93b26d6SMatthew DillonThe best way to detect an incursion is to look for modified, missing, or 616454ba768SRuslan Ermilovunexpected files. 617454ba768SRuslan ErmilovThe best 618d93b26d6SMatthew Dillonway to look for modified files is from another (often centralized) 619d93b26d6SMatthew Dillonlimited-access system. 620d93b26d6SMatthew DillonWriting your security scripts on the extra-secure limited-access system 62147afd1f8SDaniel Harrismakes them mostly invisible to potential attackers, and this is important. 622d93b26d6SMatthew DillonIn order to take maximum advantage you generally have to give the 623d93b26d6SMatthew Dillonlimited-access box significant access to the other machines in the business, 624d93b26d6SMatthew Dillonusually either by doing a read-only NFS export of the other machines to the 625454ba768SRuslan Ermilovlimited-access box, or by setting up SSH keypairs to allow the limit-access 626454ba768SRuslan Ermilovbox to SSH to the other machines. 627454ba768SRuslan ErmilovExcept for its network traffic, NFS is 62847afd1f8SDaniel Harristhe least visible method \(em allowing you to monitor the file systems on each 629454ba768SRuslan Ermilovclient box virtually undetected. 630454ba768SRuslan ErmilovIf your 631d93b26d6SMatthew Dillonlimited-access server is connected to the client boxes through a switch, 632454ba768SRuslan Ermilovthe NFS method is often the better choice. 633454ba768SRuslan ErmilovIf your limited-access server 634d93b26d6SMatthew Dillonis connected to the client boxes through a hub or through several layers 635454ba768SRuslan Ermilovof routing, the NFS method may be too insecure (network-wise) and using SSH 636454ba768SRuslan Ermilovmay be the better choice even with the audit-trail tracks that SSH lays. 637d93b26d6SMatthew Dillon.Pp 638d93b26d6SMatthew DillonOnce you give a limit-access box at least read access to the client systems 639d93b26d6SMatthew Dillonit is supposed to monitor, you must write scripts to do the actual 640454ba768SRuslan Ermilovmonitoring. 641454ba768SRuslan ErmilovGiven an NFS mount, you can write scripts out of simple system 642d93b26d6SMatthew Dillonutilities such as 643d93b26d6SMatthew Dillon.Xr find 1 644d93b26d6SMatthew Dillonand 645454ba768SRuslan Ermilov.Xr md5 1 . 646454ba768SRuslan ErmilovIt is best to physically 647d93b26d6SMatthew Dillon.Xr md5 1 648454ba768SRuslan Ermilovthe client-box files boxes at least once a 649ad27d066SMatthew Dillonday, and to test control files such as those found in 650ad27d066SMatthew Dillon.Pa /etc 651ad27d066SMatthew Dillonand 652ad27d066SMatthew Dillon.Pa /usr/local/etc 653454ba768SRuslan Ermiloveven more often. 654454ba768SRuslan ErmilovWhen mismatches are found relative to the base MD5 655d93b26d6SMatthew Dilloninformation the limited-access machine knows is valid, it should scream at 656454ba768SRuslan Ermilova sysadmin to go check it out. 657454ba768SRuslan ErmilovA good security script will also check for 658454ba768SRuslan Ermilovinappropriate SUID binaries and for new or deleted files on system partitions 659d93b26d6SMatthew Dillonsuch as 660d93b26d6SMatthew Dillon.Pa / 661568e4cbbSGuy Helmerand 662454ba768SRuslan Ermilov.Pa /usr . 663f063d76aSMatthew Dillon.Pp 664454ba768SRuslan ErmilovWhen using SSH rather than NFS, writing the security script is much more 665454ba768SRuslan Ermilovdifficult. 666454ba768SRuslan ErmilovYou essentially have to 667454ba768SRuslan Ermilov.Xr scp 1 668d93b26d6SMatthew Dillonthe scripts to the client box in order to run them, making them visible, and 669454ba768SRuslan Ermilovfor safety you also need to 670454ba768SRuslan Ermilov.Xr scp 1 671454ba768SRuslan Ermilovthe binaries (such as 672454ba768SRuslan Ermilov.Xr find 1 ) 673454ba768SRuslan Ermilovthat those scripts use. 674454ba768SRuslan ErmilovThe 675454ba768SRuslan Ermilov.Xr sshd 8 676454ba768SRuslan Ermilovdaemon on the client box may already be compromised. 677454ba768SRuslan ErmilovAll in all, 678454ba768SRuslan Ermilovusing SSH may be necessary when running over unsecure links, but it is also a 679d93b26d6SMatthew Dillonlot harder to deal with. 680f063d76aSMatthew Dillon.Pp 681f063d76aSMatthew DillonA good security script will also check for changes to user and staff members 682ad27d066SMatthew Dillonaccess configuration files: 683454ba768SRuslan Ermilov.Pa .rhosts , .shosts , .ssh/authorized_keys 6845203edcdSRuslan Ermilovand so forth, files that might fall outside the purview of the MD5 check. 685f063d76aSMatthew Dillon.Pp 686d93b26d6SMatthew DillonIf you have a huge amount of user disk space it may take too long to run 687454ba768SRuslan Ermilovthrough every file on those partitions. 688454ba768SRuslan ErmilovIn this case, setting mount 689e354922cSRuslan Ermilovflags to disallow SUID binaries on those partitions is a good 690454ba768SRuslan Ermilovidea. 691454ba768SRuslan ErmilovThe 692454ba768SRuslan Ermilov.Cm nosuid 693e354922cSRuslan Ermilovoption 694c4d9468eSRuslan Ermilov(see 695c4d9468eSRuslan Ermilov.Xr mount 8 ) 696e354922cSRuslan Ermilovis what you want to look into. 697454ba768SRuslan ErmilovI would scan them anyway at least once a 698d93b26d6SMatthew Dillonweek, since the object of this layer is to detect a break-in whether or 699a30de06bSCeri Daviesnot the break-in is effective. 700f063d76aSMatthew Dillon.Pp 701568e4cbbSGuy HelmerProcess accounting 702c4d9468eSRuslan Ermilov(see 703c4d9468eSRuslan Ermilov.Xr accton 8 ) 704568e4cbbSGuy Helmeris a relatively low-overhead feature of 7056ac7e896SDavid E. O'Brienthe operating system which I recommend using as a post-break-in evaluation 706454ba768SRuslan Ermilovmechanism. 707454ba768SRuslan ErmilovIt is especially useful in tracking down how an intruder has 708d93b26d6SMatthew Dillonactually broken into a system, assuming the file is still intact after 7096ac7e896SDavid E. O'Brienthe break-in occurs. 710f063d76aSMatthew Dillon.Pp 711f063d76aSMatthew DillonFinally, security scripts should process the log files and the logs themselves 71247afd1f8SDaniel Harrisshould be generated in as secure a manner as possible \(em remote syslog can be 713454ba768SRuslan Ermilovvery useful. 714454ba768SRuslan ErmilovAn intruder tries to cover his tracks, and log files are critical 715d93b26d6SMatthew Dillonto the sysadmin trying to track down the time and method of the initial 716454ba768SRuslan Ermilovbreak-in. 717454ba768SRuslan ErmilovOne way to keep a permanent record of the log files is to run 718d93b26d6SMatthew Dillonthe system console to a serial port and collect the information on a 719d93b26d6SMatthew Dilloncontinuing basis through a secure machine monitoring the consoles. 720f063d76aSMatthew Dillon.Sh PARANOIA 721454ba768SRuslan ErmilovA little paranoia never hurts. 722454ba768SRuslan ErmilovAs a rule, a sysadmin can add any number 72347afd1f8SDaniel Harrisof security features as long as they do not affect convenience, and 72447afd1f8SDaniel Harriscan add security features that do affect convenience with some added 725454ba768SRuslan Ermilovthought. 726454ba768SRuslan ErmilovEven more importantly, a security administrator should mix it up 72747afd1f8SDaniel Harrisa bit \(em if you use recommendations such as those given by this manual 728d93b26d6SMatthew Dillonpage verbatim, you give away your methodologies to the prospective 72947afd1f8SDaniel Harrisattacker who also has access to this manual page. 730454ba768SRuslan Ermilov.Sh SPECIAL SECTION ON DoS ATTACKS 731454ba768SRuslan ErmilovThis section covers Denial of Service attacks. 732454ba768SRuslan ErmilovA DoS attack is typically a packet attack. 733454ba768SRuslan ErmilovWhile there is not much you can do about modern spoofed 734f063d76aSMatthew Dillonpacket attacks that saturate your network, you can generally limit the damage 735f063d76aSMatthew Dillonby ensuring that the attacks cannot take down your servers. 736f063d76aSMatthew Dillon.Bl -enum -offset indent 737f063d76aSMatthew Dillon.It 738f063d76aSMatthew DillonLimiting server forks 739f063d76aSMatthew Dillon.It 740454ba768SRuslan ErmilovLimiting springboard attacks (ICMP response attacks, ping broadcast, etc.) 741f063d76aSMatthew Dillon.It 742f063d76aSMatthew DillonKernel Route Cache 743f063d76aSMatthew Dillon.El 744f063d76aSMatthew Dillon.Pp 745454ba768SRuslan ErmilovA common DoS attack is against a forking server that attempts to cause the 7466ac7e896SDavid E. O'Brienserver to eat processes, file descriptors, and memory until the machine 747454ba768SRuslan Ermilovdies. 748454ba768SRuslan ErmilovThe 749454ba768SRuslan Ermilov.Xr inetd 8 750454ba768SRuslan Ermilovserver 751568e4cbbSGuy Helmerhas several options to limit this sort of attack. 752f063d76aSMatthew DillonIt should be noted that while it is possible to prevent a machine from going 753f063d76aSMatthew Dillondown it is not generally possible to prevent a service from being disrupted 754454ba768SRuslan Ermilovby the attack. 755454ba768SRuslan ErmilovRead the 756454ba768SRuslan Ermilov.Xr inetd 8 757454ba768SRuslan Ermilovmanual page carefully and pay specific attention 758568e4cbbSGuy Helmerto the 759454ba768SRuslan Ermilov.Fl c , C , 760568e4cbbSGuy Helmerand 761568e4cbbSGuy Helmer.Fl R 762454ba768SRuslan Ermilovoptions. 763454ba768SRuslan ErmilovNote that spoofed-IP attacks will circumvent 764568e4cbbSGuy Helmerthe 765568e4cbbSGuy Helmer.Fl C 766454ba768SRuslan Ermilovoption to 767454ba768SRuslan Ermilov.Xr inetd 8 , 768454ba768SRuslan Ermilovso typically a combination of options must be used. 769f063d76aSMatthew DillonSome standalone servers have self-fork-limitation parameters. 770f063d76aSMatthew Dillon.Pp 771454ba768SRuslan ErmilovThe 772454ba768SRuslan Ermilov.Xr sendmail 8 773454ba768SRuslan Ermilovdaemon has its 774568e4cbbSGuy Helmer.Fl OMaxDaemonChildren 775568e4cbbSGuy Helmeroption which tends to work much 776454ba768SRuslan Ermilovbetter than trying to use 777454ba768SRuslan Ermilov.Xr sendmail 8 Ns 's 778454ba768SRuslan Ermilovload limiting options due to the 779454ba768SRuslan Ermilovload lag. 780454ba768SRuslan ErmilovYou should specify a 781454ba768SRuslan Ermilov.Va MaxDaemonChildren 782568e4cbbSGuy Helmerparameter when you start 783454ba768SRuslan Ermilov.Xr sendmail 8 784454ba768SRuslan Ermilovhigh enough to handle your expected load but not so high that the 785454ba768SRuslan Ermilovcomputer cannot handle that number of 786454ba768SRuslan Ermilov.Nm sendmail Ns 's 787454ba768SRuslan Ermilovwithout falling on its face. 788454ba768SRuslan ErmilovIt is also prudent to run 789454ba768SRuslan Ermilov.Xr sendmail 8 790454ba768SRuslan Ermilovin 791454ba768SRuslan Ermilov.Dq queued 792454ba768SRuslan Ermilovmode 793568e4cbbSGuy Helmer.Pq Fl ODeliveryMode=queued 794568e4cbbSGuy Helmerand to run the daemon 795454ba768SRuslan Ermilov.Pq Dq Nm sendmail Fl bd 796568e4cbbSGuy Helmerseparate from the queue-runs 797454ba768SRuslan Ermilov.Pq Dq Nm sendmail Fl q15m . 798454ba768SRuslan ErmilovIf you still want real-time delivery you can run the queue 799568e4cbbSGuy Helmerat a much lower interval, such as 800568e4cbbSGuy Helmer.Fl q1m , 801568e4cbbSGuy Helmerbut be sure to specify a reasonable 802454ba768SRuslan Ermilov.Va MaxDaemonChildren 803454ba768SRuslan Ermilovoption for that 804454ba768SRuslan Ermilov.Xr sendmail 8 805454ba768SRuslan Ermilovto prevent cascade failures. 806f063d76aSMatthew Dillon.Pp 807454ba768SRuslan ErmilovThe 808454ba768SRuslan Ermilov.Xr syslogd 8 809454ba768SRuslan Ermilovdaemon can be attacked directly and it is strongly recommended that you use 810568e4cbbSGuy Helmerthe 811568e4cbbSGuy Helmer.Fl s 812568e4cbbSGuy Helmeroption whenever possible, and the 813568e4cbbSGuy Helmer.Fl a 814568e4cbbSGuy Helmeroption otherwise. 815f063d76aSMatthew Dillon.Pp 816f063d76aSMatthew DillonYou should also be fairly careful 817f063d76aSMatthew Dillonwith connect-back services such as tcpwrapper's reverse-identd, which can 818454ba768SRuslan Ermilovbe attacked directly. 819454ba768SRuslan ErmilovYou generally do not want to use the reverse-ident 820f063d76aSMatthew Dillonfeature of tcpwrappers for this reason. 821f063d76aSMatthew Dillon.Pp 822f063d76aSMatthew DillonIt is a very good idea to protect internal services from external access 823454ba768SRuslan Ermilovby firewalling them off at your border routers. 824454ba768SRuslan ErmilovThe idea here is to prevent 825f063d76aSMatthew Dillonsaturation attacks from outside your LAN, not so much to protect internal 826454ba768SRuslan Ermilovservices from network-based root compromise. 827454ba768SRuslan ErmilovAlways configure an exclusive 828454ba768SRuslan Ermilovfirewall, i.e., 829568e4cbbSGuy Helmer.So 83047afd1f8SDaniel Harrisfirewall everything 83147afd1f8SDaniel Harris.Em except 83247afd1f8SDaniel Harrisports A, B, C, D, and M-Z 833568e4cbbSGuy Helmer.Sc . 834568e4cbbSGuy HelmerThis 835f063d76aSMatthew Dillonway you can firewall off all of your low ports except for certain specific 836454ba768SRuslan Ermilovservices such as 837454ba768SRuslan Ermilov.Xr named 8 838c4d9468eSRuslan Ermilov(if you are primary for a zone), 839454ba768SRuslan Ermilov.Xr talkd 8 , 840454ba768SRuslan Ermilov.Xr sendmail 8 , 841f063d76aSMatthew Dillonand other internet-accessible services. 842f063d76aSMatthew DillonIf you try to configure the firewall the other 84347afd1f8SDaniel Harrisway \(em as an inclusive or permissive firewall, there is a good chance that you 844568e4cbbSGuy Helmerwill forget to 845454ba768SRuslan Ermilov.Dq close 846568e4cbbSGuy Helmera couple of services or that you will add a new internal 847454ba768SRuslan Ermilovservice and forget to update the firewall. 848454ba768SRuslan ErmilovYou can still open up the 849f063d76aSMatthew Dillonhigh-numbered port range on the firewall to allow permissive-like operation 850454ba768SRuslan Ermilovwithout compromising your low ports. 851454ba768SRuslan ErmilovAlso take note that 852f6f8f44dSAlexey Zelkin.Fx 853568e4cbbSGuy Helmerallows you to 854f063d76aSMatthew Dilloncontrol the range of port numbers used for dynamic binding via the various 855454ba768SRuslan Ermilov.Va net.inet.ip.portrange 856454ba768SRuslan Ermilovsysctl's 857454ba768SRuslan Ermilov.Pq Dq Li "sysctl net.inet.ip.portrange" , 858568e4cbbSGuy Helmerwhich can also 859454ba768SRuslan Ermilovease the complexity of your firewall's configuration. 860454ba768SRuslan ErmilovI usually use a normal 861f063d76aSMatthew Dillonfirst/last range of 4000 to 5000, and a hiport range of 49152 to 65535, then 862568e4cbbSGuy Helmerblock everything under 4000 off in my firewall 863c4d9468eSRuslan Ermilov(except for certain specific 864c4d9468eSRuslan Ermilovinternet-accessible ports, of course). 865f063d76aSMatthew Dillon.Pp 866454ba768SRuslan ErmilovAnother common DoS attack is called a springboard attack \(em to attack a server 867f063d76aSMatthew Dillonin a manner that causes the server to generate responses which then overload 868454ba768SRuslan Ermilovthe server, the local network, or some other machine. 869454ba768SRuslan ErmilovThe most common attack 870454ba768SRuslan Ermilovof this nature is the ICMP PING BROADCAST attack. 871454ba768SRuslan ErmilovThe attacker spoofs ping 872f063d76aSMatthew Dillonpackets sent to your LAN's broadcast address with the source IP address set 873454ba768SRuslan Ermilovto the actual machine they wish to attack. 874454ba768SRuslan ErmilovIf your border routers are not 875f063d76aSMatthew Dillonconfigured to stomp on ping's to broadcast addresses, your LAN winds up 876f063d76aSMatthew Dillongenerating sufficient responses to the spoofed source address to saturate the 877f063d76aSMatthew Dillonvictim, especially when the attacker uses the same trick on several dozen 878454ba768SRuslan Ermilovbroadcast addresses over several dozen different networks at once. 879454ba768SRuslan ErmilovBroadcast attacks of over a hundred and twenty megabits have been measured. 880454ba768SRuslan ErmilovA second common springboard attack is against the ICMP error reporting system. 881454ba768SRuslan ErmilovBy 882f063d76aSMatthew Dillonconstructing packets that generate ICMP error responses, an attacker can 883f063d76aSMatthew Dillonsaturate a server's incoming network and cause the server to saturate its 884454ba768SRuslan Ermilovoutgoing network with ICMP responses. 885454ba768SRuslan ErmilovThis type of attack can also crash the 886454ba768SRuslan Ermilovserver by running it out of 887454ba768SRuslan Ermilov.Vt mbuf Ns 's , 888454ba768SRuslan Ermilovespecially if the server cannot drain the 889454ba768SRuslan ErmilovICMP responses it generates fast enough. 890454ba768SRuslan ErmilovThe 891f6f8f44dSAlexey Zelkin.Fx 892568e4cbbSGuy Helmerkernel has a new kernel 893454ba768SRuslan Ermilovcompile option called 894454ba768SRuslan Ermilov.Dv ICMP_BANDLIM 895454ba768SRuslan Ermilovwhich limits the effectiveness of these 896454ba768SRuslan Ermilovsorts of attacks. 897454ba768SRuslan ErmilovThe last major class of springboard attacks is related to 898454ba768SRuslan Ermilovcertain internal 899454ba768SRuslan Ermilov.Xr inetd 8 900454ba768SRuslan Ermilovservices such as the UDP echo service. 901454ba768SRuslan ErmilovAn attacker 902f063d76aSMatthew Dillonsimply spoofs a UDP packet with the source address being server A's echo port, 903f063d76aSMatthew Dillonand the destination address being server B's echo port, where server A and B 904454ba768SRuslan Ermilovare both on your LAN. 905454ba768SRuslan ErmilovThe two servers then bounce this one packet back and 906454ba768SRuslan Ermilovforth between each other. 907454ba768SRuslan ErmilovThe attacker can overload both servers and their 908454ba768SRuslan ErmilovLANs simply by injecting a few packets in this manner. 909454ba768SRuslan ErmilovSimilar problems 910454ba768SRuslan Ermilovexist with the internal chargen port. 911454ba768SRuslan ErmilovA competent sysadmin will turn off all 912454ba768SRuslan Ermilovof these 913454ba768SRuslan Ermilov.Xr inetd 8 Ns -internal 914454ba768SRuslan Ermilovtest services. 915f063d76aSMatthew Dillon.Pp 916f063d76aSMatthew DillonSpoofed packet attacks may also be used to overload the kernel route cache. 917454ba768SRuslan ErmilovRefer to the 918454ba768SRuslan Ermilov.Va net.inet.ip.rtexpire , net.inet.ip.rtminexpire , 919454ba768SRuslan Ermilovand 920454ba768SRuslan Ermilov.Va net.inet.ip.rtmaxcache 921454ba768SRuslan Ermilov.Xr sysctl 8 922454ba768SRuslan Ermilovvariables. 923454ba768SRuslan ErmilovA spoofed packet attack that uses a random source IP will cause 924f063d76aSMatthew Dillonthe kernel to generate a temporary cached route in the route table, viewable 925568e4cbbSGuy Helmerwith 926454ba768SRuslan Ermilov.Dq Li "netstat -rna | fgrep W3" . 927568e4cbbSGuy HelmerThese routes typically timeout in 1600 928454ba768SRuslan Ermilovseconds or so. 929454ba768SRuslan ErmilovIf the kernel detects that the cached route table has gotten 930454ba768SRuslan Ermilovtoo big it will dynamically reduce the 931454ba768SRuslan Ermilov.Va rtexpire 932454ba768SRuslan Ermilovbut will never decrease it to 933454ba768SRuslan Ermilovless than 934454ba768SRuslan Ermilov.Va rtminexpire . 935454ba768SRuslan ErmilovThere are two problems: (1) The kernel does not react 936f063d76aSMatthew Dillonquickly enough when a lightly loaded server is suddenly attacked, and (2) The 937454ba768SRuslan Ermilov.Va rtminexpire 938454ba768SRuslan Ermilovis not low enough for the kernel to survive a sustained attack. 939f063d76aSMatthew DillonIf your servers are connected to the internet via a T3 or better it may be 940454ba768SRuslan Ermilovprudent to manually override both 941454ba768SRuslan Ermilov.Va rtexpire 942454ba768SRuslan Ermilovand 943454ba768SRuslan Ermilov.Va rtminexpire 944454ba768SRuslan Ermilovvia 94585752545SGuy Helmer.Xr sysctl 8 . 946568e4cbbSGuy HelmerNever set either parameter to zero 947c4d9468eSRuslan Ermilov(unless you want to crash the machine :-)). 948f063d76aSMatthew DillonSetting both parameters to 2 seconds should be sufficient to protect the route 949f063d76aSMatthew Dillontable from attack. 950d93b26d6SMatthew Dillon.Sh ACCESS ISSUES WITH KERBEROS AND SSH 951454ba768SRuslan ErmilovThere are a few issues with both Kerberos and SSH that need to be addressed 952454ba768SRuslan Ermilovif you intend to use them. 953454ba768SRuslan ErmilovKerberos5 is an excellent authentication 954454ba768SRuslan Ermilovprotocol but the kerberized 955454ba768SRuslan Ermilov.Xr telnet 1 956454ba768SRuslan Ermilovand 957454ba768SRuslan Ermilov.Xr rlogin 1 958454ba768SRuslan Ermilovsuck rocks. 959454ba768SRuslan ErmilovThere are bugs that make them unsuitable for dealing with binary streams. 960454ba768SRuslan ErmilovAlso, by default 961454ba768SRuslan ErmilovKerberos does not encrypt a session unless you use the 962d93b26d6SMatthew Dillon.Fl x 963454ba768SRuslan Ermilovoption. 964454ba768SRuslan ErmilovSSH encrypts everything by default. 965d93b26d6SMatthew Dillon.Pp 966454ba768SRuslan ErmilovSSH works quite well in every respect except when it is set up to 9679baaab27SDima Dorfmanforward encryption keys. 9689baaab27SDima DorfmanWhat this means is that if you have a secure workstation holding 969454ba768SRuslan Ermilovkeys that give you access to the rest of the system, and you 970454ba768SRuslan Ermilov.Xr ssh 1 971454ba768SRuslan Ermilovto an 972454ba768SRuslan Ermilovunsecure machine, your keys become exposed. 973454ba768SRuslan ErmilovThe actual keys themselves are 974454ba768SRuslan Ermilovnot exposed, but 975454ba768SRuslan Ermilov.Xr ssh 1 976454ba768SRuslan Ermilovinstalls a forwarding port for the duration of your 97747afd1f8SDaniel Harrislogin and if an attacker has broken root on the unsecure machine he can utilize 978d93b26d6SMatthew Dillonthat port to use your keys to gain access to any other machine that your 979d93b26d6SMatthew Dillonkeys unlock. 980d93b26d6SMatthew Dillon.Pp 981454ba768SRuslan ErmilovWe recommend that you use SSH in combination with Kerberos whenever possible 982454ba768SRuslan Ermilovfor staff logins. 983454ba768SRuslan ErmilovSSH can be compiled with Kerberos support. 984454ba768SRuslan ErmilovThis reduces 985454ba768SRuslan Ermilovyour reliance on potentially exposable SSH keys while at the same time 986454ba768SRuslan Ermilovprotecting passwords via Kerberos. 987454ba768SRuslan ErmilovSSH keys 988d93b26d6SMatthew Dillonshould only be used for automated tasks from secure machines (something 989454ba768SRuslan Ermilovthat Kerberos is unsuited to). 990454ba768SRuslan ErmilovWe also recommend that you either turn off 991454ba768SRuslan Ermilovkey-forwarding in the SSH configuration, or that you make use of the 992454ba768SRuslan Ermilov.Va from Ns = Ns Ar IP/DOMAIN 993454ba768SRuslan Ermilovoption that SSH allows in its 994d93b26d6SMatthew Dillon.Pa authorized_keys 9957c86a74bSMike Pritchardfile to make the key only usable to entities logging in from specific 996d93b26d6SMatthew Dillonmachines. 997f063d76aSMatthew Dillon.Sh SEE ALSO 998f063d76aSMatthew Dillon.Xr chflags 1 , 999f063d76aSMatthew Dillon.Xr find 1 , 1000f063d76aSMatthew Dillon.Xr md5 1 , 1001f6f8f44dSAlexey Zelkin.Xr netstat 1 , 10028596de53SNik Clayton.Xr openssl 1 , 10035521ff5aSRuslan Ermilov.Xr ssh 1 , 1004f0ea72a0SChristian Brueffer.Xr xdm 1 Pq Pa ports/x11/xorg-clients , 1005d93b26d6SMatthew Dillon.Xr group 5 , 1006ad27d066SMatthew Dillon.Xr ttys 5 , 10078596de53SNik Clayton.Xr accton 8 , 1008d93b26d6SMatthew Dillon.Xr init 8 , 10098596de53SNik Clayton.Xr sshd 8 , 1010ad27d066SMatthew Dillon.Xr sysctl 8 , 10118596de53SNik Clayton.Xr syslogd 8 , 1012ad27d066SMatthew Dillon.Xr vipw 8 1013f063d76aSMatthew Dillon.Sh HISTORY 1014f063d76aSMatthew DillonThe 1015f063d76aSMatthew Dillon.Nm 1016568e4cbbSGuy Helmermanual page was originally written by 1017568e4cbbSGuy Helmer.An Matthew Dillon 1018568e4cbbSGuy Helmerand first appeared 1019568e4cbbSGuy Helmerin 102085752545SGuy Helmer.Fx 3.1 , 1021568e4cbbSGuy HelmerDecember 1998. 1022