You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Nick Kew <ni...@webthing.com> on 2014/09/26 16:41:43 UTC
Proposed simple shell-shock protection
I've revisited mod_taint this morning, and made some updates:
a bugfix, a new option to apply an untainting rule to all headers.
But topically, a canned configuration option to protect
against shell-shock patterns:
LoadModule modules/mod_taint.so
Untaint shellshock
Untaint works in a directory context, so can be
selectively enabled for potentially-vulnerable apps
such as those involving CGI, SSI, ExtFilter,
or (other) scripts.
This goes through all Request headers, any PATH_INFO
and QUERY_STRING, and (just to be paranoid) any
other subprocess environment variables. It untaints
them against a regexp that checks for "()" at the
beginning of a variable, and returns an HTTP 400 error
(Bad Request) if found.
Feedback welcome, indeed solicited. I believe this
is a simple but sensible approach to protecting
potentially-vulnerable systems, but I'm open to
contrary views. The exact details, including the
shellshock regexp itself, could probably use some
refinement. And of course, bug reports!
Builds and runs with httpd 2.2 and 2.4. Very limited
testing verifies that it catches a shellshock attack
in a request header.
http://people.apache.org/~niq/mod_taint.html
Note: cross-posting, with followup-to set to dev@.
If you're following up to report a critical bug,
adding users@ will ensure widest exposure!
--
Nick Kew
Re: Proposed simple shell-shock protection
Posted by Stefan Fritsch <sf...@sfritsch.de>.
On Thursday 16 October 2014 02:38:15, Marian Marinov wrote:
> I just want to point out that () is not the only possible string.
> Actually what you want to catch is something like this: ^\(.*\)
I don't think so. Where did you get that information?
Re: Proposed simple shell-shock protection
Posted by Marian Marinov <mm...@yuhu.biz>.
On 09/29/2014 06:57 PM, Stefan Fritsch wrote:
> On Monday 29 September 2014 10:07:40, Nick Kew wrote:
>> Yes. It's catching potential attacks in r->headers_in.
>> The rest is paranoia-mode afterthoughts:
>> PATH_INFO/QUERY_STRING because they could contain something
>> interesting, subprocess_env just "because it's there" (there's
>> a code comment about "just to be paranoid").
> I haven't looked at the code deeply, but SERVER_PROTOCOL is one vector
> for shell-shock and mod_taint does not seem to cover that.
>
> Of course, I would be in favor of httpd itself enforcing a sane value
> for this and other variables (see strict mode in trunk), but 2.4
> doesn't.
>
I just want to point out that () is not the only possible string. Actually what you want to catch is something like
this: ^\(.*\)
Marian
Re: Proposed simple shell-shock protection
Posted by Stefan Fritsch <sf...@sfritsch.de>.
On Monday 29 September 2014 10:07:40, Nick Kew wrote:
> Yes. It's catching potential attacks in r->headers_in.
> The rest is paranoia-mode afterthoughts:
> PATH_INFO/QUERY_STRING because they could contain something
> interesting, subprocess_env just "because it's there" (there's
> a code comment about "just to be paranoid").
I haven't looked at the code deeply, but SERVER_PROTOCOL is one vector
for shell-shock and mod_taint does not seem to cover that.
Of course, I would be in favor of httpd itself enforcing a sane value
for this and other variables (see strict mode in trunk), but 2.4
doesn't.
Re: Proposed simple shell-shock protection
Posted by Nick Kew <ni...@webthing.com>.
On Mon, 2014-09-29 at 09:43 +0200, Yann Ylavic wrote:
> On Mon, Sep 29, 2014 at 7:59 AM, Nick Kew <ni...@webthing.com> wrote:
> > On Sun, 2014-09-28 at 23:10 +0200, Rainer Jung wrote:
> >
> >> IMHO it is a useful approach. Whan I looked at the CGI topic, I noticed
> >> that the safest thing is cleaning up in ap_create_environment(), because
> >> you can be sure to get every env var in your hands there, not only the
> >> ones coming from headers.
> >
> > The "shellshock" recipe for mod_taint takes a bit of a kitchen-sink
> > approach:
> > - The Request headers
> > - The Request fields that haven't always been fully sanitised
> > and that might try to smuggle something: PATH_INFO and
> > QUERY_STRING (r->args).
> > - subprocess_env
>
> mod_taint uses the header_parser hook to untaint the request
> headers/fields, but this is too early for subprocess_env.
Yes. It's catching potential attacks in r->headers_in.
The rest is paranoia-mode afterthoughts:
PATH_INFO/QUERY_STRING because they could contain something
interesting, subprocess_env just "because it's there" (there's
a code comment about "just to be paranoid").
> As Rainer noticed httpd is probably missing a env_parser hook that
> could be called by ap_create_environment(), but still that would not
> apply to [fs]cgi (which don't use it).
>
> So maybe rather than defining a hook that would work on the whole char
> **env, we could have one working on any key/value pair like :
>
> AP_IMPLEMENT_HOOK_RUN_ALL(int, env_parser,
> (apr_pool_t *p, const char **key, const char
> **value), (p, key, value), OK, DECLINED)
>
> This seems quite costly though...
Agreed. A whole new hook, just to catch a bug that isn't ours!
The taint principle is to focus precisely on data coming from
the untrusted source - i.e. over the Web. That's what mod_taint does.
If it's missing anything, it would have to be something that
happens before header_parser: for example, could a RewriteMap
invoke a shell somewhere early?
The other vector if something in HTTPD parses input
and puts the parsed data into env. For example, if
a custom module decrypts an encrypted identity token
and puts it into the subprocess environment.
I was going to say that's beyond the scope of
anything we can/should do, but I guess REMOTE_USER
is indeed our business.
--
Nick Kew
Re: Proposed simple shell-shock protection
Posted by Yann Ylavic <yl...@gmail.com>.
On Mon, Sep 29, 2014 at 7:59 AM, Nick Kew <ni...@webthing.com> wrote:
> On Sun, 2014-09-28 at 23:10 +0200, Rainer Jung wrote:
>
>> IMHO it is a useful approach. Whan I looked at the CGI topic, I noticed
>> that the safest thing is cleaning up in ap_create_environment(), because
>> you can be sure to get every env var in your hands there, not only the
>> ones coming from headers.
>
> The "shellshock" recipe for mod_taint takes a bit of a kitchen-sink
> approach:
> - The Request headers
> - The Request fields that haven't always been fully sanitised
> and that might try to smuggle something: PATH_INFO and
> QUERY_STRING (r->args).
> - subprocess_env
mod_taint uses the header_parser hook to untaint the request
headers/fields, but this is too early for subprocess_env.
As Rainer noticed httpd is probably missing a env_parser hook that
could be called by ap_create_environment(), but still that would not
apply to [fs]cgi (which don't use it).
So maybe rather than defining a hook that would work on the whole char
**env, we could have one working on any key/value pair like :
AP_IMPLEMENT_HOOK_RUN_ALL(int, env_parser,
(apr_pool_t *p, const char **key, const char
**value), (p, key, value), OK, DECLINED)
This seems quite costly though...
>
> The point being, that comprehensively covers data coming from
> an HTTP request and that might find its way into a subprocess
> environment! Unless someone embeds a backdoor in some trojan,
> in which case all bets are off ...
>
>> Unfortunately that's not an extensible part of
>> code (no hook). Furthermore cleaning the env vars only works for CGI,
>> but not e.g. for FCGI, SCGI proxying etc. Sometimes it would be
>> convenient to sanitize data on e.g. a revproxy and not on every internal
>> web server maybe doing CGI. So I'd say mod_taint is a good compromise
>> between the slightly higher safety of directly sanitizing the env vars
>> and compatibility with current hooks.
>
> You're looking at a WAF there. mod_taint is but one small part of
> the functionality of a WAF, but just happens to be the part that
> sits between untrusted Request data and a subprocess environment!
> Cleaning up headers and QEURY_STRING/PATH_INFO protects a generic
> backend, anything from local CGI to proxy.
>
>> I haven't looked at your updated code yet (only at the old one that
>> didn't easily allow to untaint all headers),
>
> Indeed, it was only after your first email that I looked at it
> and started thinking harder about whether it in fact did the job!
>
>> but could it be helpful to
>> allow narrowing down which headers and vars to untaint? Like e.g. with a
>> regexp against the header/var name? Something between listing individual
>> headers und untainting all headers? Or is there no real use case for this?
>
> I don't really see a use case. HTTP rules allow arbitrary
> headers as extensions and CGI rules translate those by
> formula to environment variables, so we always need some
> kind of catch-all. But I guess there's nothing to stop
> wildcarding being incorporated into the apr_table_do
> that iterates over request_headers and subprocess_env.
>
>> Some headers have a more complex internal structure. Cookies come to
>> mind. There one might want to untaint using a regexp against the cookie
>> values, not the cookie header value.
>
> What matters is the value passed to the subprocess as
> HTTP_COOKIE. We're sanitising that, but parsing the
> (sanitised) value(s) is none of our business.
>
> --
> Nick Kew
>
Re: Proposed simple shell-shock protection
Posted by Nick Kew <ni...@webthing.com>.
On Sun, 2014-09-28 at 23:10 +0200, Rainer Jung wrote:
> IMHO it is a useful approach. Whan I looked at the CGI topic, I noticed
> that the safest thing is cleaning up in ap_create_environment(), because
> you can be sure to get every env var in your hands there, not only the
> ones coming from headers.
The "shellshock" recipe for mod_taint takes a bit of a kitchen-sink
approach:
- The Request headers
- The Request fields that haven't always been fully sanitised
and that might try to smuggle something: PATH_INFO and
QUERY_STRING (r->args).
- subprocess_env
The point being, that comprehensively covers data coming from
an HTTP request and that might find its way into a subprocess
environment! Unless someone embeds a backdoor in some trojan,
in which case all bets are off ...
> Unfortunately that's not an extensible part of
> code (no hook). Furthermore cleaning the env vars only works for CGI,
> but not e.g. for FCGI, SCGI proxying etc. Sometimes it would be
> convenient to sanitize data on e.g. a revproxy and not on every internal
> web server maybe doing CGI. So I'd say mod_taint is a good compromise
> between the slightly higher safety of directly sanitizing the env vars
> and compatibility with current hooks.
You're looking at a WAF there. mod_taint is but one small part of
the functionality of a WAF, but just happens to be the part that
sits between untrusted Request data and a subprocess environment!
Cleaning up headers and QEURY_STRING/PATH_INFO protects a generic
backend, anything from local CGI to proxy.
> I haven't looked at your updated code yet (only at the old one that
> didn't easily allow to untaint all headers),
Indeed, it was only after your first email that I looked at it
and started thinking harder about whether it in fact did the job!
> but could it be helpful to
> allow narrowing down which headers and vars to untaint? Like e.g. with a
> regexp against the header/var name? Something between listing individual
> headers und untainting all headers? Or is there no real use case for this?
I don't really see a use case. HTTP rules allow arbitrary
headers as extensions and CGI rules translate those by
formula to environment variables, so we always need some
kind of catch-all. But I guess there's nothing to stop
wildcarding being incorporated into the apr_table_do
that iterates over request_headers and subprocess_env.
> Some headers have a more complex internal structure. Cookies come to
> mind. There one might want to untaint using a regexp against the cookie
> values, not the cookie header value.
What matters is the value passed to the subprocess as
HTTP_COOKIE. We're sanitising that, but parsing the
(sanitised) value(s) is none of our business.
--
Nick Kew
Re: Proposed simple shell-shock protection
Posted by Rainer Jung <ra...@kippdata.de>.
Am 26.09.2014 um 16:41 schrieb Nick Kew:
> I've revisited mod_taint this morning, and made some updates:
> a bugfix, a new option to apply an untainting rule to all headers.
> But topically, a canned configuration option to protect
> against shell-shock patterns:
>
> LoadModule modules/mod_taint.so
> Untaint shellshock
>
> Untaint works in a directory context, so can be
> selectively enabled for potentially-vulnerable apps
> such as those involving CGI, SSI, ExtFilter,
> or (other) scripts.
>
> This goes through all Request headers, any PATH_INFO
> and QUERY_STRING, and (just to be paranoid) any
> other subprocess environment variables. It untaints
> them against a regexp that checks for "()" at the
> beginning of a variable, and returns an HTTP 400 error
> (Bad Request) if found.
>
> Feedback welcome, indeed solicited. I believe this
> is a simple but sensible approach to protecting
> potentially-vulnerable systems, but I'm open to
> contrary views. The exact details, including the
> shellshock regexp itself, could probably use some
> refinement. And of course, bug reports!
>
> Builds and runs with httpd 2.2 and 2.4. Very limited
> testing verifies that it catches a shellshock attack
> in a request header.
>
> http://people.apache.org/~niq/mod_taint.html
>
> Note: cross-posting, with followup-to set to dev@.
> If you're following up to report a critical bug,
> adding users@ will ensure widest exposure!
IMHO it is a useful approach. Whan I looked at the CGI topic, I noticed
that the safest thing is cleaning up in ap_create_environment(), because
you can be sure to get every env var in your hands there, not only the
ones coming from headers. Unfortunately that's not an extensible part of
code (no hook). Furthermore cleaning the env vars only works for CGI,
but not e.g. for FCGI, SCGI proxying etc. Sometimes it would be
convenient to sanitize data on e.g. a revproxy and not on every internal
web server maybe doing CGI. So I'd say mod_taint is a good compromise
between the slightly higher safety of directly sanitizing the env vars
and compatibility with current hooks.
I haven't looked at your updated code yet (only at the old one that
didn't easily allow to untaint all headers), but could it be helpful to
allow narrowing down which headers and vars to untaint? Like e.g. with a
regexp against the header/var name? Something between listing individual
headers und untainting all headers? Or is there no real use case for this?
Some headers have a more complex internal structure. Cookies come to
mind. There one might want to untaint using a regexp against the cookie
values, not the cookie header value.
Regards,
Rainer
Re: [users@httpd] Proposed simple shell-shock protection
Posted by Nick Kew <ni...@webthing.com>.
On 29 Sep 2014, at 19:41, Pete Houston wrote:
> It is not a flaw in apache. Apache is simply a network-enabled channel
> through which exploitative payloads may be delivered to unpatched
> installations of bash (one of many such channels).
Yep. mod_taint (or any other Apache-based solution) is secondary protection.
Updating bash must be your primary defence.
Your system may not be vulnerable in the first place. If bash isn't
your default shell then the chances of it getting invoked by anything
running under apache are very remote. Check #!/bin/sh: if it's a
not link to bash then the chances of bash ever being reachable through
apache are very remote unless/until your attacker already owns you.
If you want to be properly paranoid, run apache in a VM or chroot jail
with no bash at all!
--
Nick Kew
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Proposed simple shell-shock protection
Posted by Pete Houston <ph...@openstrike.co.uk>.
On Mon, Sep 29, 2014 at 01:09:19PM -0500, Sharon Zastre wrote:
> Is it safe to assume that a fix/patch/upgrade will become available to address the shellshock vulnerability?
Yes, but not in apache. The vulnerability dubbed "shellshock" is a
flaw in bash and patches and upgrades are already widely available for
bash. Upgrade or patch your bash installations now.
It is not a flaw in apache. Apache is simply a network-enabled channel
through which exploitative payloads may be delivered to unpatched
installations of bash (one of many such channels).
Pete
--
Openstrike - improving business through open source
http://www.openstrike.co.uk/ or call 01722 770036 / 07092 020107
RE: [users@httpd] Proposed simple shell-shock protection
Posted by Sharon Zastre <SZ...@dryden.ca>.
I will admit that I am far from an advanced user of Apache. So for now I think I will hold off on trying to create the module. Is it safe to assume that a fix/patch/upgrade will become available to address the shellshock vulnerability?
Thanks,
Sharon
-----Original Message-----
From: Nick Kew [mailto:nick@webthing.com]
Sent: Monday, September 29, 2014 12:59 PM
To: users@httpd.apache.org
Subject: Re: [users@httpd] Proposed simple shell-shock protection
On 29 Sep 2014, at 17:35, Sharon Zastre wrote:
> Thank you Nick for quickly looking into a solution/work around for the shellshock vulnerability. But I'm confused as to how to implement it. I am currently at Apache 2.4.9 with OpenSSL 1.0.1g. Do I need to upgrade to 2.4.10 or 2.5(?) first? Will it simply be in the install and I include mod_taint in the config file? Or is this a separate download that I need to run?
No, you don't need to upgrade anything. Just build the module.
with your existing 2.2.x or 2.4.x. Maybe even 2.0.x: I haven't tried!
If you don't know how, the tool you need is apxs, and the server docs explain how to use it.
You should also be aware that if you're not accustomed to getting
your hands dirty, you might find it too 'bleeding edge'. I just had a
bug report a few hours ago and have yet to find time to investigate.
--
Nick Kew
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Proposed simple shell-shock protection
Posted by Nick Kew <ni...@webthing.com>.
On 29 Sep 2014, at 17:35, Sharon Zastre wrote:
> Thank you Nick for quickly looking into a solution/work around for the shellshock vulnerability. But I'm confused as to how to implement it. I am currently at Apache 2.4.9 with OpenSSL 1.0.1g. Do I need to upgrade to 2.4.10 or 2.5(?) first? Will it simply be in the install and I include mod_taint in the config file? Or is this a separate download that I need to run?
No, you don't need to upgrade anything. Just build the module.
with your existing 2.2.x or 2.4.x. Maybe even 2.0.x: I haven't tried!
If you don't know how, the tool you need is apxs, and the server
docs explain how to use it.
You should also be aware that if you're not accustomed to getting
your hands dirty, you might find it too 'bleeding edge'. I just had a
bug report a few hours ago and have yet to find time to investigate.
--
Nick Kew
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
RE: [users@httpd] Proposed simple shell-shock protection
Posted by Sharon Zastre <SZ...@dryden.ca>.
Thank you Nick for quickly looking into a solution/work around for the shellshock vulnerability. But I'm confused as to how to implement it. I am currently at Apache 2.4.9 with OpenSSL 1.0.1g. Do I need to upgrade to 2.4.10 or 2.5(?) first? Will it simply be in the install and I include mod_taint in the config file? Or is this a separate download that I need to run?
Thanks,
Sharon
-----Original Message-----
From: Nick Kew [mailto:nick@webthing.com]
Sent: Friday, September 26, 2014 9:42 AM
To: dev@httpd.apache.org; users@httpd.apache.org
Subject: [users@httpd] Proposed simple shell-shock protection
I've revisited mod_taint this morning, and made some updates:
a bugfix, a new option to apply an untainting rule to all headers.
But topically, a canned configuration option to protect against shell-shock patterns:
LoadModule modules/mod_taint.so
Untaint shellshock
Untaint works in a directory context, so can be selectively enabled for potentially-vulnerable apps such as those involving CGI, SSI, ExtFilter, or (other) scripts.
This goes through all Request headers, any PATH_INFO and QUERY_STRING, and (just to be paranoid) any other subprocess environment variables. It untaints them against a regexp that checks for "()" at the beginning of a variable, and returns an HTTP 400 error (Bad Request) if found.
Feedback welcome, indeed solicited. I believe this is a simple but sensible approach to protecting potentially-vulnerable systems, but I'm open to contrary views. The exact details, including the shellshock regexp itself, could probably use some refinement. And of course, bug reports!
Builds and runs with httpd 2.2 and 2.4. Very limited testing verifies that it catches a shellshock attack in a request header.
http://people.apache.org/~niq/mod_taint.html
Note: cross-posting, with followup-to set to dev@.
If you're following up to report a critical bug, adding users@ will ensure widest exposure!
--
Nick Kew
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: Proposed simple shell-shock protection
Posted by Nick Kew <ni...@webthing.com>.
On 26 Sep 2014, at 15:59, Yann Ylavic wrote:
> Hi Nick,
>
> any link to the source code?
Sorry, thought there was a link from the HTML page, but that
must've got lost in the update.
http://people.apache.org/~niq/mod_taint.c
--
Nick Kew
Re: Proposed simple shell-shock protection
Posted by Yann Ylavic <yl...@gmail.com>.
Hi Nick,
any link to the source code?
Regards,
Yann.
On Fri, Sep 26, 2014 at 4:41 PM, Nick Kew <ni...@webthing.com> wrote:
> I've revisited mod_taint this morning, and made some updates:
> a bugfix, a new option to apply an untainting rule to all headers.
> But topically, a canned configuration option to protect
> against shell-shock patterns:
>
> LoadModule modules/mod_taint.so
> Untaint shellshock
>
> Untaint works in a directory context, so can be
> selectively enabled for potentially-vulnerable apps
> such as those involving CGI, SSI, ExtFilter,
> or (other) scripts.
>
> This goes through all Request headers, any PATH_INFO
> and QUERY_STRING, and (just to be paranoid) any
> other subprocess environment variables. It untaints
> them against a regexp that checks for "()" at the
> beginning of a variable, and returns an HTTP 400 error
> (Bad Request) if found.
>
> Feedback welcome, indeed solicited. I believe this
> is a simple but sensible approach to protecting
> potentially-vulnerable systems, but I'm open to
> contrary views. The exact details, including the
> shellshock regexp itself, could probably use some
> refinement. And of course, bug reports!
>
> Builds and runs with httpd 2.2 and 2.4. Very limited
> testing verifies that it catches a shellshock attack
> in a request header.
>
> http://people.apache.org/~niq/mod_taint.html
>
> Note: cross-posting, with followup-to set to dev@.
> If you're following up to report a critical bug,
> adding users@ will ensure widest exposure!
>
> --
> Nick Kew