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