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

  1.  
  2. -----BEGIN PGP SIGNED MESSAGE-----
  3.  
  4. =============================================================================
  5. CERT(sm) Advisory CA-96.06
  6. Original issue date: March 20, 1996
  7. Last revised: June 4, 1997
  8.            Updates section - added information about other cgi programs
  9.           being exploited.
  10.  
  11.               A complete revision history is at the end of this file.
  12.  
  13. Topic: Vulnerability in NCSA/Apache CGI example code
  14. - ------------------------------------------------------------------------------
  15.  
  16.    The text of this advisory was originally released on March 14, 1996,
  17.    as AUSCERT Advisory AA-96.01, developed by the Australian Computer
  18.    Emergency Response Team. Because of the seriousness of the problem, we
  19.    are reprinting the AUSCERT advisory here with their permission. Only
  20.    the contact information at the end has changed: AUSCERT contact
  21.    information has been replaced with CERT/CC contact information.
  22.  
  23.    We will update this advisory as we receive additional information.
  24.    Please check advisory files regularly for updates that relate to your site.
  25.  
  26.    Note: The vulnerability described in this advisory is being actively
  27.    exploited.
  28.  
  29.  
  30. =============================================================================
  31.  
  32. The Australian Computer Emergency Response Team (AUSCERT) has received
  33. information that example CGI code, as found in the NCSA 1.5a-export and APACHE
  34. 1.0.3 httpd (and possibly previous distributions of both servers), contains
  35. a security vulnerability.  Programs using this code may be vulnerable to
  36. attack.
  37.  
  38. The CGI program "phf", included with those distributions, is an example of
  39. such a vulnerable program.  This program may have been installed as part of
  40. the installation process for the httpd.
  41.  
  42. AUSCERT recommends that sites that have installed any CGI program
  43. incorporating the vulnerable code (such as "phf") apply one of the workarounds
  44. as described in Section 3.
  45.  
  46. - -----------------------------------------------------------------------------
  47.  
  48. 1.  Description
  49.  
  50.     A security vulnerability has been reported in example CGI code, as
  51.     provided with the NCSA httpd 1.5a-export and APACHE httpd 1.0.3 (and
  52.     possibly previous distributions of both servers).  The example code
  53.     contains a library function escape_shell_cmd() (in cgi-src/util.c).  This
  54.     function, which attempts to prevent exploitation of shell-based library
  55.     calls, such as system() and popen(), contains a vulnerability.
  56.  
  57.     Any program which relies on escape_shell_cmd() to prevent exploitation
  58.     of shell-based library calls may be vulnerable to attack.
  59.  
  60.     In particular, this includes the "phf" program which is also distributed
  61.     with the example code.  Some sites may have installed phf by default,
  62.     even though it is not required to run httpd successfully.
  63.  
  64.     Any vulnerable program which is installed as a CGI application may allow
  65.     unauthorised activity on the HTTP server.
  66.  
  67.     Please note that this vulnerability is not in httpd itself, but in CGI
  68.     programs which rely on the supplied escape_shell_cmd() function.  Any
  69.     HTTP server (not limited to NCSA or Apache) which has installed CGI
  70.     programs which rely on escape_shell_cmd() may be vulnerable to attack.
  71.  
  72.     Sites which have the source code to their CGI applications available can
  73.     determine whether their applications may be vulnerable by examining the
  74.     source for usage of the escape_shell_cmd() function which is defined in
  75.     cgi-src/util.c.
  76.  
  77.     Sites which do not have the source code for their CGI applications
  78.     should contact the distributors of the applications for more information.
  79.  
  80.     It is important to note that attacks similar to this may succeed
  81.     against any CGI program which has not been written with due
  82.     consideration for security.  Sites using HTTP servers, and in
  83.     particular CGI applications, are encouraged to develop an understanding
  84.     of the security issues involved.  References in Section 4 provide some
  85.     initial pointers in this area.
  86.  
  87. 2.  Impact
  88.  
  89.     A remote user may retrieve any world readable files, execute arbitrary
  90.     commands and create files on the server with the privileges of the httpd
  91.     process which answers HTTP requests.  This may be used to compromise the
  92.     http server and under certain configurations gain privileged access.
  93.  
  94. 3.  Workarounds
  95.  
  96.     The use of certain C library calls (including system() and popen()) in
  97.     security critical code (such as CGI programs) has been a notorious source
  98.     of security vulnerabilities.  Good security coding practice usually
  99.     dictates that easily exploitable system or library calls should not be
  100.     used.  While secure CGI coding techniques are beyond the scope of this
  101.     advisory many useful guidelines are available.
  102.  
  103.     Sites planning to install or write their own CGI programs are encouraged
  104.     to read the references in Section 4 first.
  105.  
  106.     3.1.  Remove CGI programs
  107.  
  108.     Any CGI program which uses the escape_shell_cmd() function and is not
  109.     required should be disabled.  This may be accomplished by removing
  110.     execute permissions from the program or removing the program itself.
  111.  
  112.     In particular, sites which have installed the "phf" program and do not
  113.     require it should disable it.  The "phf" program is not required to
  114.     run httpd successfully.  Sites requiring "phf" functionality should apply
  115.     one of the workarounds given in sections 3.2 and 3.3.
  116.  
  117.     3.2.  Rewrite CGI programs
  118.  
  119.     The intent of the escape_shell_cmd() function is to prevent passing shell
  120.     meta-characters to susceptible library calls.  A more secure approach is
  121.     to avoid the use of these library calls entirely.
  122.  
  123.     AUSCERT recommends that sites which are currently using CGI programs
  124.     which use shell-based library calls (such as system() and popen())
  125.     consider rewriting these programs to remove direct calls to easily
  126.     compromised library functions.
  127.  
  128.     Sites should note that this is only one aspect of secure programming
  129.     practice.  More details on this approach and other guidelines for secure
  130.     CGI programming may be found in the references in Section 4.
  131.  
  132.     3.3.  Recompile CGI programs with patched util.c
  133.  
  134.     For sites that still wish to use programs using the escape_shell_cmd()
  135.     function, a patched version of cgi-src/util.c has been made available by
  136.     NCSA which addresses this particular vulnerability.  The patched version
  137.     of util.c is available as part of the http1.5.1b3-export distribution.
  138.     This is available from:
  139.  
  140.                 http://hoohoo.ncsa.uiuc.edu/beta-1.5
  141.  
  142.     Please note that this is a beta-release of the NCSA httpd and is not a
  143.     stable version of the httpd.  The patched version of cgi-src/util.c may be
  144.     used independently.
  145.  
  146.     CGI programs which are required and use the escape_shell_cmd() should be
  147.     recompiled with the new version of cgi-src/util.c and then reinstalled.
  148.  
  149.     Apache have reported that they intend to fix this vulnerability in a
  150.     future release.  Until then the patched version of util.c as supplied
  151.     in the http1.5.1b3-export release should be compatible.
  152.  
  153. 4.  Additional measures
  154.  
  155.     Sites should consider taking this opportunity to examine their httpd
  156.     configuration.  In particular, all CGI programs that are not required
  157.     should be removed, and all those remaining should be examined for possible
  158.     security vulnerabilities.
  159.  
  160.     It is also important to ensure that all child processes of httpd are
  161.     running as a non-privileged user.  This is often a configurable option.
  162.     See the documentation for your httpd distribution for more details.
  163.  
  164.     Numerous resources relating to WWW security are available.  The following
  165.     pages provide a useful starting point.  They include links describing
  166.     general WWW security, secure httpd setup and secure CGI programming.
  167.  
  168.         The World Wide Web Security FAQ:
  169.                 http://www-genome.wi.mit.edu/WWW/faqs/www-security-faq.html
  170.  
  171.         NSCA's "Security Concerns on the Web" Page:
  172.                 http://hoohoo.ncsa.uiuc.edu/security/
  173.  
  174.     The following book contains useful information including sections on
  175.     secure programming techniques.
  176.  
  177.         "Practical Unix & Internet Security", Simson Garfinkel and
  178.         Gene Spafford, 2nd edition, O'Reilly and Associates, 1996.
  179.  
  180.     Please note that the URLs referenced in this advisory are not under
  181.     AUSCERT's control and therefore AUSCERT cannot be responsible for their
  182.     availability or content.  Please contact the administrator of the site in
  183.     question if you encounter any difficulties with the above sites.
  184.  
  185. - -----------------------------------------------------------------------------
  186. AUSCERT thanks Jeff Uphoff of NRAO, IBM-ERS, NASIRC and Wolfgang Ley of
  187. DFN-CERT for their assistance.
  188. - -----------------------------------------------------------------------------
  189.  
  190. The AUSCERT team have made every effort to ensure that the information
  191. contained in this document is accurate.  However, the decision to use the
  192. information described is the responsibility of each user or organisation.
  193. The appropriateness of this document for an organisation or individual system
  194. should be considered before application in conjunction with local policies
  195. and procedures.  AUSCERT takes no responsibility for the consequences of
  196. applying the contents of this document.
  197.  
  198. ==============================================================================
  199.  
  200. CERT Contact Information
  201. - ------------------------
  202. If you believe that your system has been compromised, contact the CERT
  203. Coordination Center or your representative in the Forum of Incident
  204. Response and Security Teams (FIRST).
  205.  
  206. We strongly urge you to encrypt any sensitive information you send by email.
  207. The CERT Coordination Center can support a shared DES key and PGP. Contact the
  208. CERT staff for more information.
  209.  
  210. Location of CERT PGP key
  211.          ftp://info.cert.org/pub/CERT_PGP.key
  212.  
  213.  
  214. Email    cert@cert.org
  215.  
  216. Phone    +1 412-268-7090 (24-hour hotline)
  217.                 CERT personnel answer 8:30-5:00 p.m. EST
  218.                 (GMT-5)/EDT(GMT-4), and are on call for
  219.                 emergencies during other hours.
  220.  
  221. Fax      +1 412-268-6989
  222.  
  223. Postal address
  224.         CERT Coordination Center
  225.         Software Engineering Institute
  226.         Carnegie Mellon University
  227.         Pittsburgh PA 15213-3890
  228.         USA
  229.  
  230. To be added to our mailing list for CERT advisories and bulletins, send your
  231. email address to
  232.         cert-advisory-request@cert.org
  233.  
  234. CERT publications, information about FIRST representatives, and other
  235. security-related information are available for anonymous FTP from
  236.         ftp://info.cert.org/pub/
  237.  
  238. CERT advisories and bulletins are also posted on the USENET newsgroup
  239.         comp.security.announce
  240.  
  241.  
  242. CERT is a service mark of Carnegie Mellon University.
  243.  
  244. ============================================================================
  245. UPDATES
  246.  
  247. Similar attacks may succeed against other cgi scripts if the scripts
  248. are written without appropriate care regarding security issues. We
  249. encourage sites to evaluate all programs in their cgi-bin directory
  250. and remove any scripts that are not in active use.
  251.  
  252. We would like to point out that along with "phf" we have received
  253. reports that "php" programs are also being exploited.
  254.  
  255.  
  256. CERT/CC received the following update from NASIRC concerning the
  257. vulnerability described in this advisory:
  258.  
  259. NEW INFORMATION
  260.  
  261.    The routine "escape_shell_cmd()" also occurs in the file
  262.    "src/util.c". Note that the files "cgi-src/util.c" and
  263.    "src/util.c" are not identical, however they both contain an
  264.    identical copy of the routine "escape_shell_cmd()", which has the
  265.    vulnerability.  The file "src/util.c" is used to build the HTTP
  266.    daemon, therefore the "newline" hole exists within the server.
  267.  
  268.    PATCH
  269.  
  270.    The patch recommended by NCSA modifies the routine
  271.    "escape_shell_cmd()" to expand the list of characters that it
  272.    will escape.  In the routine "escape_shell_cmd()", the line:
  273.  
  274.                    if(ind("&;`'\"|*?~<>^()[]{}$\\",cmd[x]) != -1){
  275.  
  276.    Must be changed to:
  277.  
  278.                    if(ind("&;`'\"|*?~<>^()[]{}$\\\n",cmd[x]) != -1){
  279.  
  280.  
  281.    NCSA HTTPD 1.5.1
  282.  
  283.    Instead of patching the source, the most up-to-date version of
  284.    NCSA HTTPd source may be downloaded from:
  285.  
  286. ftp://ftp.ncsa.uiuc.edu/Web/httpd/Unix/ncsa_httpd/current/httpd_1.5.1-export_source.tar.Z
  287.  
  288.    MD5 (httpd_1.5.1-export_source.tar.Z) = bcf1fd410b5839c51dc75816a155fbb8
  289.  
  290. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  291. Revision history
  292.  
  293. June 4, 1997   Updates section - added information about other cgi programs
  294.            being exploited.
  295. Aug. 30, 1996  Information previously in the README was inserted into the
  296.                advisory.
  297. Apr. 17, 1996  Updates section - added new information provided by the
  298.                NASA Automated Systems Incident Response Capability (NASIRC).
  299.  
  300.  
  301. -----BEGIN PGP SIGNATURE-----
  302. Version: 2.6.2
  303.  
  304. iQCVAwUBM5WIYHVP+x0t4w7BAQHtpQP/e+aGsAPqjxNA+ijxoVLcZLGpOmRHz1hs
  305. ZuKNhCIEjIB4hxxA8UfAgnsR08NUFs088a0V9j+Ty16qARXLV444vZvBG2bDDVEY
  306. Y5cEHEY+u1E7BNq0SYs4g1X4BR2ge5JyhfJtyLmbnY8xVcSmtCPQ0xWGt8HdhQgp
  307. 9Ou4GapN7FE=
  308. =siUr
  309. -----END PGP SIGNATURE-----
  310.  
  311.