PHPKonf Istanbul PHP Conference 2019 - Call for Papers

湖北11选五: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 4 notes

bk 2 at me dot com
6 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.
daniel dot eckl at gmx dot de
16 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.

  DocumentRoot /www-home/
  <Location />
    php_admin_value open_basedir     \ "/www-home/"

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.

10 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.
13 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
  • 12306网站用户信息外泄?铁总深夜“辟谣” 2018-12-11
  • 第二届加强创新和社会管理案例理论论坛暨社会管理创新案例颁奖典礼 2018-12-10
  • 中国共产党第十九次全国代表大会 2018-12-10
  • 女性之声——全国妇联 2018-12-10
  • NBA总决赛4比0横扫骑士问鼎 4年夺3冠勇士王朝! 2018-12-09
  • 图解:关于中国梦,习近平总书记这十句话直抵人心 2018-12-09
  • 【十九大·理论新视野】动漫:“美丽中国”如何绘就 2018-12-09
  • 宁波制造分享俄罗斯世界杯经济蛋糕 2018-12-08
  • 为丰富百姓餐桌提供更多选择(打开对外开放新局面) 2018-12-08
  • 英媒:中国正引领无人智能设备革命 城市机器人或将崛起 2018-12-08
  • 强征钢铝税惹众怒,美国在G7财长会上被孤立 2018-12-07
  • 太原35397名考生参加中考体测 2018-12-07
  • 西藏昂仁县:保障群众健康生活 用健康扶贫助推精准扶贫 2018-12-07
  • 警惕打着“高科技”旗号的食品虚假宣传 2018-12-07
  • 不是“不尊重公投”,而是不尊重人类社会发展规律就是不尊重人类。 2018-12-06
  • 900| 653| 133| 505| 643| 437| 579| 176| 518| 80|