Australia's Leading Computer Emergency Response Team

AA-95.04 -- wu-ftpd misconfiguration vulnerability
Date: 02 June 1995
Original URL: http://www.auscert.org.au/render.html?cid=1&it=1848

Click here for PGP verifiable version
=============================================================================
AA-95.04                    AUSCERT  Advisory
                              June 2, 1995
                  wu-ftpd misconfiguration vulnerability
-----------------------------------------------------------------------------

    A problem exists with certain configurations of the Washington
    University ftpd which may allow root access from any account on the
    system.  This vulnerability was described in the AA-94.01 Advisory,
    which is available from:

    ftp://ftp.auscert.org.au/pub/auscert/advisory/
    		AA-94.01.ftpd.Configuration.Advice

    Please note that AUSCERT previously operated as SERT.  AUSCERT contact
    details (below) supercede the SERT details included in AA-94.01.

Note:  This Advisory contains new and updated information.

*** The Australian Computer Emergency Response Team has received information
*** that some pre-compiled wu-ftpd-2.4 binaries distributed with Linux have
*** a vulnerable configuration by default.
    
    All other users of wu-ftpd should take this opportunity to verify the
    configuration of their daemons.

    Versions of wu-ftpd prior to 2.4 contain serious security
    vulnerabilities and should be updated immediately.

1.  Description

    A vulnerability exists in certain configurations of wu-ftpd which may
    allow users to gain root access.  The vulnerability has been described
    previously in the AA-94.01 Advisory.

    In its original form, the vulnerability was not enabled by default. 
    However, certain distributions of Linux contain a wu.ftpd that has been
    compiled with a vulnerable configuration.  This vulnerable
    configuration is distributed and run by default.

    This vulnerability has been confirmed for Linux Slackware-2.1 and 2.2.  
    It has been claimed that Linux Slackware-2.0 and 2.3 are also affected. 
    Other versions may similarly be affected.  To test whether your system 
    is affected, see Section 3 (Detection).

    Non-Linux systems running wu-ftpd should also be checked to determine
    if the configuration is vulnerable.  See Section 3 (Detection).

    The pre-compiled binaries shipped for Linux Slackware distributions are
    vulnerable.  The variable _PATH_EXECPATH has been set to "/bin" in the
    configuration file src/pathnames.h when the distribution binary was
    built.  _PATH_EXECPATH should be set to "/bin/ftp-exec" or a similar
    directory that does not contain a shell or command interpreter.  The
    source code shipped with the Linux distributions contains the correct
    value ("/bin/ftp-exec") (which should be verified before recompiling),
    despite the incorrect distribution binary.  See Section 4.2 for further
    information.
 
    The documentation states that the directory defined by _PATH_EXECPATH
    is relative to ~ftp.  This is misleading.  The pathname is relative to
    ~ftp for anonymous users only.  It is relative to "/" for normal user
    sessions.
    
    Floppy-only distributions of Linux do not contain source code.  The
    latest version of the wu-ftpd source code can be obtained from:

    ftp://ftp.auscert.org.au/pub/mirrors/wuarchive.wustl.edu/
    		packages/wuarchive-ftpd/wu-ftpd-2.4.tar.Z

    A diff(1) file exists to modify the wu-ftpd source code to allow it
    to compile on Linux.  The application of this patch will cause the
    vulnerable configuration to exist.

*** The patch file wu-ftpd-2.4.diff.gz for Linux contains incorrect
*** information.  This should be corrected and verified before recompiling.

2.  Impact

    Anyone who has a local account on the system offering ftp services with
    the vulnerable configuration may gain root access.  Support for
    anonymous ftp access is not required to exploit this vulnerability.

3.  Detection

    Vulnerable systems can be detected by executing (as a user) the
    commands below or by running strings(1) against the wu-ftpd daemon. 

    Both tests are recommended.

3.1 Detection using user commands

    To test your configuration to see if you are vulnerable, you can
    execute the following commands:

    srchost> ftp ftphost
    Connected to ftphost
    220 ftphost FTP server (Version wu-2.4(2) Mon Apr 18 09:12:35 GMT+1000 1994) ready.
    Name (srchost:user):
    331 Password required for user.
    Password:
    230 User user logged in.
    ftp> quote site exec echo problem
    200-echo problem
    200-problem
    200  (end of 'echo problem')
    ftp> quit
    221 Goodbye.
    srchost>

    If you receive the line "200-problem", then your site is vulnerable.
    Note that this does not work for anonymous ftp access, or for all
    vulnerable configurations.

3.2 Detection using strings(1)

    Determine the location of the SITE EXEC path by executing the following
    command on the src/pathnames.h file:

    	$ grep _PATH_EXECPATH pathnames.h
    	#define _PATH_EXECPATH	"/bin/ftp-exec"
    	$

    Use the output of this command to verify that the currently running
    binary is configured the same as the source code.  Note, you should
    consult your documentation for strings(1) to determine the correct
    switch for examining the entire binary:

    	$ strings -a wu.ftpd | grep "/bin/ftp-exec"
    	/bin/ftp-exec
    	$

    If the binary contains the same pathname for _PATH_EXECPATH, then you
    have determined the correct location for the SITE EXEC commands.

    The directory defined by _PATH_EXECPATH should not contain a shell or
    command interpreter (such as perl) and should not be world or group
    writeable, nor should any directory back to the root directory (/) be
    group or world writeable.  Permissions 511 are acceptable.

4. Recovery
    
    If you have the vulnerability and you are unsure how to rectify it
    immediately, you should disable your ftp daemon until the configuration
    can be corrected.

4.1 Temporary workaround

    If you are unsure how to rebuild a new ftpd daemon, then an interim
    workaround is to disable the existing service.

    Note:  this will cause all incoming ftp requests to fail.

    1. become root

    2. comment out ftp in /etc/inetd.conf by prepending # to the line, ie:
       #ftp	stream	tcp	<rest of normal ftp line here>

    3. Restart the inetd process.  On most systems, this is done by sending
       a HUP signal to the inetd process.  For example:

    	# /bin/ps -ef | grep inetd | grep -v grep		(System V)
    			or
	# /bin/ps -aux | grep inetd | grep -v grep		(BSD)

       followed by:

	# kill -HUP  <pid gained by above line>

       You should verify that the ftp service has been disabled by
       attempting to connect to it.  You should see a "connection refused"
       message.

4.2 Correcting the configuration

    Ensure that the _PATH_EXECPATH definition in src/pathnames.h is
    "/bin/ftp-exec" and not "/bin" or any other system directory containing
    a shell or interpreter, and then recompile.

    If the wu-ftpd-2.4.diff.gz patch has been applied on Linux systems, the
    patched version of pathnames.h will be vulnerable.  This file should be
    edited manually before the rebuild to correct the _PATH_EXECPATH
    definition to "/bin/ftp-exec".

    Replace the existing ftpd binary with the newly built version.

5. Instructions to enable SITE EXEC

    Once the running binary has been confirmed as not containing the
    vulnerable configuration, the SITE EXEC commands can be enabled by
    following the following steps.

    a) Ensure that the _PATH_EXECPATH definition in pathnames.h is
       "/bin/ftp-exec" and not "/bin" or any other system directory
       containing a shell.  This should also be checked in the binary
       version (see Section 3.2).
    b) Create ~ftp/bin/ftp-exec.  This should be owned by root, permissions
       set to 555.
    c) Copy the statically linked binaries that you want available for
       execution by SITE EXEC into the ~ftp/bin/ftp-exec directory.  These
       should be owned by root, permissions 111.  The binaries should never
       be a shell or command interpreter that allows arbitrary programs to
       be run.
    d) If you want the DIR ftp command, you will need a hard link from
       ~ftp/bin/ls to ~ftp/bin/ftp-exec/ls or a copy of ls in ~ftp/bin.

    The instructions above enable SITE EXEC commands for anonymous users
    only.  To enable SITE EXEC commands for normal ftp users:
    
    e) Create a symbolic link from /bin/ftp-exec to ~ftp/bin/ftp-exec.

    You should follow file ownership, group membership and permissions
    strictly according to your documentation.  Note that some versions of
    ftp contain incorrect information for setting file permissions and
    ownership.  Further information can be found in:
    
    ftp://ftp.auscert.org.au/pub/mirrors/cert.org/tech_tips/anonymous_ftp

----------------------------------------------------------------------------
AUSCERT would like to acknowledge Michel (an113354@anon.penet.fi), Thomas
Lundquist (Thomas.Lundquist@hiof.no), Aleph One (aleph1@dfw.net), Olaf Kirch
(okir@monad.swb.de), Jeff Uphoff, and Dave Barr (barr@math.psu.edu) for 
information published about the Linux problem.

AUSCERT would like to thank Dr. Ian Hoyle from BHP Research and Reinhard
Uebel from QTAC for their assistance in confirming the extent of this
vulnerability.
----------------------------------------------------------------------------

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

AUSCERT is the Australian Computer Emergency Response Team, funded by the
Australian Academic Research Network (AARNet) for its members.  It is
located at The University of Queensland within the Prentice Centre.
AUSCERT is a full member of the Forum of Incident Response and Security
Teams (FIRST).

AUSCERT maintains an anonymous FTP service which is found on:
ftp://ftp.auscert.org.au.  This archive contains past SERT and AUSCERT
Advisories, and other computer security information.

AUSCERT also maintains a World Wide Web service which is found on:
http://www.auscert.org.au.

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

Postal:
Australian Computer Emergency Response Team
c/- Prentice Centre
The University of Queensland
Brisbane
Qld.  4072.
AUSTRALIA