home *** CD-ROM | disk | FTP | other *** search
/ The Hacker's Encyclopedia 1998 / hackers_encyclopedia.iso / hacking / unix / apache11.txt < prev    next >
Encoding:
Text File  |  2003-06-11  |  9.9 KB  |  253 lines

  1.                         ######    ##   ##    ######
  2.                         ##        ###  ##      ##
  3.                         ######    ## # ##      ##
  4.                             ##    ##  ###      ##
  5.                         ###### .  ##   ## .  ######.
  6.  
  7.                             Secure Networks Inc.
  8.  
  9.                              Security Advisory
  10.                              January 12, 1997
  11.  
  12.                     Vulnerabilities in the Apache httpd
  13.  
  14. There is a serious vulnerability in the cookies module of the Apache httpd,
  15. version 1.1.1 and earlier, which makes it possible for remote individuals
  16. to obtain access to systems running the Apache httpd.  Only sites which
  17. enabled mod_cookies, a nondefault option, are vulnerable.
  18.  
  19. Technical Details
  20. ~~~~~~~~~~~~~~~~~
  21. The function make_cookie, in mod_cookies.c uses a 100 byte buffer,
  22. new_cookie to store information used to track web site users.  The
  23. hostname, which with even the most cautious of resolver libraries, can be
  24. up to 255 characters long, is stuffed into this buffer, along with the
  25. string "apache=" and a number.  The offending code reads:
  26.  
  27. void make_cookie(request_rec *r)
  28. {
  29.     struct timeval tv;
  30.     char new_cookie[100];       /* blurgh */
  31.     char *dot;
  32.     const char *rname = pstrdup(r->pool,
  33.                                 get_remote_host(r->connection, r->per_dir_config,
  34.                                                 REMOTE_NAME));
  35. struct timezone tz = { 0 , 0 };
  36.     if ((dot = strchr(rname,'.'))) *dot='\0';   /* First bit of hostname */
  37.     gettimeofday(&tv, &tz);
  38.     sprintf(new_cookie,"%s%s%d%ld%d; path=/",
  39.         COOKIE_NAME, rname,
  40.         (int)getpid(),
  41.         (long)tv.tv_sec, (int)tv.tv_usec/1000 );
  42.     table_set(r->headers_out,"Set-Cookie",new_cookie);
  43.     return;
  44. }
  45.  
  46. Note that although the get_remote_host() function converts all uppercase
  47. letters to lowercase letters, there is at least one way in which a
  48. determined attacker can still exploit the overflow.
  49.  
  50.  
  51. Impact
  52. ~~~~~~
  53. Remote individuals can obtain access to the web server.  If the httpd
  54. services requests as user root, attackers can obtain root access.  If the
  55. httpd is run in a chroot() environment, the attacker will be restricted to
  56. the chrooted environment.  We strongly advise adminstrators to run their
  57. web servers as an unpriviliged user in an chrooted environment whenever
  58. possible.
  59.  
  60.  
  61. Vulnerable Systems
  62. ~~~~~~~~~~~~~~~~~~
  63. Any system running the Apache httpd 1.1.1 or earlier, with the compile-time
  64. option mod_cookies enabled is vulnerable.  To tell which web server
  65. software you are using, telnet to port 80 of the web server, and issue the
  66. command:
  67. GET / HTTP/1.0
  68. to the web server, followed by two carriage returns.  You should see
  69. something which looks like:
  70.  
  71. $ telnet localhost 80
  72. Trying 127.0.0.1...
  73. Connected to localhost.
  74. Escape character is '^]'.
  75. GET / HTTP/1.0
  76.  
  77. HTTP/1.0 200 OK
  78. Date: Tue, 07 Jan 1997 18:59:31 GMT
  79. Server: Apache/1.1.1
  80. Content-type: text/html
  81. Set-Cookie: Apache=localhost9185266357164; path=/
  82. .
  83. .
  84. .
  85. The important lines to look at are the Server: lines, and the Set-Cookie:
  86. lines.  The Server: line tells you which web server software you are
  87. running, and the Set-Cookie line appears only if your web server is
  88. using cookies to track users.  If the Set-Cookie: line appears, and the
  89. Server: line reads Apache/1.1.1, or a number smaller than 1.1.1, then you
  90. are vulnerable.
  91.  
  92. Apache versions 1.2b0 and later do not appear to be vulnerable.  This is
  93. because of the changes made to the cookie handling code when it was moved
  94. to mod_usertrack.  As part of these changes, the buffer in the make_cookie
  95. function was moved off of the stack.  Therefore although the overflow is
  96. still present, and prevents users with long host names from accessing the
  97. web server, it is not likely to be exploitable.
  98.  
  99. In addition to the Apache httpd, some commercial web servers derived from
  100. the Apache httpd are likely to be vulnerable.  In particular, Thawte
  101. Consulting's Sioux server, and Community ConneXion's Stronghold server
  102. appear likely to be vulnerable.  In both cases, as in the Apache httpd, a
  103. nondefault compile-time option must be enabled.  Exploitability of web
  104. server software other than the Apache httpd has not been verified.  Users
  105. of Apache derived web servers should disable mod_cookies if enabled, and
  106. contact their vendors for further information.
  107.  
  108.  
  109.  
  110. Fix Information
  111. ~~~~~~~~~~~~~~~
  112. We suggest increasing the buffer length to handle 255 character hostnames,
  113. and verifying that hostname length is within acceptable limits.
  114.  
  115. The Apache group suggests that Apache 1.1.1 users do one of the following:
  116. 1. Upgrade to Apache 1.1.2, which can be obtained at
  117.    http://www.apache.org/dist/, compile the new version, then kill
  118.    your currently-running httpd, and start the new version.
  119. 2. Apply the attached  patch to mod_cookies.c, recompile, and kill
  120.    and restart your httpd.
  121. 3. Discontinue the use of mod_cookies, by editing the Configuration
  122.    file, and recommpiling.
  123. 4. Upgrade to the current Apache 1.2 beta.
  124.  
  125. Note that options 2 and 3 do not fix an unrelated hole which allows
  126. remote users to obtain directory indexes even when an index.html is
  127. present.
  128.  
  129. *** mod_cookies.c       Tue Jan  7 14:38:15 1997
  130. --- /usr/tmp/mod_cookies.c      Tue Jan  7 14:38:11 1997
  131. ***************
  132. *** 119,125 ****
  133.   void make_cookie(request_rec *r)
  134.   {
  135.       struct timeval tv;
  136. !     char new_cookie[100];     /* blurgh */
  137.       char *dot;
  138.       const char *rname = pstrdup(r->pool,
  139.                                 get_remote_host(r->connection, r->per_dir_config,
  140. --- 119,125 ----
  141.   void make_cookie(request_rec *r)
  142.   {
  143.       struct timeval tv;
  144. !     char new_cookie[1024];    /* blurgh */
  145.       char *dot;
  146.       const char *rname = pstrdup(r->pool,
  147.                                 get_remote_host(r->connection, r->per_dir_config,
  148. ***************
  149. *** 128,133 ****
  150. --- 128,136 ----
  151.       struct timezone tz = { 0 , 0 };
  152.  
  153.       if ((dot = strchr(rname,'.'))) *dot='\0'; /* First bit of hostname */
  154. +     if (strlen (rname) > 255)
  155. +       rname[256] = 0;
  156. +
  157.       gettimeofday(&tv, &tz);
  158.       sprintf(new_cookie,"%s%s%d%ld%d; path=/",
  159.           COOKIE_NAME, rname,
  160.  
  161.  
  162. Users of the Stronghold web server will be able to obtain a fix at
  163. http://stronghold.c2.net/support/ups_and_bugs.php.  There will be a
  164. new release of Stronghold on Monday, fixing the problem.
  165.  
  166.  
  167. Additional Information
  168. ~~~~~~~~~~~~~~~~~~~~~~
  169. If you have any questions about this advisory, feel free to mail me at
  170. davids@secnet.com.  Past Secure Networks advisories can be found at
  171. ftp://ftp.secnet.com/pub/advisories, and Secure Networks papers can be
  172. found at ftp://ftp.secnet.com/pub/papers.
  173.  
  174. The following PGP key is for davids@secnet.com, should you wish to encrypt
  175. any message traffic to me.:
  176.  
  177. -----BEGIN PGP PUBLIC KEY BLOCK-----
  178. Version: 2.6.2
  179.  
  180. mQCNAzJ4qJAAAAEEAOgB7mooQ6NgzcUSIehKUufGsyojutC7phVXZ+p8FnHLLZNB
  181. BLQEtj5kmfww2A2pR29q4rgPeqEUOjWPlLNdSLby3NI8yKz1AQSQLHAwIDXt/lku
  182. 8QXClaV6pNIaQSN8cnyyvjH6TYF778yZhYz0mwLqW6dU5whHtP93ojDw1UhtAAUR
  183. tCtEYXZpZCBTYWNlcmRvdGUgPGRhdmlkc0BzaWxlbmNlLnNlY25ldC5jb20+
  184. =LtL9
  185. -----END PGP PUBLIC KEY BLOCK-----
  186.  
  187. Many thanks to Ramsey Dow (ramseyd@secnet.com) for helping find vulnerable
  188. Apache derivatives.
  189.  
  190. For further information about the Apache httpd, see http://www.apache.org
  191.  
  192. For further information about the Sioux web server, see
  193. http://www.thawte.com/products/sioux
  194.  
  195. For further information about the Stronghold web server, see
  196. http://stronghold.c2.net/support/ups_and_bugs.php and
  197. http://stronghold.c2.net
  198.  
  199. Many thanks to the Apache group and vendors of Apache derived web servers
  200. for an extremely prompt response.
  201.  
  202. Copyright Notice
  203. ~~~~~~~~~~~~~~~~
  204. The contents of this advisory are Copyright (C) 1997 Secure Networks Inc,
  205. and may be distributed freely provided that no fee is charged for
  206. distribution, and that proper credit is given.
  207.  
  208. Apache httpd source code distributed in this advisory falls under the
  209. following license:
  210. Copyright (c) 1995, 1996 The Apache Group.  All rights reserved.
  211.  
  212.  Redistribution and use in source and binary forms, with or without
  213.  modification, are permitted provided that the following conditions
  214.  are met:
  215.  
  216.  1. Redistributions of source code must retain the above copyright
  217.     notice, this list of conditions and the following disclaimer.
  218.  
  219.  2. Redistributions in binary form must reproduce the above copyright
  220.     notice, this list of conditions and the following disclaimer in
  221.     the documentation and/or other materials provided with the
  222.     distribution.
  223.  
  224.  3. All advertising materials mentioning features or use of this
  225.     software must display the following acknowledgment:
  226.     "This product includes software developed by the Apache Group
  227.     for use in the Apache HTTP server project
  228.     (http://www.apache.org/)."
  229.  
  230.  4. The names "Apache Server" and "Apache Group" must not be used to
  231.     endorse or promote products derived from this software without
  232.     prior written permission.
  233.  
  234.  5. Redistributions of any form whatsoever must retain the following
  235.     acknowledgment:
  236.     "This product includes software developed by the Apache Group
  237.     for use in the Apache HTTP server project
  238.     (http://www.apache.org/)."
  239.  
  240.  THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  241.  EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  242.  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  243.  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  244.  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  245.  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  246.  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  247.  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  248.  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  249.  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  250.  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  251.  OF THE POSSIBILITY OF SUCH DAMAGE.
  252.  
  253.