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