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