超越PHP PHP动态 | 经典文章 | CLASS | 相关下载 | 常见问题 | FORUM | WIKI | 在线手册
Site search:    
<Case 4: PHP parser outside of web treeFilesystem Security>
Last updated: Fri, 22 Jun 2007

章 24. Installed as an Apache module

When PHP is used as an Apache module it inherits Apache's user permissions (typically those of the "nobody" user). This has several impacts on security and authorization. For example, if you are using PHP to access a database, unless that database has built-in access control, you will have to make the database accessible to the "nobody" user. This means a malicious script could access and modify the database, even without a username and password. It's entirely possible that a web spider could stumble across a database administrator's web page, and drop all of your databases. You can protect against this with Apache authorization, or you can design your own access model using LDAP, .htaccess files, etc. and include that code as part of your PHP scripts.

Often, once security is established to the point where the PHP user (in this case, the apache user) has very little risk attached to it, it is discovered that PHP is now prevented from writing any files to user directories. Or perhaps it has been prevented from accessing or changing databases. It has equally been secured from writing good and bad files, or entering good and bad database transactions.

A frequent security mistake made at this point is to allow apache root permissions, or to escalate apache's abilities in some other way.

Escalating the Apache user's permissions to root is extremely dangerous and may compromise the entire system, so sudo'ing, chroot'ing, or otherwise running as root should not be considered by those who are not security professionals.

There are some simpler solutions. By using open_basedir you can control and restrict what directories are allowed to be used for PHP. You can also set up apache-only areas, to restrict all web based activity to non-user, or non-system, files.




add a note add a note User Contributed Notes
Installed as an Apache module
hallow at webmages dot com
11-Jul-2001 08:54
mod_php is bad for virtual hosting.  If you've got 5 different vhosts running on apache, and mod_php installed, and each of the users have some page that requires php to write something to the disk, and they give proper permissions for the web server to do so, anyone with access to php/the web server can do so.

Also, if their application has a config file which is blocked say by .htaccess, that contains things like database logins and passwords, etc., it must be readable by the web server, and as such anyone with access to write a php script can grab a copy of the file off the disk and display it.

The only way to get around this is to run a seperate instance of apache for each virtual server, or to use the php-cgi binary and something like apache's suEXEC.

<Case 4: PHP parser outside of web treeFilesystem Security>
 Last updated: Fri, 22 Jun 2007
view source | feedback | send page | sitemap | aboutus   
Copyright ® 2002-2003 PHPE.NET. All rights reserved
Last updated:2002-11-22