[Résolu] Problème de sécurité Apache et VirtualHost

Bonjour,

Je suis confronté à un sacré problème de sécurité et je n’arrive pas à trouver comment palier à ça.
Sur mon serveur, j’héberge plusieurs sites Internet— pour ça, j’utilise des VirtualHost via Apache.

Chaque site à son dossier racine placé dans /opt/apache2/flex/NOM-DU-SITE.EXT/www

Le problème ;
Si un petit malin utilise la fonction include() de PHP et s’amuse à
récupérer le contenu d’un fichier .htaccess ou pire, .htpasswd d’un
autre VirtualHost que le sien; ça fonctionne et retourne le contenu du
fichier.

Par exemple, le site vhost «tutu-rose.sexy» place le fichier index.php
avec le code
include(’/opt/apache2/flex/site-super-important.com/www-secure/.htpasswd’); —
le contenu s’affiche.

Mon but est d’empêcher ceci mais, je vois pas comment faire.

Voici une partie de mon fichier apache2.conf

#
# LogLevel: Control the severity of messages logged to the error_log.
# Available values: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the log level for particular modules, e.g.
# "LogLevel info ssl:warn"
#
LogLevel crit

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf

# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#
AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>


#
# The following directives define some format nicknames for use with
# a CustomLog directive.
#
# These deviate from the Common Log Format definitions in that they use %O
# (the actual bytes sent including headers) instead of %b (the size of the
# requested file), because the latter makes it impossible to detect partial
# requests.
#
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
# Use mod_remoteip instead.
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

# Include other options
Include apache2-security.conf

# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

Et un exemple de fichier VirtualHost ;

[code]<VirtualHost *:80>
ServerName tutu-rose.sexy
ServerAlias tutu-rose.sexy

    ServerAdmin webmaster@tutu-rose.sexy
    DocumentRoot /opt/apache2/flex/tutu-rose.sexy

    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /opt/apache2/flex/tutu-rose.sexy/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Require all granted
            DirectoryIndex index.php index.html
    </Directory>

    #ErrorLog ${APACHE_LOG_DIR}/error.log
    #LogLevel info

    #CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName tutu-rose.sexy ServerAlias www.tutu-rose.sexy
    ServerAdmin webmaster@tutu-rose.sexy
    DocumentRoot /opt/apache2/flex/tutu-rose.sexy/www

    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /opt/apache2/flex/tutu-rose.sexy/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Require all granted
            DirectoryIndex index.php index.html
    </Directory>

    #ErrorLog ${APACHE_LOG_DIR}/error.log
    #LogLevel info

    #CustomLog ${APACHE_LOG_DIR}/access.log combined
[/code]

PS : Entre parenthèses, j’ai fait quelques tests; certains hébergeurs dont je ne citerais pas le nom ont la même faille!

D’ailleurs, même un include(’/etc/ppp/chap-secrets’); fonctionne et me retourne les logins VPN… :scream:

Bonsoir,

php_admin_value open_basedir “un_chemin” placé dans un fichier VirtualHost permet “en gros”, de restreindre l’accès à php à un ou plusieurs répertoires.

Deux liens qui devrait répondre à vos questions :
https://www.camillebaronnet.fr/blog/fr/gerer-un-base-directory-different-pour-chaque-vhost-avec-open_basedir
https://wiki.apache.org/httpd/SecuringPHP

2 J'aime

@cedric058 :

Dire que j’ai cherché durant des heures sur «mon ami Google» et que je n’ai absolument rien trouvé de concluent ou fonctionnel…

C’est exactement ça que je cherchais. Un grand merci !— Sujet résolu.


<VirtualHost *:80>
    ServerName mon-site-a-moi.net
    ServerAlias mon-site-a-moi.net

    ServerAdmin webmaster@mon-site-a-moi.net
    DocumentRoot /opt/apache2/flex/mon-site-a-moi.net

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /opt/apache2/flex/mon-site-a-moi.net/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
                DirectoryIndex index.php index.html
        </Directory>
        <IfModule mod_php5.c>
                php_value open_basedir   /dev/urandom:/dev/null:/opt/apache2/common:/tmp:/opt/apache2/flex/mon-site-a-moi.net
                php_value upload_tmp_dir /tmp
        </IfModule>

    #ErrorLog ${APACHE_LOG_DIR}/error.log
    #LogLevel info

    #CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:80>
    ServerName mon-site-a-moi.net
    ServerAlias www.mon-site-a-moi.net        
    ServerAdmin webmaster@mon-site-a-moi.net        
    DocumentRoot /opt/apache2/flex/mon-site-a-moi.net/www

        <Directory />
                Options FollowSymLinks
                AllowOverride None
        </Directory>
        <Directory /opt/apache2/flex/mon-site-a-moi.net/www/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Require all granted
                DirectoryIndex index.php index.html
        </Directory>
        <IfModule mod_php5.c>
                php_value open_basedir   /dev/urandom:/dev/null:/opt/apache2/common:/tmp:/opt/apache2/flex/mon-site-a-moi.net/www
                php_value upload_tmp_dir /tmp
        </IfModule>

    #ErrorLog ${APACHE_LOG_DIR}/error.log
    #LogLevel info

    #CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

PS : Je tiens à préciser que j’ai rajouté /dev/null et /dev/urandom en sus de /tmp car la documentation d’ownCloud le recommande fortement pour des raisons de sécurité.

ÉNORME ! :scream:
merci pour ce topic… je viens de modifier tous mes vhosts ! :sweat_smile: