RE: STG Security Advisory: [SSA-20041215-17] Vulnerability of uploading files with multiple extensions in JSBoard

From: Richard Stanway (bugtraq_at_secur1ty.net)
Date: 12/16/04

  • Next message: Katrina Tsipenyuk: "Unchecked returns from kernel_read() in linux-2.6.10-rc2 kernel"
    To: <bugtraq@securityfocus.com>
    Date: Thu, 16 Dec 2004 17:21:07 -0000
    
    

    Hi,

    > ...
    > This
    > is originated from a feature of Apache MIME module (mod_mime),
    > which regards
    > attack.php.hwp as a normal PHP file and execute the file through mod_php
    > module with the privilege of the HTTPD process.
    >
    > cf. http://httpd.apache.org/docs/mod/mod_mime.html - "Files with Multiple
    > Extensions" : it's a feature, not a bug.
    >

    I'd like to follow up on this as I've done a bit of research onto this
    "multiple extensions" behaviour in the past. I was however unaware that
    having extensions on the end that aren't registered MIME types will also
    cause code execution, but after looking through mod_mime.c it is quite clear
    it's possible. There are a huge number of 3rd party PHP scripts out there
    that are unaware of the "multiple extensions" behaviour and thus could be
    vulnerable to this issue. Most of them do have a simple extension checks
    though for files such as .jpg .png .gif etc so the chances of being able to
    upload a file without a registered MIME type are somewhat reduced.

    As a rather ugly "fix", I have patched Apache to remove the multiple
    extensions behaviour for handlers (AddHandler) as there seemed no legitimate
    reason why it would be needed. If anyone is interested, the patch is
    available at http://secur1ty.net/mod_mime-handler-lastonly.patch and applies
    cleanly to the 1.3.3x series and I have been using this patch for over a
    year in production use without any problems. This begs the question, is
    there any legitimate use or need for "handlers" to be invoked on every
    extension? For "index.en.html" and such I can understand why multiple
    extensions are used for MIME type purposes, but is there any such practical
    use for handlers?

    If not, why then does PHP use a MIME type to execute by default instead of a
    handler? It appears to work equally well when the AddType is changed to
    AddHandler in the httpd.conf, and similar items (server-parsed, cgi-script)
    are added as handlers by default. Since multiple MIME types are legitimately
    used and multiple handlers have questionable use, would it not make sense to
    have handlers only invoke on the last extension and have PHP and other
    scripting language modules execute as handlers?

    The risks may also be increased on servers using cPanel, a popular web
    hosting control panel that has the option of using PHP as a CGI under suExec
    to aid in auditing and file permissions issues. The cPanel developers have
    purposefully removed the need for PHP CGI files to be +x, and since CGI is
    used as a handler, any file.php.ext on a PHP-CGI enabled cPanel server will
    be executed, regardless if .ext is a registered MIME type which would
    otherwise mitigate the problem. The developers have confirmed this is the
    intended behaviour in order to "make it easier for users". Again, this would
    not be a problem if handlers weren't invoked on every extension.

    I contacted the Apache security team over a year ago about the various
    issues with the mod_mime.c processing of multiple extensions but did not
    receive a reply. I would also like to point out an article I wrote about
    handling file uploads and dynamic content, this should be recommended
    reading for any 3rd party script coders who use file uploads as it has a
    section about multiple extensions as well as other pertinent issues. You can
    read it at http://shsc.info/FileUploadSecurity.

    I'd appreciate any feedback about the handler issue as I really don't see
    why it's needed and it seems like a good way to fix the problem rather than
    have thousands of vulnerable PHP scripts on the loose.

    Rich.


  • Next message: Katrina Tsipenyuk: "Unchecked returns from kernel_read() in linux-2.6.10-rc2 kernel"

    Relevant Pages

    • Re: Find and List files matching file extension - inside zip files !
      ... Just because he asked about "extensions" ... use of filename suffixes themselves to know the distinction between ... What people have said is that MIME type filename extensions already long ...
      (comp.os.linux.setup)
    • Loading DLLs from different path
      ... PHP is a popular server-side scripting language for web servers. ... It popularity is mainly due that it has many 3rd party extensions. ... The issue is that our DLL is dependent on RPC application server API DLLs in a different folder. ... The problem is that we never recommended putting dlls on the PATH nor do we recommend for our customers to have copies of DLLS over all the place. ...
      (microsoft.public.win32.programmer.kernel)
    • RE: [PHP] Re: IE download problem
      ... code to upload the file to a different php file. ... Subject: Re: IE download problem ... I tried sending the correct mime type and still had the same problem. ...
      (php.general)
    • Re: Plain text files in internet explorer
      ... And this isn't a matter of URLs or extensions being abused by web ... Web servers can and do serve different content to different ... >copmlex system of sometimes looking at the MIME type, ... attach his *resume*. ...
      (Vuln-Dev)
    • Re: [PHP] Include an encoder into PHP distribution?
      ... >> libraries will not be accepted by the PHP group. ... I think that an encoder ... PHP already comes with extensions for the same ... caching, including Zend and Ioncube's. ...
      (php.general)