📄 securing-freebsd.html
字号:
willing to perform (the convenience factor strikes again). You may have to run theseservers as <tt class="USERNAME">root</tt> and rely on other mechanisms to detectbreak-ins that might occur through them.</p><p>The other big potential <tt class="USERNAME">root</tt> holes in a system are thesuid-root and sgid binaries installed on the system. Most of these binaries, such as <bclass="APPLICATION">rlogin</b>, reside in <tt class="FILENAME">/bin</tt>, <ttclass="FILENAME">/sbin</tt>, <tt class="FILENAME">/usr/bin</tt>, or <ttclass="FILENAME">/usr/sbin</tt>. While nothing is 100% safe, the system-default suid andsgid binaries can be considered reasonably safe. Still, <tt class="USERNAME">root</tt>holes are occasionally found in these binaries. A <tt class="USERNAME">root</tt> hole wasfound in <var class="LITERAL">Xlib</var> in 1998 that made <bclass="APPLICATION">xterm</b> (which is typically suid) vulnerable. It is better to besafe than sorry and the prudent sysadmin will restrict suid binaries, that only staffshould run, to a special group that only staff can access, and get rid of (<ttclass="COMMAND">chmod 000</tt>) any suid binaries that nobody uses. A server with nodisplay generally does not need an <b class="APPLICATION">xterm</b> binary. Sgid binariescan be almost as dangerous. If an intruder can break an sgid-kmem binary, the intrudermight be able to read <tt class="FILENAME">/dev/kmem</tt> and thus read the encryptedpassword file, potentially compromising any passworded account. Alternatively an intruderwho breaks group <var class="LITERAL">kmem</var> can monitor keystrokes sent throughptys, including Pt's used by users who login through secure methods. An intruder thatbreaks the <tt class="GROUPNAME">tty</tt> group can write to almost any user's tty. If auser is running a terminal program or emulator with a keyboard-simulation feature, theintruder can potentially generate a data stream that causes the user's terminal to echo acommand, which is then run as that user.</p></div><div class="SECT2"><h2 class="SECT2"><a id="SECURE-USERS" name="SECURE-USERS">14.3.3 Securing UserAccounts</a></h2><p>User accounts are usually the most difficult to secure. While you can impose Draconianaccess restrictions on your staff and ``star'' out their passwords, you may not be ableto do so with any general user accounts you might have. If you do have sufficientcontrol, then you may win out and be able to secure the user accounts properly. If not,you simply have to be more vigilant in your monitoring of those accounts. Use of ssh andKerberos for user accounts is more problematic, due to the extra administration andtechnical support required, but still a very good solution compared to a crypted passwordfile.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN18948" name="AEN18948">14.3.4 Securing the PasswordFile</a></h2><p>The only sure fire way is to <var class="LITERAL">*</var> out as many passwords as youcan and use ssh or Kerberos for access to those accounts. Even though the encryptedpassword file (<tt class="FILENAME">/etc/spwd.db</tt>) can only be read by <ttclass="USERNAME">root</tt>, it may be possible for an intruder to obtain read access tothat file even if the attacker cannot obtain root-write access.</p><p>Your security scripts should always check for and report changes to the password file(see the <a href="securing-freebsd.html#SECURITY-INTEGRITY">Checking file integrity</a>section below).</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN18956" name="AEN18956">14.3.5 Securing the Kernel Core, RawDevices, and File systems</a></h2><p>If an attacker breaks <tt class="USERNAME">root</tt> he can do just about anything,but there are certain conveniences. For example, most modern kernels have a packetsniffing device driver built in. Under FreeBSD it is called the <ttclass="DEVICENAME">bpf</tt> device. An intruder will commonly attempt to run a packetsniffer on a compromised machine. You do not need to give the intruder the capability andmost systems do not have the need for the <tt class="DEVICENAME">bpf</tt> device compiledin.</p><p>But even if you turn off the <tt class="DEVICENAME">bpf</tt> device, you still have<tt class="FILENAME">/dev/mem</tt> and <tt class="FILENAME">/dev/kmem</tt> to worryabout. For that matter, the intruder can still write to raw disk devices. Also, there isanother kernel feature called the module loader, <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=kldload&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">kldload</span>(8)</span></a>. Anenterprising intruder can use a KLD module to install his own <ttclass="DEVICENAME">bpf</tt> device, or other sniffing device, on a running kernel. Toavoid these problems you have to run the kernel at a higher secure level, at leastsecurelevel 1. The securelevel can be set with a <tt class="COMMAND">sysctl</tt> on the<var class="VARNAME">kern.securelevel</var> variable. Once you have set the securelevelto 1, write access to raw devices will be denied and special <ttclass="COMMAND">chflags</tt> flags, such as <var class="LITERAL">schg</var>, will beenforced. You must also ensure that the <var class="LITERAL">schg</var> flag is set oncritical startup binaries, directories, and script files -- everything that gets run upto the point where the securelevel is set. This might be overdoing it, and upgrading thesystem is much more difficult when you operate at a higher secure level. You maycompromise and run the system at a higher secure level but not set the <varclass="LITERAL">schg</var> flag for every system file and directory under the sun.Another possibility is to simply mount <tt class="FILENAME">/</tt> and <ttclass="FILENAME">/usr</tt> read-only. It should be noted that being too Draconian in whatyou attempt to protect may prevent the all-important detection of an intrusion.</p></div><div class="SECT2"><h2 class="SECT2"><a id="SECURITY-INTEGRITY" name="SECURITY-INTEGRITY">14.3.6 CheckingFile Integrity: Binaries, Configuration Files, Etc.</a></h2><p>When it comes right down to it, you can only protect your core system configurationand control files so much before the convenience factor rears its ugly head. For example,using <tt class="COMMAND">chflags</tt> to set the <var class="LITERAL">schg</var> bit onmost of the files in <tt class="FILENAME">/</tt> and <tt class="FILENAME">/usr</tt> isprobably counterproductive, because while it may protect the files, it also closes adetection window. The last layer of your security onion is perhaps the most important --detection. The rest of your security is pretty much useless (or, worse, presents you witha false sense of safety) if you cannot detect potential incursions. Half the job of theonion is to slow down the attacker, rather than stop him, in order to give the detectionside of the equation a chance to catch him in the act.</p><p>The best way to detect an incursion is to look for modified, missing, or unexpectedfiles. The best way to look for modified files is from another (often centralized)limited-access system. Writing your security scripts on the extra-secure limited-accesssystem makes them mostly invisible to potential attackers, and this is important. Inorder to take maximum advantage you generally have to give the limited-access boxsignificant access to the other machines in the business, usually either by doing aread-only NFS export of the other machines to the limited-access box, or by setting upssh key-pairs to allow the limited-access box to ssh to the other machines. Except forits network traffic, NFS is the least visible method -- allowing you to monitor the filesystems on each client box virtually undetected. If your limited-access server isconnected to the client boxes through a switch, the NFS method is often the betterchoice. If your limited-access server is connected to the client boxes through a hub, orthrough several layers of routing, the NFS method may be too insecure (network-wise) andusing ssh may be the better choice even with the audit-trail tracks that ssh lays.</p><p>Once you give a limited-access box, at least read access to the client systems it issupposed to monitor, you must write scripts to do the actual monitoring. Given an NFSmount, you can write scripts out of simple system utilities such as <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=find&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">find</span>(1)</span></a> and <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=md5&sektion=1"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">md5</span>(1)</span></a>. It is best tophysically md5 the client-box files at least once a day, and to test control files suchas those found in <tt class="FILENAME">/etc</tt> and <ttclass="FILENAME">/usr/local/etc</tt> even more often. When mismatches are found, relativeto the base md5 information the limited-access machine knows is valid, it should screamat a sysadmin to go check it out. A good security script will also check forinappropriate suid binaries and for new or deleted files on system partitions such as <ttclass="FILENAME">/</tt> and <tt class="FILENAME">/usr</tt>.</p><p>When using ssh rather than NFS, writing the security script is much more difficult.You essentially have to <tt class="COMMAND">scp</tt> the scripts to the client box inorder to run them, making them visible, and for safety you also need to <ttclass="COMMAND">scp</tt> the binaries (such as find) that those scripts use. The <bclass="APPLICATION">ssh</b> client on the client box may already be compromised. All inall, using ssh may be necessary when running over insecure links, but it is also a lotharder to deal with.</p><p>A good security script will also check for changes to user and staff members accessconfiguration files: <tt class="FILENAME">.rhosts</tt>, <ttclass="FILENAME">.shosts</tt>, <tt class="FILENAME">.ssh/authorized_keys</tt> and soforth... files that might fall outside the purview of the <var class="LITERAL">MD5</var>check.</p><p>If you have a huge amount of user disk space, it may take too long to run throughevery file on those partitions. In this case, setting mount flags to disallow suidbinaries and devices on those partitions is a good idea. The <varclass="LITERAL">nodev</var> and <var class="LITERAL">nosuid</var> options (see <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=mount&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">mount</span>(8)</span></a>) are what youwant to look into. You should probably scan them anyway, at least once a week, since theobject of this layer is to detect a break-in whether or not the break-in iseffective.</p><p>Process accounting (see <ahref="http://www.FreeBSD.org/cgi/man.cgi?query=accton&sektion=8"><spanclass="CITEREFENTRY"><span class="REFENTRYTITLE">accton</span>(8)</span></a>) is arelatively low-overhead feature of the operating system which might help as apost-break-in evaluation mechanism. It is especially useful in tracking down how anintruder has actually broken into a system, assuming the file is still intact after thebreak-in occurs.</p><p>Finally, security scripts should process the log files, and the logs themselves shouldbe generated in as secure a manner as possible -- remote syslog can be very useful. Anintruder tries to cover his tracks, and log files are critical to the sysadmin trying totrack down the time and method of the initial break-in. One way to keep a permanentrecord of the log files is to run the system console to a serial port and collect theinformation on a continuing basis through a secure machine monitoring the consoles.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN19020" name="AEN19020">14.3.7 Paranoia</a></h2><p>A little paranoia never hurts. As a rule, a sysadmin can add any number of securityfeatures, as long as they do not affect convenience, and can add security features that<span class="emphasis"><i class="EMPHASIS">do</i></span> affect convenience with someadded thought. Even more importantly, a security administrator should mix it up a bit --if you use recommendations such as those given by this document verbatim, you give awayyour methodologies to the prospective attacker who also has access to this document.</p></div><div class="SECT2"><h2 class="SECT2"><a id="AEN19024" name="AEN19024">14.3.8 Denial of ServiceAttacks</a></h2><p>This section covers Denial of Service attacks. A DoS attack is typically a packetattack. While there is not much you can do about modern spoofed packet attacks thatsaturate your network, you can generally limit the damage by ensuring that the attackscannot take down your servers.</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -