home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 May / Gamestar_62_2004-05_dvd.iso / Programy / apache_2.0.48-win32-x86-no_ssl.msi / Data.Cab / F252417_security_tips.xml < prev    next >
Extensible Markup Language  |  2003-04-15  |  14KB  |  328 lines

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE manualpage SYSTEM "../style/manualpage.dtd">
  3. <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
  4.  
  5. <manualpage metafile="security_tips.xml.meta">
  6.   <parentdocument href="./">Miscellaneous Documentation</parentdocument>
  7.  
  8.   <title>Security Tips</title>
  9.   
  10.   <summary>
  11.     <p>Some hints and tips on security issues in setting up a web server. 
  12.     Some of the suggestions will be general, others specific to Apache.</p>
  13.   </summary>
  14.   
  15.   <section id="uptodate"><title>Keep up to Date</title>
  16.  
  17.     <p>The Apache HTTP Server has a good record for security and a
  18.     developer community highly concerned about security issues.  But
  19.     it is inevitable that some problems -- small or large -- will be
  20.     discovered in software after it is released.  For this reason, it
  21.     is crucial to keep aware of updates to the software.  If you have
  22.     obtained your version of the HTTP Server directly from Apache, we
  23.     highly recommend you subscribe to the <a
  24.     href="http://httpd.apache.org/lists.html#http-announce">Apache
  25.     HTTP Server Announcements List</a> where you can keep informed of
  26.     new releases and security updates.  Similar services are available
  27.     from most third-party distributors of Apache software.</p>
  28.  
  29.     <p>Of course, most times that a web server is compromised, it is
  30.     not because of problems in the HTTP Server code.  Rather, it comes
  31.     from problems in add-on code, CGI scripts, or the underlying
  32.     Operating System.  You must therefore stay aware of problems and
  33.     updates with all the software on your system.</p>
  34.  
  35.   </section>
  36.  
  37.   <section id="serverroot">
  38.   
  39.     <title>Permissions on ServerRoot Directories</title>
  40.     
  41.     <p>In typical operation, Apache is started by the root user, and it 
  42.     switches to the user defined by the <directive 
  43.     module="mpm_common">User</directive> directive to serve hits. As is the 
  44.     case with any command that root executes, you must take care that it is 
  45.     protected from modification by non-root users. Not only must the files 
  46.     themselves be writeable only by root, but so must the directories, and 
  47.     parents of all directories. For example, if you choose to place 
  48.     ServerRoot in  /usr/local/apache then it is suggested that you create 
  49.     that directory as root, with commands like these:</p>
  50.     
  51.     <example>
  52.       mkdir /usr/local/apache <br />
  53.       cd /usr/local/apache <br />
  54.       mkdir bin conf logs <br />
  55.       chown 0 . bin conf logs <br />
  56.       chgrp 0 . bin conf logs <br />
  57.       chmod 755 . bin conf logs
  58.     </example>
  59.     
  60.     <p>It is assumed that /, /usr, and /usr/local are only modifiable by 
  61.     root. When you install the httpd executable, you should ensure that 
  62.     it is similarly protected:</p>
  63.     
  64.     <example>
  65.       cp httpd /usr/local/apache/bin <br />
  66.       chown 0 /usr/local/apache/bin/httpd <br />
  67.       chgrp 0 /usr/local/apache/bin/httpd <br />
  68.       chmod 511 /usr/local/apache/bin/httpd
  69.     </example>
  70.     
  71.     <p>You can create an htdocs subdirectory which is modifiable by other 
  72.     users -- since root never executes any files out of there, and shouldn't 
  73.     be creating files in there.</p>
  74.     
  75.     <p>If you allow non-root users to modify any files that root either 
  76.     executes or writes on then you open your system to root compromises. 
  77.     For example, someone could replace the httpd binary so that the next 
  78.     time you start it, it will execute some arbitrary code. If the logs 
  79.     directory is writeable (by a non-root user), someone could replace 
  80.     a log file with a symlink to some other system file, and then root 
  81.     might overwrite that file with arbitrary data. If the log files 
  82.     themselves are writeable (by a non-root user), then someone may be 
  83.     able to overwrite the log itself with bogus data.</p>
  84.     
  85.   </section>
  86.   
  87.   <section id="ssi">
  88.   
  89.     <title>Server Side Includes</title>
  90.     
  91.     <p>Server Side Includes (SSI) present a server administrator with 
  92.     several potential security risks.</p>
  93.     
  94.     <p>The first risk is the increased load on the server. All 
  95.     SSI-enabled files have to be parsed by Apache, whether or not 
  96.     there are any SSI directives included within the files. While this 
  97.     load increase is minor, in a shared server environment it can become 
  98.     significant.</p>
  99.     
  100.     <p>SSI files also pose the same risks that are associated with CGI 
  101.     scripts in general. Using the "exec cmd" element, SSI-enabled files 
  102.     can execute any CGI script or program under the permissions of the 
  103.     user and group Apache runs as, as configured in httpd.conf.</p>
  104.     
  105.     <p>There are ways to enhance the security of SSI files while still 
  106.     taking advantage of the benefits they provide.</p>
  107.     
  108.     <p>To isolate the damage a wayward SSI file can cause, a server 
  109.     administrator can enable <a href="../suexec.html">suexec</a> as 
  110.     described in the <a href="#cgi">CGI in General</a> section</p>
  111.     
  112.     <p>Enabling SSI for files with .html or .htm extensions can be 
  113.     dangerous. This is especially true in a shared, or high traffic, 
  114.     server environment. SSI-enabled files should have a separate extension,
  115.     such as the conventional .shtml. This helps keep server load at a 
  116.     minimum and allows for easier management of risk.</p>
  117.     
  118.     <p>Another solution is to disable the ability to run scripts and 
  119.     programs from SSI pages. To do this replace <code>Includes</code>
  120.     with <code>IncludesNOEXEC</code> in the <directive
  121.     module="core">Options</directive> directive.  Note that users may 
  122.     still use <--#include virtual="..." --> to execute CGI scripts if 
  123.     these scripts are in directories desginated by a <directive
  124.     module="mod_alias">ScriptAlias</directive> directive.</p>
  125.     
  126.   </section>
  127.   
  128.   <section id="cgi">
  129.   
  130.     <title>CGI in General</title>
  131.     
  132.     <p>First of all, you always have to remember that you must trust the 
  133.     writers of the CGI scripts/programs or your ability to spot potential 
  134.     security holes in CGI, whether they were deliberate or accidental. CGI 
  135.     scripts can run essentially arbitrary commands on your system with the 
  136.     permissions of the web server user and can therefore be extremely 
  137.     dangerous if they are not carefully checked.</p>
  138.     
  139.     <p>All the CGI scripts will run as the same user, so they have potential 
  140.     to conflict (accidentally or deliberately) with other scripts e.g. User 
  141.     A hates User B, so he writes a script to trash User B's CGI database. One 
  142.     program which can be used to allow scripts to run as different users is
  143.     <a href="../suexec.html">suEXEC</a> which is included with Apache as of 
  144.     1.2 and is called from special hooks in the Apache server code. Another 
  145.     popular way of doing this is with 
  146.     <a href="http://cgiwrap.unixtools.org/">CGIWrap</a>.</p>
  147.     
  148.   </section>
  149.  
  150.   <section id="nsaliasedcgi">
  151.   
  152.     <title>Non Script Aliased CGI</title>
  153.     
  154.     <p>Allowing users to execute CGI scripts in any directory should only be 
  155.     considered if:</p>
  156.     
  157.     <ul>
  158.       <li>You trust your users not to write scripts which will deliberately 
  159.           or accidentally expose your system to an attack.</li>
  160.       <li>You consider security at your site to be so feeble in other areas, 
  161.           as to make one more potential hole irrelevant.</li>
  162.       <li>You have no users, and nobody ever visits your server.</li>
  163.     </ul>
  164.     
  165.   </section>
  166.   
  167.   <section id="saliasedcgi">
  168.   
  169.     <title>Script Aliased CGI</title>
  170.     
  171.     <p>Limiting CGI to special directories gives the admin control over what 
  172.     goes into those directories. This is inevitably more secure than non 
  173.     script aliased CGI, but only if users with write access to the 
  174.     directories are trusted or the admin is willing to test each 
  175.     new CGI script/program for potential security holes.</p>
  176.     
  177.     <p>Most sites choose this option over the non script aliased CGI 
  178.     approach.</p>
  179.     
  180.   </section>
  181.  
  182.    <section id="dynamic">
  183.  
  184.   <title>Other sources of dynamic content</title>
  185.  
  186.   <p>
  187.   Embedded scripting options which run as part of the server itself,
  188.   such as mod_php, mod_perl, mod_tcl, and mod_python, run under the
  189.   identity of the server itself (see the <directive 
  190.   module="mpm_common">User</directive> directive), and therefore
  191.   scripts executed by these engines potentially can access anything the
  192.   server user can. Some scripting engines may provide restrictions, but
  193.   it is better to be safe and assume not.</p>
  194.  
  195.   </section>
  196.   
  197.   <section id="systemsettings">
  198.   
  199.     <title>Protecting System Settings</title>
  200.     
  201.     <p>To run a really tight ship, you'll want to stop users from setting 
  202.     up <code>.htaccess</code> files which can override security features 
  203.     you've configured. Here's one way to do it.</p>
  204.     
  205.     <p>In the server configuration file, put</p>
  206.     
  207.     <example>
  208.       <Directory /> <br />
  209.         AllowOverride None <br />
  210.       </Directory>
  211.     </example>
  212.     
  213.     <p>This prevents the use of <code>.htaccess</code> files in all 
  214.     directories apart from those specifically enabled.</p>
  215.     
  216.   </section>
  217.   
  218.   <section id="protectserverfiles">
  219.   
  220.     <title>Protect Server Files by Default</title>
  221.     
  222.     <p>One aspect of Apache which is occasionally misunderstood is the 
  223.     feature of default access. That is, unless you take steps to change it, 
  224.     if the server can find its way to a file through normal URL mapping 
  225.     rules, it can serve it to clients.</p>
  226.     
  227.     <p>For instance, consider the following example:</p>
  228.     
  229.     <example>
  230.       # cd /; ln -s / public_html <br />
  231.       Accessing <code>http://localhost/~root/</code>
  232.     </example>
  233.     
  234.     <p>This would allow clients to walk through the entire filesystem. To 
  235.     work around this, add the following block to your server's 
  236.     configuration:</p>
  237.     
  238.     <example>
  239.       <Directory /> <br />
  240.       Order Deny,Allow <br />
  241.       Deny from all <br />
  242.       </Directory>
  243.     </example>
  244.     
  245.     <p>This will forbid default access to filesystem locations. Add 
  246.     appropriate <directive module="core">Directory</directive> blocks to 
  247.     allow access only in those areas you wish. For example,</p>
  248.     
  249.     <example>
  250.       <Directory /usr/users/*/public_html> <br />
  251.         Order Deny,Allow <br />
  252.         Allow from all <br />
  253.       </Directory> <br />
  254.       <Directory /usr/local/httpd> <br />
  255.         Order Deny,Allow <br />
  256.         Allow from all <br />
  257.       </Directory>
  258.     </example>
  259.     
  260.     <p>Pay particular attention to the interactions of <directive
  261.     module="core">Location</directive> and <directive 
  262.     module="core">Directory</directive> directives; for instance, even 
  263.     if <code><Directory /></code> denies access, a <code>
  264.     <Location /></code> directive might overturn it</p>
  265.     
  266.     <p>Also be wary of playing games with the <directive
  267.     module="mod_userdir">UserDir</directive> directive; setting it to 
  268.     something like "./" would have the same effect, for root, as the first 
  269.     example above. If you are using Apache 1.3 or above, we strongly 
  270.     recommend that you include the following line in your server 
  271.     configuration files:</p>
  272.     
  273.     <example>
  274.       UserDir disabled root
  275.     </example>
  276.     
  277.   </section>
  278.   
  279.   <section id="watchyourlogs">
  280.   
  281.     <title>Watching Your Logs</title>
  282.     
  283.     <p>To keep up-to-date with what is actually going on against your server 
  284.     you have to check the <a href="../logs.html">Log Files</a>.  Even though 
  285.     the log files only reports what has already happend, they will give you 
  286.     some understanding of what attacks is thrown against the server and 
  287.     allows you to check if the necessary level of security is present.</p>
  288.     
  289.     <p>A couple of examples:</p>
  290.     
  291.     <example>
  292.       grep -c "/jsp/source.jsp?/jsp/ /jsp/source.jsp??" access_log <br />
  293.       grep "client denied" error_log | tail -n 10
  294.     </example>
  295.     
  296.     <p>The first example will list the number of attacks trying to exploit the
  297.     <a href="http://online.securityfocus.com/bid/4876/info/">Apache Tomcat 
  298.     Source.JSP Malformed Request Information Disclosure Vulnerability</a>, 
  299.     the second example will list the ten last denied clients, for example:</p>
  300.     
  301.     <example>
  302.       [Thu Jul 11 17:18:39 2002] [error] [client foo.bar.com] client denied 
  303.       by server configuration: /usr/local/apache/htdocs/.htpasswd
  304.     </example>
  305.     
  306.     <p>As you can see, the log files only report what already has happend, so 
  307.     if the client had been able to access the <code>.htpasswd</code> file you 
  308.     would have seen something similar to:</p>
  309.     
  310.     <example>
  311.       foo.bar.com - - [12/Jul/2002:01:59:13 +0200] "GET /.htpasswd HTTP/1.1"
  312.     </example>
  313.     
  314.     <p>in your <a href="../logs.html#accesslog">Access Log</a>. This means 
  315.     you probably commented out the following in your server configuration 
  316.     file:</p>
  317.     
  318.     <example>
  319.       <Files ~ "^\.ht"> <br />
  320.         Order allow,deny <br />
  321.         Deny from all <br />
  322.       <Files>
  323.     </example>
  324.     
  325.   </section>
  326.   
  327. </manualpage>
  328.