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