Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Apache: Dev

[patch] Fix cross-user symlink race condition vulnerability

 

 

Apache dev RSS feed   Index | Next | Previous | View Threaded


ejacobs at bluehost

Oct 30, 2012, 9:46 PM

Post #1 of 9 (1767 views)
Permalink
[patch] Fix cross-user symlink race condition vulnerability

There is a race condition vulnerability in httpd 2.2.23 (also present in
previous releases) that allows a malicious user to serve arbitrary files
from nearly anywhere on a server that isn't protected by strict os level
permissions. In a shared hosting environment, this is a big vulnerability.

If you would like more information on the exploit itself, please let me
know. I have a proof of concept that is able to hit the exploit with
100% success.

This is my first patch submitted to Apache, so I'm sorry if I've missed
something. I'm aware that this doesn't meet some of the code standards
that are in place (e.g, it doesn't work at all on Windows), but I wanted
to put it out there anyway.

The patch that fixes the vulnerability is attached. Thank you in advance
for the feedback.

--

Eric Jacobs
Junior Systems Administrator
Bluehost.com
Attachments: httpd-2.2.23-symlink-protection.patch (8.13 KB)


christophe.jaillet at wanadoo

Oct 31, 2012, 12:10 AM

Post #2 of 9 (1692 views)
Permalink
Re: [patch] Fix cross-user symlink race condition vulnerability [In reply to]

Le 31/10/2012 05:46, Eric Jacobs a écrit :
> There is a race condition vulnerability in httpd 2.2.23 (also present
> in previous releases) that allows a malicious user to serve arbitrary
> files from nearly anywhere on a server that isn't protected by strict
> os level permissions. In a shared hosting environment, this is a big
> vulnerability.
>
> If you would like more information on the exploit itself, please let
> me know. I have a proof of concept that is able to hit the exploit
> with 100% success.
>
> This is my first patch submitted to Apache, so I'm sorry if I've
> missed something. I'm aware that this doesn't meet some of the code
> standards that are in place (e.g, it doesn't work at all on Windows),
> but I wanted to put it out there anyway.
>
> The patch that fixes the vulnerability is attached. Thank you in
> advance for the feedback.
>

Hi,

could you please open a bug report on bugzilla
(https://issues.apache.org/bugzilla/) so that your message and proposed
patch does not get lost in this mailing list.

Thanks in advance.

Best regards,
Christophe JAILLET


minfrin at sharp

Oct 31, 2012, 4:31 AM

Post #3 of 9 (1688 views)
Permalink
Re: [patch] Fix cross-user symlink race condition vulnerability [In reply to]

On 31 Oct 2012, at 6:46 AM, Eric Jacobs <ejacobs [at] bluehost> wrote:

> There is a race condition vulnerability in httpd 2.2.23 (also present in previous releases) that allows a malicious user to serve arbitrary files from nearly anywhere on a server that isn't protected by strict os level permissions. In a shared hosting environment, this is a big vulnerability.
>
> If you would like more information on the exploit itself, please let me know. I have a proof of concept that is able to hit the exploit with 100% success.
>
> This is my first patch submitted to Apache, so I'm sorry if I've missed something. I'm aware that this doesn't meet some of the code standards that are in place (e.g, it doesn't work at all on Windows), but I wanted to put it out there anyway.
>
> The patch that fixes the vulnerability is attached. Thank you in advance for the feedback.

As this is reported as a security issue, would it be possible instead to email the details to security [at] httpd, and we can take a look?

Regards,
Graham
--
Attachments: smime.p7s (4.26 KB)


covener at gmail

Oct 31, 2012, 5:00 AM

Post #4 of 9 (1698 views)
Permalink
Re: [patch] Fix cross-user symlink race condition vulnerability [In reply to]

On Wed, Oct 31, 2012 at 7:31 AM, Graham Leggett <minfrin [at] sharp> wrote:
> On 31 Oct 2012, at 6:46 AM, Eric Jacobs <ejacobs [at] bluehost> wrote:
>
>> There is a race condition vulnerability in httpd 2.2.23 (also present in previous releases) that allows a malicious user to serve arbitrary files from nearly anywhere on a server that isn't protected by strict os level permissions. In a shared hosting environment, this is a big vulnerability.
>>
>> If you would like more information on the exploit itself, please let me know. I have a proof of concept that is able to hit the exploit with 100% success.
>>
>> This is my first patch submitted to Apache, so I'm sorry if I've missed something. I'm aware that this doesn't meet some of the code standards that are in place (e.g, it doesn't work at all on Windows), but I wanted to put it out there anyway.
>>
>> The patch that fixes the vulnerability is attached. Thank you in advance for the feedback.
>
> As this is reported as a security issue, would it be possible instead to email the details to security [at] httpd, and we can take a look?
>

In general that is the proper form -- but this particular issue is
documented as a limitation:

"Omitting this option should not be considered a security restriction,
since symlink testing is subject to race conditions that make it
circumventable."


ejacobs at bluehost

Oct 31, 2012, 12:36 PM

Post #5 of 9 (1690 views)
Permalink
Re: [patch] Fix cross-user symlink race condition vulnerability [In reply to]

On 10/31/2012 06:00 AM, Eric Covener wrote:
> In general that is the proper form -- but this particular issue is
> documented as a limitation:
>
> "Omitting this option should not be considered a security restriction,
> since symlink testing is subject to race conditions that make it
> circumventable."

Some users (like Bluehost) require the functionality of symlinks without
the possibility of server side vulnerabilities. Having the vulnerability
documented doesn't keep servers safe. The patch I submitted allows httpd
to use symlinks in a protected fashion that doesn't allow for users to
serve arbitrary files.

I'll go ahead and submit a more detailed email to the security. More
feedback from the devs is appreciated.


--

Eric Jacobs
Junior Systems Administrator
Bluehost.com


covener at gmail

Oct 31, 2012, 12:49 PM

Post #6 of 9 (1693 views)
Permalink
Re: [patch] Fix cross-user symlink race condition vulnerability [In reply to]

On Wed, Oct 31, 2012 at 3:36 PM, Eric Jacobs <ejacobs [at] bluehost> wrote:
> On 10/31/2012 06:00 AM, Eric Covener wrote:
>>
>> In general that is the proper form -- but this particular issue is
>> documented as a limitation:
>>
>> "Omitting this option should not be considered a security restriction,
>> since symlink testing is subject to race conditions that make it
>> circumventable."
>
>
> Some users (like Bluehost) require the functionality of symlinks without the
> possibility of server side vulnerabilities. Having the vulnerability
> documented doesn't keep servers safe.

My point was that discussion of this particular issue does not need to
be segregated to the private security list.


lazy404 at gmail

Nov 4, 2012, 3:18 PM

Post #7 of 9 (1762 views)
Permalink
Re: [patch] Fix cross-user symlink race condition vulnerability [In reply to]

2012/10/31 Eric Jacobs <ejacobs [at] bluehost>:
> On 10/31/2012 06:00 AM, Eric Covener wrote:
>>
>> In general that is the proper form -- but this particular issue is
>> documented as a limitation:
>>
>> "Omitting this option should not be considered a security restriction,
>> since symlink testing is subject to race conditions that make it
>> circumventable."
>
>
> Some users (like Bluehost) require the functionality of symlinks without the
> possibility of server side vulnerabilities. Having the vulnerability
> documented doesn't keep servers safe. The patch I submitted allows httpd to
> use symlinks in a protected fashion that doesn't allow for users to serve
> arbitrary files.
>
> I'll go ahead and submit a more detailed email to the security. More
> feedback from the devs is appreciated.

on some systems, at least on Linux You can use a grsecurity kernel
patch feature which prevents those races
and is cheeper performance wise

+config GRKERNSEC_SYMLINKOWN
+ bool "Kernel-enforced SymlinksIfOwnerMatch"
+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
+ help
+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
+ that prevents it from being used as a security feature. As Apache
+ verifies the symlink by performing a stat() against the target of
+ the symlink before it is followed, an attacker can setup a symlink
+ to point to a same-owned file, then replace the symlink with one
+ that targets another user's file just after Apache "validates" the
+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
+ will be in place for the group you specify. If the sysctl option
+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
+ created.

there probably is something similar on *BSD's, or if there isn't it
won't be hard to make

Your patch checks for a race conditions every time, even if Symlinks
weren't allowed. It also references some
configuration dependent directory like /usr/local/apache/htdocs.

--
Michal Grzedzicki


jasonstaburn at yahoo

Mar 4, 2013, 8:25 AM

Post #8 of 9 (1458 views)
Permalink
RE: [patch] Fix cross-user symlink race condition vulnerability [In reply to]

> If you would like more information on the exploit itself, please let me  
> know. I have a proof of concept that is able to hit the exploit with 
> 100% success.

Hi Eric,

I'm trying to test this patch and would love to know how you're able to duplicate this on-demand.

Thanks,
Jason


ejacobs at bluehost

Mar 5, 2013, 3:12 PM

Post #9 of 9 (1483 views)
Permalink
Re: [patch] Fix cross-user symlink race condition vulnerability [In reply to]

On 03/04/2013 09:25 AM, Jason Staburn wrote:
>> If you would like more information on the exploit itself, please let me
>> know. I have a proof of concept that is able to hit the exploit with
>> 100% success.
>
> I'm trying to test this patch and would love to know how you're able to duplicate this on-demand.
>

My proof of concept is attached to this email, but this exploit shows up
in the wild all the time. I've seen numerous php and perl based exploits
pop up via script kiddie injections. This PoC is just something I threw
together in a few minutes.

You'll need to update the paths to the files in main() to suit your
environment. If you're having a hard time hitting the race condition,
try tuning tim.tv_nsec in tsleep().

Finally, this exploit works two ways:
1) symlinking directly to your target file.
2) symlinking to a directory containing the target file.

The patch I published a few months ago fixes both vectors.


--
Eric Jacobs
Junior Systems Administrator
Bluehost.com
Attachments: symlink-poc.c (1.71 KB)

Apache dev RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.