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

  1. ---------- Forwarded message ----------
  2. Date: Fri, 22 Dec 1995 10:03:05 -0600 (CST)
  3. From: David Pratt <dpratt@msc.edu>
  4. To: www-security@ns2.rutgers.edu
  5. Subject: NCSA Httpd Security Hole
  6.  
  7. December 22, 1995
  8.  
  9.   I stumbled upon a security risk in NCSA's httpd Version 1.42.
  10. Under certain conditions, you can force the daemon to return the
  11. source code for any scripts contained in /cgi-bin.  This behavior
  12. is not exhibited by Netscape's, or CERN's daemon.  It appears that
  13. this behavior is also present in Version 1.5 as the pertinent
  14. source code is identical.  I do not have that version running, so
  15. it is not possible to test it directly.
  16.   This security hole only presents itself for systems with cgi-bin
  17. directories contained within their DocumentRoot directories.  You
  18. can access the source code by adding multiple "/" preceeding the
  19. cgi-bin portion of the URL.  If indexing is turned on, you can
  20. get a full listing of all files within the cgi-bin directory.
  21. Example URL's follow:
  22.   
  23.      URL:    http://www.foo.com//cgi-bin/
  24.      URL:    http://www.foo.com///cgi-bin/man.pl
  25.  
  26.   The daemon fails to detect this as a cgi-bin redirect, then
  27. parses the file ///cgi-bin/man.pl from your document root.  Since
  28. the multiple slashes are legal syntax in UNIX, the daemon returns
  29. the file as straight text.  This provides potential hackers a
  30. glimpse at what measures you have taken (or haven't taken) to
  31. thwart their access.
  32.   In perusing the httpd source, the problem appears located in
  33. routine "translate_name" in file "http_alias.c".  An alias table
  34. is built up for string comparisons with the incoming URL.  At
  35. startup, this table is loaded with the value of ScriptAlias in
  36. your configuration files, generally "/cgi-bin".  Comparing
  37. "/cgi-bin" with "//cgi-bin" fails, and the file is returned to
  38. the browser as straight text.
  39.   The short term workaround is listed below.  Basically, the URL
  40. is scanned for multiple slashes as far up the processing pipeline
  41. as possible.  As far as I can determine, this is within function
  42. "unescape_url" in file "util.c".
  43.  
  44.  
  45.  
  46. void unescape_url(char *url) {
  47.     register int x,y;
  48. /* 
  49.  *  Remove multiple slashes in URL in place.
  50.  */
  51.     char *src  = url;
  52.     char *dest = url;
  53.  
  54.     for (; src && *src; src++) {
  55.       if (*src == '/' && *(src+1) == '/') continue;
  56.       *dest++ = *src;
  57.     }
  58.     *dest = '\0';
  59. /*
  60.  *  End Modification
  61.  */
  62.  
  63.     for(x=0,y=0;url[y];++x,++y) {
  64.         if((url[x] = url[y]) == '%') {
  65.             url[x] = x2c(&url[y+1]);
  66.             y+=2;
  67.         }
  68.     }
  69.     url[x] = '\0';
  70. }
  71.  
  72.  
  73. Remember, this hole is ONLY seen if your cgi-bin directory is
  74. located in your DocumentRoot directory.  For those of you with
  75. systems configured like this, and I have seen a lot, sorry to
  76. ruin your plans for cutting out early for Christmas.
  77.  
  78. -- 
  79.  
  80.   Dave Pratt 
  81.   dpratt@msc.edu  (612)337-3534
  82.   Minnesota Supercomputer Center Inc.
  83.   Graphics and Visualization Group        
  84.   1200 Washington Avenue South
  85.   Minneapolis, MN  55415
  86.  
  87.