Operating System:

Published:

10 September 2001

Protect yourself against future threats.

-----BEGIN PGP SIGNED MESSAGE-----

===========================================================================
             AUSCERT External Security Bulletin Redistribution

               ESB-2001.390 -- RUS-CERT Advisory 2001-08:01
         Vulnerabilities in several Apache authentication modules
                             11 September 2001

===========================================================================

        AusCERT Security Bulletin Summary
        ---------------------------------

Product:                Apache using authentication modules:
                         * AuthPG 1.2b2 by Min S. Kim 
                           (also known as mod_auth_pg)
                         * mod_auth_mysql 1.9 by Vivek Khera
                         * mod_auth_oracle 0.5.1 by Serg Oskin
                         * mod_auth_pgsql 0.9.5 by Guiseppe Tanzilli 
                           and Matthias Eckermann
                         * mod_auth_pgsql_sys 0.9.4 
                           (modified by Victor Glushchenko)
Impact:                 Execute Arbitrary Code/Commands
                        Access Privileged Data
Access Required:        Remote

- --------------------------BEGIN INCLUDED TEXT--------------------

Vulnerabilities in several Apache authentication modules

   RUS-CERT has discovered that several Apache authentication modules
   which use SQL databases to store authentication information are
   vulnerable to a remote SQL code injection attack.
   
  Systems Affected
  
   Any Apache server using database-based authentication with the
   following modules:

     * AuthPG 1.2b2 by Min S. Kim (also known as mod_auth_pg)
     * mod_auth_mysql 1.9 by Vivek Khera
     * mod_auth_oracle 0.5.1 by Serg Oskin
     * mod_auth_pgsql 0.9.5 by Guiseppe Tanzilli and Matthias Eckermann
     * mod_auth_pgsql_sys 0.9.4 (by the same authors, modifications by
       Victor Glushchenko)
       
   It is possible that other authentication modules not listed above are
   affected.
   
  Systems Not Affected
  
   RUS-CERT has examined the following authentication modules and
   verified that an Apache server using these modules is not vulnerable
   to the problem described in this document:

     * mod_auth_mysql 2.20 by Zeev Suraski
     * mod_auth_ora7 1.0 by Ben Reser
     * mod_auth_ora8 1.0 by Ben Reser
       
  Attack vector
  
   HTTP requests sent to the Apache server using the vulnerable
   authentication modules.
   
  Impact
  
   In the case of the PostgreSQL modules, an attack can execute arbitrary
   SQL statements or cause the database query for the password to return
   arbitrary data. As a result, unauthorized access to the web server is
   possible.
   
   With the Oracle module, the attacker can call stored procedures and
   cause the database query for the password to return arbitrary data.
   The impact with MySQL is currently unclear, but with the advent of
   stored procedures, harmful side effects might become possible as well.
   
  Vulnerability Type
  
   SQL code insertion attack
   
  Description
  
   During the authentication process, the password hash has to be looked
   up in the database, so a SQL SELECT statement has to be built. In the
   vulnerable modules, this is done using code equivalent to the
   following pseudocode:
   
Query := Sprintf ("SELECT %s FROM %s WHERE %s = '%s'",
                  Password_Column, User_Table, User_Column,
                  User);

   Later on, the retrieved password hash is compared with the one
   supplied by the user trying to authenticate.
   
   However, the value of User has been received over the network. Suppose
   an attacker choses the string (note the single quotation mark at the
   beginning):
   
'; SELECT 'wA8aGH92dPQnIDD

   Now the resulting string contains two SQL statements:
   
     SELECT password_column FROM user_table WHERE user_column = '';
     SELECT 'wA8aGH92dPQnIDD'
     
   PostgreSQL's libpq client library will transmit both statements to the
   PostgreSQL server. The server will execute both statements and return
   the result of the second to the client. This way, an attacker can make
   it appear to the authentication code that the database contains the
   proper hash for the password it just has provided. Other forms of
   attacks are possible by issuing INSERT or DELETE statements in
   essentially the same manner, of course.
   
   In the MySQL and Oracle cases, the impact of the vulnerability is
   different. Oracle does not seem to allow multiple SQL statements per
   query, but using a UNION clause to add additional data seems to be
   possible, so the attack given above can be duplicated. In addition,
   stored procedures can be called, with a potential for harmful side
   effects. We were unable to obtain a definite answer if the
   vulnerability is exploitable if a MySQL database is used, since MySQL
   neither supports UNION clauses nor stored procedures.
   
  Proposed Solution
  
    PostgreSQL
    
   We believe that the fact that the essentially the same vulnerability
   is present in many PostgreSQL applications is related to the lack of a
   suitable string quoting function in the PostgreSQL client library (and
   not just to code reuse and overlap among the authors).
   
   Therefore, we propose that a function which escapes characters treated
   specially by the PostgreSQL by replacing them with safe character
   sequences is included in the PostgreSQL client library. We provide a
   mostly untested sample implementation:

     * Escaping Strings in PostgreSQL Queries
       (http://cert.uni-stuttgart.de/doc/postgresql/escape/)
       
   Some of the fixed versions below already implement this suggestion.
   
    MySQL and Oracle
    
   Both the MySQL and Oracle client libraries provide a suitable function
   for quoting strings in SQL queries. The authentication modules which
   are not vulnerable (see above) use them, so we propose to use these
   modules, or the fixed versions below.
   
  Patched Versions
  
   Several authors have already reacted and released new versions:

     * AuthPG 1.3 by Min S. Kim (http://authpg.sourceforge.net/)
     * mod_auth_mysql 1.10 by Vivek Khera (ftp://ftp.kcilink.com/pub/)
     * mod_auth_pgsql 0.9.6 by Guiseppe Tanzilli
       (http://www.giuseppetanzilli.it/mod_auth_pgsql/dist/)
       
   Serg Oskin has announced a fixed version as well.
   
  Contact Status
  
   RUS-CERT contacted the authors of the vulnerable authentication
   modules on 2001-08-23.

  About RUS-CERT
  
   RUS-CERT (http://cert.uni-stuttgart.de/) is the Computer Emergency
   Response Team located at the Computing Center (RUS) of the
   University of Stuttgart, Germany.

  URI For This Advisory

   http://cert.uni-stuttgart.de/advisories/apache_auth.php

- --------------------------END INCLUDED TEXT--------------------

You have received this e-mail bulletin as a result of your organisation's
registration with AusCERT. The mailing list you are subscribed to is
maintained within your organisation, so if you do not wish to continue
receiving these bulletins you should contact your local IT manager. If
you do not know who that is, please send an email to auscert@auscert.org.au
and we will forward your request to the appropriate person.

This security bulletin is provided as a service to AusCERT's members.  As
AusCERT did not write the document quoted above, AusCERT has had no control
over its content.  The decision to use any or all of this information is
the responsibility of each user or organisation, and should be done so in
accordance with site policies and procedures.

NOTE: This is only the original release of the security bulletin.  It may
not be updated when updates to the original are made.  If downloading at
a later date, it is recommended that the bulletin is retrieved directly
from the original authors to ensure that the information is still current.

Contact information for the authors of the original document is included
in the Security Bulletin above.  If you have any questions or need further
information, please contact them directly.

Previous advisories and external security bulletins can be retrieved from:

	http://www.auscert.org.au/Information/advisories.html

If you believe that your system has been compromised, contact AusCERT or
your representative in FIRST (Forum of Incident Response and Security
Teams).

Internet Email: auscert@auscert.org.au
Facsimile:	(07) 3365 7031
Telephone:	(07) 3365 4417 (International: +61 7 3365 4417)
		AusCERT personnel answer during Queensland business hours
		which are GMT+10:00 (AEST).
		On call after hours for emergencies.

-----BEGIN PGP SIGNATURE-----
Version: 2.6.3i
Charset: noconv
Comment: ftp://ftp.auscert.org.au/pub/auscert/AUSCERT_PGP.key

iQCVAwUBO53tBSh9+71yA2DNAQEH1gQAj/RlSWSPpS7gnXbX8rbt6pfSmSWAfnHN
Mj38rdDEgZ5qqS56zUdTtpw96g4IqEP3vUObSeibXazbRF/w/TDtWMo6fgyyBmiO
6vaChQ3u7IbjBQCiMQlKBxIWxv2o8r8vKiQT3QgiDXnPPKlN1yX0nsulePaw2Py5
NlIG9Hai9zg=
=ezXL
-----END PGP SIGNATURE-----