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