Installato come modulo Apache

Quando PHP viene utilizzato come modulo Apache, esso eredita i permessi dell'utente Apache (tipicamente quelli dell'utente "nobody"). Questo ha diversi impatti sulla sicurezza e l'autorizzazione. Per esempio, se si sta usando PHP per accedere ad un database, a meno che il database non abbia un sistema interno di controllo degli accessi, dovrai rendere il database accessibile dall'utente "nobody". Questo significa che uno script malevolo potrebbe accedere e modificare il database, anche senza username e password. É del tutto possibile che uno spider web possa atterrare sulla pagina web dell'amministratore del database, ed eliminare tutti i tuoi database. Puoi proteggerti da questo tramite le autorizzazioni di Apache, o puoi progettare il tuo modello di accessi attraverso LDAP, i file .htaccess, ecc. ed includere quel codice come parte dei tuoi script PHP.

Spesso, una volta che la sicurezza viene stabilita verso il punto dove l'utente PHP (in questo caso, l'utente apache) ha pochissimi rischi collegati ad esso, si scopre che a PHP viene ora impedito di scrivere su qualsiasi file, nelle directory degli utenti. O forse è stato impedito l'accesso o la modifica dei database. É stato equamente messo in sicurezza dalla scrittura di file buoni e cattivi, o dall'ingresso di transazioni buone e cattive al database.

Un errore frequente di sicurezza fatto a questo punto è di fornire i permessi di root ad apache, o di aumentare le abilità di apache in qualche altro modo.

Fornire i permessi di root all'utente Apache è estremamente pericoloso e può compromettere l'intero sistema, quindi metodi come sudo, chroot, o l'esecuzione come root non dovrebbero essere presi in considerazione da coloro che non sono dei professionisti della sicurezza.

Ci sono alcune soluzioni più semplici. Utilizzando open_basedir puoi controllare e limitare quali directory posso essere utilizzate per PHP. Puoi inoltre impostare delle aree solo per apache, limitando tutte le attività web ai file non di utenti, oppure non di sistema.

add a note add a note

User Contributed Notes 4 notes

up
11
bk 2 at me dot com
12 years ago
doc_root already limits apache/php script folder locations.

open_basedir is better used to restrict script access to folders
which do NOT contain scripts. Can be a sub-folder of doc_root as in php doc example doc_root/tmp, but better yet in a separate folder tree, like ~user/open_basedir_root/. Harmful scripts could modify other scripts if doc_root (or include_path) and open_basedir overlap.
If apache/php can't browse scripts in open_basedir, even if malicious scripts uploaded more bad scripts there, they won't be browse-able (executable).

One should also note that the many shell execute functions are effectively a way to bypass open_basedir limits, and such functions should be disabled if security demands strict folder access control. Harmful scripts can do the unix/windows version of "delete */*/*/*" if allowed to execute native os shell commands via those functions. OS Shell commands could similarly bypass redirect restrictions and upload file restrictions by just brute force copying files into the doc_root tree. It would be nice if they could be disabled as a group or class of functions, but it is still possible to disable them one by one if needed for security.

PS. currently there is a bug whereby the documented setting of open_basedir to docroot/tmp will not work if any include or require statements are done. Right now include will fail if the included php file is not in BOTH the open_basedir tree and the doc_root+include_path trees. Which is the opposite of safe.
This means by any included php file must be in open_basedir, so is vulnerable to harmful scripts and php viruses like Injektor.
up
2
daniel dot eckl at gmx dot de
21 years ago
There is a better solution than starting every virtual host in a seperate instance, which is wasting ressources.

You can set open_basedir dynamically for every virtual host you have, so every PHP script on a virtual host is jailed to its document root.

Example:
<VirtualHost www.example.com>
  ServerName www.example.com
  DocumentRoot /www-home/example.com
[...]
  <Location />
    php_admin_value open_basedir     \ "/www-home/example.com/:/usr/lib/php/"
  </Location>
</VirtualHost>

If you set safe_mode on, then the script can only use binaries in given directories (make a special dir only with the binaries your customers may use).

Now no user of a virtual host can read/write/modify the data of another user on your machine.

Windseeker
up
-9
Vikanich
15 years ago
Big thanks to "daniel dot eckl at gmx dot de" but i have to change his config, because it doesn't work (may be wrong syntax).
I have add only this string to VirtualHost config and it works.
php_admin_value open_basedir  /www/site1/
Now all php scripts are locked in the directory.
up
-19
Kibab
18 years ago
I'm running Windows version of Apache with php as module. System is Windows XP Service Pack 2 on NTFS filesystem. To avoid potential security problems, I've set Apache to run under NT AUTHORITY\Network Service account, and there is only one directory, named Content, with Full Access for this account. Other directories are either not accessible at all or with readonly permissions (like %systemroot%)... So, even if Apache will be broken, nothing would happen to entire system, because that account doesn't have admin privilegies :)
To Top