security_tips.xml revision db479b48bd4d75423ed4a45e15b75089d1a8ad72
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony<?xml version="1.0" encoding="UTF-8" ?>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony<!DOCTYPE manualpage SYSTEM "/style/manualpage.dtd">
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
a7f7b4fafb3773005d3126f003cff159c03e72a0nilgun<!-- $LastChangedRevision$ -->
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony<!--
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony Licensed to the Apache Software Foundation (ASF) under one or more
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony contributor license agreements. See the NOTICE file distributed with
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony this work for additional information regarding copyright ownership.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony The ASF licenses this file to You under the Apache License, Version 2.0
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony (the "License"); you may not use this file except in compliance with
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony the License. You may obtain a copy of the License at
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony http://www.apache.org/licenses/LICENSE-2.0
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony Unless required by applicable law or agreed to in writing, software
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony distributed under the License is distributed on an "AS IS" BASIS,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony See the License for the specific language governing permissions and
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony limitations under the License.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony-->
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony<manualpage metafile="security_tips.xml.meta">
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <parentdocument href="./">Miscellaneous Documentation</parentdocument>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <title>Security Tips</title>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <summary>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>Some hints and tips on security issues in setting up a web server.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony Some of the suggestions will be general, others specific to Apache.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </summary>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <section id="uptodate"><title>Keep up to Date</title>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>The Apache HTTP Server has a good record for security and a
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony developer community highly concerned about security issues. But
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony it is inevitable that some problems -- small or large -- will be
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony discovered in software after it is released. For this reason, it
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony is crucial to keep aware of updates to the software. If you have
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony obtained your version of the HTTP Server directly from Apache, we
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony highly recommend you subscribe to the <a
331e0914b4c54463a06069051f0245b4058a90c2nilgun href="http://httpd.apache.org/lists.html#http-announce">Apache
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony HTTP Server Announcements List</a> where you can keep informed of
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony new releases and security updates. Similar services are available
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony from most third-party distributors of Apache software.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>Of course, most times that a web server is compromised, it is
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony not because of problems in the HTTP Server code. Rather, it comes
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony from problems in add-on code, CGI scripts, or the underlying
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony Operating System. You must therefore stay aware of problems and
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony updates with all the software on your system.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </section>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <section id="dos">
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <title>Denial of Service (DoS) attacks</title>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>All network servers can be subject to denial of service attacks
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony that attempt to prevent responses to clients by tying up the
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony resources of the server. It is not possible to prevent such
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony attacks entirely, but you can do certain things to mitigate the
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony problems that they create.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>Often the most effective anti-DoS tool will be a firewall or
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony other operating-system configurations. For example, most
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony firewalls can be configured to restrict the number of simultaneous
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony connections from any individual IP address or network, thus
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony preventing a range of simple attacks. Of course this is no help
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony against Distributed Denial of Service attacks (DDoS).</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>There are also certain Apache HTTP Server configuration
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony settings that can help mitigate problems:</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <ul>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <li>The <directive module="core">TimeOut</directive> directive
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony should be lowered on sites that are subject to DoS attacks.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony Setting this to as low as a few seconds may be appropriate.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony As <directive module="core">TimeOut</directive> is currently
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony used for several different operations, setting it to a low value
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony introduces problems with long running CGI scripts.</li>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <li>The <directive module="core">KeepAliveTimeout</directive>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony directive may be also lowered on sites that are subject to DoS
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony attacks. Some sites even turn off the keepalives completely via
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <directive module="core">KeepAlive</directive>, which has of course
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony other drawbacks on performance.</li>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <li>The values of various timeout-related directives provided by
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony other modules should be checked.</li>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <li>The directives
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <directive module="core">LimitRequestBody</directive>,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <directive module="core">LimitRequestFields</directive>,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <directive module="core">LimitRequestFieldSize</directive>,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <directive module="core">LimitRequestLine</directive>, and
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <directive module="core">LimitXMLRequestBody</directive>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony should be carefully configured to limit resource consumption
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony triggered by client input.</li>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <li>On operating systems that support it, make sure that you use
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony the <directive module="core">AcceptFilter</directive> directive
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony to offload part of the request processing to the operating
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony system. This is active by default in Apache httpd, but may
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony require reconfiguration of your kernel.</li>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <li>Tune the <directive
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony module="mpm_common">MaxClients</directive> directive to allow
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony the server to handle the maximum number of simultaneous
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony connections without running out of resources. See also the <a
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony href="perf-tuning.html">performance tuning
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony documentation</a>.</li>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <li>The use of a threaded <a href="/mpm.html">mpm</a> may
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony allow you to handle more simultaneous connections, thereby
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony mitigating DoS attacks. Further, the experimental
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <module>event</module> mpm
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony uses asynchronous processing to avoid devoting a thread to each
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony connection. At the current point of time this
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony is work in progress and not fully implemented. Especially the
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <module>event</module> mpm is currently incompatible with
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <module>mod_ssl</module> and other input filters.</li>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <li>There are a number of third-party modules available through
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <a
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony href="http://modules.apache.org/">http://modules.apache.org/</a>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony that can restrict certain client behaviors and thereby mitigate
331e0914b4c54463a06069051f0245b4058a90c2nilgun DoS problems.</li>
331e0914b4c54463a06069051f0245b4058a90c2nilgun
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </ul>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </section>
4d59c48d506af681afac46a88516e369495c1ae4nilgun
4d59c48d506af681afac46a88516e369495c1ae4nilgun
4d59c48d506af681afac46a88516e369495c1ae4nilgun <section id="serverroot">
4d59c48d506af681afac46a88516e369495c1ae4nilgun
4d59c48d506af681afac46a88516e369495c1ae4nilgun <title>Permissions on ServerRoot Directories</title>
4d59c48d506af681afac46a88516e369495c1ae4nilgun
4d59c48d506af681afac46a88516e369495c1ae4nilgun <p>In typical operation, Apache is started by the root user, and it
4d59c48d506af681afac46a88516e369495c1ae4nilgun switches to the user defined by the <directive
4d59c48d506af681afac46a88516e369495c1ae4nilgun module="mpm_common">User</directive> directive to serve hits. As is the
4d59c48d506af681afac46a88516e369495c1ae4nilgun case with any command that root executes, you must take care that it is
4d59c48d506af681afac46a88516e369495c1ae4nilgun protected from modification by non-root users. Not only must the files
4d59c48d506af681afac46a88516e369495c1ae4nilgun themselves be writeable only by root, but so must the directories, and
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony parents of all directories. For example, if you choose to place
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony ServerRoot in /usr/local/apache then it is suggested that you create
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony that directory as root, with commands like these:</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony mkdir /usr/local/apache <br />
4d59c48d506af681afac46a88516e369495c1ae4nilgun cd /usr/local/apache <br />
4d59c48d506af681afac46a88516e369495c1ae4nilgun mkdir bin conf logs <br />
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony chown 0 . bin conf logs <br />
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony chgrp 0 . bin conf logs <br />
4d59c48d506af681afac46a88516e369495c1ae4nilgun chmod 755 . bin conf logs
4d59c48d506af681afac46a88516e369495c1ae4nilgun </example>
4d59c48d506af681afac46a88516e369495c1ae4nilgun
4d59c48d506af681afac46a88516e369495c1ae4nilgun <p>It is assumed that /, /usr, and /usr/local are only modifiable by
4d59c48d506af681afac46a88516e369495c1ae4nilgun root. When you install the <program>httpd</program> executable, you
4d59c48d506af681afac46a88516e369495c1ae4nilgun should ensure that it is similarly protected:</p>
4d59c48d506af681afac46a88516e369495c1ae4nilgun
4d59c48d506af681afac46a88516e369495c1ae4nilgun <example>
4d59c48d506af681afac46a88516e369495c1ae4nilgun cp httpd /usr/local/apache/bin <br />
4d59c48d506af681afac46a88516e369495c1ae4nilgun chown 0 /usr/local/apache/bin/httpd <br />
4d59c48d506af681afac46a88516e369495c1ae4nilgun chgrp 0 /usr/local/apache/bin/httpd <br />
4d59c48d506af681afac46a88516e369495c1ae4nilgun chmod 511 /usr/local/apache/bin/httpd
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>You can create an htdocs subdirectory which is modifiable by other
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony users -- since root never executes any files out of there, and shouldn't
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony be creating files in there.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>If you allow non-root users to modify any files that root either
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony executes or writes on then you open your system to root compromises.
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony For example, someone could replace the <program>httpd</program> binary so
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony that the next time you start it, it will execute some arbitrary code. If
331e0914b4c54463a06069051f0245b4058a90c2nilgun the logs directory is writeable (by a non-root user), someone could replace
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony a log file with a symlink to some other system file, and then root
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony might overwrite that file with arbitrary data. If the log files
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony themselves are writeable (by a non-root user), then someone may be
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony able to overwrite the log itself with bogus data.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </section>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <section id="ssi">
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <title>Server Side Includes</title>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>Server Side Includes (SSI) present a server administrator with
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony several potential security risks.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>The first risk is the increased load on the server. All
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony SSI-enabled files have to be parsed by Apache, whether or not
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony there are any SSI directives included within the files. While this
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony load increase is minor, in a shared server environment it can become
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony significant.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>SSI files also pose the same risks that are associated with CGI
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony scripts in general. Using the "exec cmd" element, SSI-enabled files
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony can execute any CGI script or program under the permissions of the
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony user and group Apache runs as, as configured in httpd.conf.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>There are ways to enhance the security of SSI files while still
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony taking advantage of the benefits they provide.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>To isolate the damage a wayward SSI file can cause, a server
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony administrator can enable <a href="/suexec.html">suexec</a> as
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony described in the <a href="#cgi">CGI in General</a> section</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>Enabling SSI for files with .html or .htm extensions can be
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony dangerous. This is especially true in a shared, or high traffic,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony server environment. SSI-enabled files should have a separate extension,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony such as the conventional .shtml. This helps keep server load at a
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony minimum and allows for easier management of risk.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>Another solution is to disable the ability to run scripts and
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony programs from SSI pages. To do this replace <code>Includes</code>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony with <code>IncludesNOEXEC</code> in the <directive
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony module="core">Options</directive> directive. Note that users may
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony still use &lt;--#include virtual="..." --&gt; to execute CGI scripts if
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony these scripts are in directories desginated by a <directive
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony module="mod_alias">ScriptAlias</directive> directive.</p>
a7f7b4fafb3773005d3126f003cff159c03e72a0nilgun
a7f7b4fafb3773005d3126f003cff159c03e72a0nilgun </section>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <section id="cgi">
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <title>CGI in General</title>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>First of all, you always have to remember that you must trust the
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony writers of the CGI scripts/programs or your ability to spot potential
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony security holes in CGI, whether they were deliberate or accidental. CGI
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony scripts can run essentially arbitrary commands on your system with the
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony permissions of the web server user and can therefore be extremely
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony dangerous if they are not carefully checked.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>All the CGI scripts will run as the same user, so they have potential
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony to conflict (accidentally or deliberately) with other scripts e.g. User
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony A hates User B, so he writes a script to trash User B's CGI database. One
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony program which can be used to allow scripts to run as different users is
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <a href="/suexec.html">suEXEC</a> which is included with Apache as of
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony 1.2 and is called from special hooks in the Apache server code. Another
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony popular way of doing this is with
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <a href="http://cgiwrap.unixtools.org/">CGIWrap</a>.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </section>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <section id="nsaliasedcgi">
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <title>Non Script Aliased CGI</title>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>Allowing users to execute CGI scripts in any directory should only be
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony considered if:</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <ul>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <li>You trust your users not to write scripts which will deliberately
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony or accidentally expose your system to an attack.</li>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <li>You consider security at your site to be so feeble in other areas,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony as to make one more potential hole irrelevant.</li>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <li>You have no users, and nobody ever visits your server.</li>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </ul>
331e0914b4c54463a06069051f0245b4058a90c2nilgun
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </section>
331e0914b4c54463a06069051f0245b4058a90c2nilgun
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <section id="saliasedcgi">
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <title>Script Aliased CGI</title>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>Limiting CGI to special directories gives the admin control over what
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony goes into those directories. This is inevitably more secure than non
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony script aliased CGI, but only if users with write access to the
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony directories are trusted or the admin is willing to test each
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony new CGI script/program for potential security holes.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>Most sites choose this option over the non script aliased CGI
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony approach.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </section>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <section id="dynamic">
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <title>Other sources of dynamic content</title>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony Embedded scripting options which run as part of the server itself,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony such as mod_php, mod_perl, mod_tcl, and mod_python, run under the
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony identity of the server itself (see the <directive
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony module="mpm_common">User</directive> directive), and therefore
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony scripts executed by these engines potentially can access anything the
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony server user can. Some scripting engines may provide restrictions, but
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony it is better to be safe and assume not.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </section>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <section id="systemsettings">
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <title>Protecting System Settings</title>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>To run a really tight ship, you'll want to stop users from setting
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony up <code>.htaccess</code> files which can override security features
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony you've configured. Here's one way to do it.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>In the server configuration file, put</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony &lt;Directory /&gt; <br />
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony AllowOverride None <br />
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony &lt;/Directory&gt;
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>This prevents the use of <code>.htaccess</code> files in all
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony directories apart from those specifically enabled.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </section>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <section id="protectserverfiles">
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <title>Protect Server Files by Default</title>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>One aspect of Apache which is occasionally misunderstood is the
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony feature of default access. That is, unless you take steps to change it,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony if the server can find its way to a file through normal URL mapping
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony rules, it can serve it to clients.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>For instance, consider the following example:</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony # cd /; ln -s / public_html <br />
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony Accessing <code>http://localhost/~root/</code>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>This would allow clients to walk through the entire filesystem. To
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony work around this, add the following block to your server's
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony configuration:</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony &lt;Directory /&gt; <br />
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony Order Deny,Allow <br />
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony Deny from all <br />
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony &lt;/Directory&gt;
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>This will forbid default access to filesystem locations. Add
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony appropriate <directive module="core">Directory</directive> blocks to
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony allow access only in those areas you wish. For example,</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony &lt;Directory /usr/users/*/public_html&gt; <br />
a7f7b4fafb3773005d3126f003cff159c03e72a0nilgun Order Deny,Allow <br />
a7f7b4fafb3773005d3126f003cff159c03e72a0nilgun Allow from all <br />
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony &lt;/Directory&gt; <br />
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony &lt;Directory /usr/local/httpd&gt; <br />
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony Order Deny,Allow <br />
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony Allow from all <br />
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony &lt;/Directory&gt;
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>Pay particular attention to the interactions of <directive
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony module="core">Location</directive> and <directive
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony module="core">Directory</directive> directives; for instance, even
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony if <code>&lt;Directory /&gt;</code> denies access, a <code>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony &lt;Location /&gt;</code> directive might overturn it</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>Also be wary of playing games with the <directive
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony module="mod_userdir">UserDir</directive> directive; setting it to
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony something like "./" would have the same effect, for root, as the first
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony example above. If you are using Apache 1.3 or above, we strongly
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony recommend that you include the following line in your server
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony configuration files:</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony UserDir disabled root
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
331e0914b4c54463a06069051f0245b4058a90c2nilgun </section>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <section id="watchyourlogs">
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <title>Watching Your Logs</title>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>To keep up-to-date with what is actually going on against your server
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony you have to check the <a href="/logs.html">Log Files</a>. Even though
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony the log files only reports what has already happened, they will give you
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony some understanding of what attacks is thrown against the server and
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony allows you to check if the necessary level of security is present.</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>A couple of examples:</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony grep -c "/jsp/source.jsp?/jsp/ /jsp/source.jsp??" access_log <br />
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony grep "client denied" error_log | tail -n 10
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>The first example will list the number of attacks trying to exploit the
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <a href="http://online.securityfocus.com/bid/4876/info/">Apache Tomcat
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony Source.JSP Malformed Request Information Disclosure Vulnerability</a>,
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony the second example will list the ten last denied clients, for example:</p>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony [Thu Jul 11 17:18:39 2002] [error] [client foo.bar.com] client denied
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony by server configuration: /usr/local/apache/htdocs/.htpasswd
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>As you can see, the log files only report what already has happened, so
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony if the client had been able to access the <code>.htpasswd</code> file you
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony would have seen something similar to:</p>
ff11394b10b5608991f43efb5308193b6d6001dfnilgun
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <example>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony foo.bar.com - - [12/Jul/2002:01:59:13 +0200] "GET /.htpasswd HTTP/1.1"
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </example>
331e0914b4c54463a06069051f0245b4058a90c2nilgun
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony <p>in your <a href="/logs.html#accesslog">Access Log</a>. This means
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony you probably commented out the following in your server configuration
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony file:</p>
ff11394b10b5608991f43efb5308193b6d6001dfnilgun
ff11394b10b5608991f43efb5308193b6d6001dfnilgun <example>
ff11394b10b5608991f43efb5308193b6d6001dfnilgun &lt;Files ~ "^\.ht"&gt; <br />
ff11394b10b5608991f43efb5308193b6d6001dfnilgun Order allow,deny <br />
ff11394b10b5608991f43efb5308193b6d6001dfnilgun Deny from all <br />
ff11394b10b5608991f43efb5308193b6d6001dfnilgun &lt;/Files&gt;
ff11394b10b5608991f43efb5308193b6d6001dfnilgun </example>
ff11394b10b5608991f43efb5308193b6d6001dfnilgun
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony </section>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony</manualpage>
4a7be288e6fc28a6cb940e26542dbf574bc907b9pctony