blowchunks - protecting existing apache servers until upgrades arrive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




Many sysadmins will be in the unpleasant situation of having to live with a 
known vulnerable apache server (or switching it off) until they can obtain, 
test and integrate updated apache binaries for their various platforms from 
different vendors, or make enough time to sit down and patch, re-compile and 
test their home-grown versions.

Some vendors have been very fast to respond, and have back-ported the fix to 
many older apache releases, helping avoid many issues that a forced upgrade 
might involve. Other vendors supplying apache and apache-based servers may 
not be so quick off the mark (or may not even be around anymore). Home grown 
releases may also be similarly outdated, and back-porting is tedious.

Because apache is so great, and has had a history of very few serious 
security bugs,  older versions are embedded in a wide variety of products and 
systems, making it even more problematic to update all of them to the latest 
release in a timely manner.

Here's an option which might help in protecting those vulnerable servers, 
giving a breathing space until a proper tested fix does become available:

Basically, most web sites and applications have no need for chunked transfer 
encoding on HTTP *request*  messages. Most browsers don't even support it, 
and it's only *required* when a client doesn't know the final length of a 
file before an upload (which is pretty rare). Disallowing such requests 
should be no big deal. (This has nothing to do with using chunked encoding 
for data served in the HTTP *response*, though I guess we should start 
looking out for malicious web servers attacking vulnerable clients...)

Attached are a two versions of code to allow the server to intercept each 
incoming HTTP request (at the 'Post Read Request' phase), and check to see if 
 chunked encoding has been requested. If so, the request is denied and 
logged. This should prevent clients being able to trigger the vulnerable 
'chunk size' reading code, and therefore prevent DoS or exploits. 

* BlowChunks.pl  - this version is for mod_perl enabled servers - if you have 
a server with mod_perl already in place, this patch is trivial to install. 
Just paste it into the end of your existing httpd.conf, and restart. All 
done. Very Easy.

* mod_blowchunks.c - this version is an apache module. If your apache is 
compiled with DSO support (run httpd -l and look for mod_so), you can compile 
and install this module with just one apxs command (and a compiler!), and 
restart. Should be straightforwards for most admins.

There is, of course, absolutely no warranty on these fixes, but it 'works for 
me'. There could be ways round the protection provided, so rely on this 
entirely at your own risk! 

Both methods offer the advantage of not needing to touch your existing apache 
binary (or any other modules), and can be trivially reverted if you have any 
trouble, or when your real fix is ready. The should work on any platform with 
either mod_perl or DSO support. If your apache is static, without DSO, you 
could re-compile it with this module included, but then you might as well 
just fix it properly.

Any suggestions, criticisms or improvements on this technique are welcome, 
but, sorry, I am not able to 'help out', answer questions or otherwise 
provide support or assistance in compiling, installing or making them work in 
any way!

Cris Bailiff
/dev/secure Pty Ltd - Awayweb, the Virtual VPN - http://www.awayweb.com







# $Id: BlowChunks.pl,v 1.4 2002/06/22 05:27:33 cbailiff Exp $
#
# Reject chunked requests before vulnerable chunking routines can read them.
# (mod_perl version)
#
# Cris Bailiff, c.bailiff+blowchunks@devsecure.com -  http://www.awayweb.com
# http://www.devsecure.com/pub/src/BlowChunks.pl
#
# Copyright 2002 Cris Bailiff.  All rights reserved.
#
# Permission is granted to anyone to use this software for any purpose on
# any computer system, and to alter it and redistribute it, subject
# to the following restrictions:
#
# 1. The author is not responsible for the consequences of use of this
#  software, no matter how awful, even if they arise from flaws in it.
#
# 2. The origin of this software must not be misrepresented, either by
#  explicit claim or by omission. 
#
# 3. Altered versions must be plainly marked as such, and must not be
#  misrepresented as being the original software. 
#
# 4. This notice may not be removed or altered.
#
# To install in your mod_perl enabled server, copy the code below into
# your httpd.conf file (at the end is best), or read this file into
# your configuration using an 'Include' statement, and restart httpd.
#
# You need mod_perl with support for PerlPostReadRequestHandler
# and <perl> sections. You have these if your mod_perl was configured
# using EVERYTHING=1, which is typical.
#
# (Permission is granted to leave these comments out of your httpd.conf file :-)
# but please use this original version if passing along...)
#
# --cut-here---

<perl>
# blowchunks for mod_perl
# $Id: BlowChunks.pl,v 1.4 2002/06/22 05:27:33 cbailiff Exp $
# Deny requests using Transfer-Encoding: chunked
#
sub Awayweb::BlowChunks::handler {
  my $r = shift;
  if (join('',$r->headers_in->get('Transfer-Encoding'))
        =~ m/chunked/i)
  {
      $r->log->warn('Transfer-Encoding: chunked - denied and logged');
      return 400
  }
  return 0
}
</perl>
PerlPostReadRequestHandler Awayweb::BlowChunks
/* 
 * $Id: mod_blowchunks.c,v 1.3 2002/06/22 05:27:33 cbailiff Exp $
 *
 * Reject chunked requests before vulnerable chunking routines can read them.
 * (apache module version)
 *
 * Cris Bailiff, c.bailiff+blowchunks@devsecure.com - http://www.awayweb.com
 * http://www.devsecure.com/pub/src/mod_blowchunks.c
 *
 * Copyright 2002 Cris Bailiff.  All rights reserved.
 *
 * Permission is granted to anyone to use this software for any purpose on
 * any computer system, and to alter it and redistribute it, subject
 * to the following restrictions:
 *
 * 1. The author is not responsible for the consequences of use of this
 *  software, no matter how awful, even if they arise from flaws in it.
 *
 * 2. The origin of this software must not be misrepresented, either by
 *  explicit claim or by omission. 
 *
 * 3. Altered versions must be plainly marked as such, and must not be
 *  misrepresented as being the original software. 
 *
 * 4. This notice may not be removed or altered.
 *
 * To compile & install in your apache (using apxs):
 *
 *     # /usr/sbin/apxs -i -a -c mod_blowchunks.c
 *
 * and restart. Read the apxs(8) man page for more info on compiling apache
 * modules.
 */

#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_main.h"
#include "http_protocol.h"

module MODULE_VAR_EXPORT blowchunks_module;

static int blowchunks_check_one_header(void *data, const char *key, const char *val)
{
    if (ap_find_last_token(NULL, val, "chunked")) {
	*((int *)data)=TRUE; 
	return FALSE;
    }
    return TRUE;
}

static int blowchunks_post_read_request(request_rec *r)
{
    int found=FALSE;
    ap_table_do(blowchunks_check_one_header,&found,r->headers_in,
	    "Transfer-Encoding",NULL);
    if (found==TRUE) {
        ap_log_rerror(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r,
	    "Transfer-Encoding: chunked - denied and logged");
	return HTTP_BAD_REQUEST;
    }
    return DECLINED;
}

module MODULE_VAR_EXPORT blowchunks_module =
{
    STANDARD_MODULE_STUFF,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
#if MODULE_MAGIC_NUMBER >= 19970902
    blowchunks_post_read_request
#else
#error Your apache is too old to have the post_read_request module hook
#endif
};

[Index of Archives]     [Linux Security]     [Netfilter]     [PHP]     [Yosemite News]     [Linux Kernel]

  Powered by Linux