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.
아파치 모듈로 설치
PHP를 아파치 모듈로 사용할 때, 아파치의 사용자 권한(일반적으로 "nobody" 사용자)을 따릅니다. 이는 보안과 인증에 몇가지 영향을 줍니다. 예를 들어, PHP로 데이터베이스에 접근할 때, 데이터베이스에 내장 접근 제어가 없다면 데이터베이스에 "nobody" 사용자가 접근할 수 있게 해야 합니다. 이는 이상한 스크립트가 사용자이름과 패스워드 없이 데이터베이스에 접근하여 변경할 수 있다는 뜻입니다. 웹 스파이더가 데이터베이스 관리자 웹 페이지에 접근하여 모든 데이터베이스를 지울 수도 있습니다. 아파치 인증이나, LDAP, .htaccess 파일 등을 사용한 자체 접근 모델을 만들고, PHP 스크립트의 일부분으로 포함하여 이러한 일들에 대항할 수 있습니다.
종종, PHP 사용자(이 경우, 아파치 사용자) 시점에서 보안이 성립되어 위험이 줄지만, 이제 PHP가 사용자 디렉토리에 파일을 쓸 수 없는 점을 발견하게 됩니다. 또는 데이터베이스 접근과 변경이 막혀있을 수 있습니다. 정상 파일과 위험 파일, 또는 정상과 이상 데이터베이스 트랜젝션을 넣는 점에 대해서 동일한 보안 효과를 가지기 때문입니다.
이 시점에서 자주 일어나는 보안 실책은 아파치에 루트 권한을 주거나, 비슷한 기능을 실행할 수 있게 하는 것입니다.
아파치 사용자 권한을 루트로 올리는 것은 매우 위험하고, 전체 시스템을 위태롭게 합니다. 그러므로, sudo, chroot, 루트로 실행하기 등은 보안 전문가가 아닌 사람이 생각해서는 안됩니다.
간단한 해결책이 있습니다. open_basedir로 PHP에서 허용할 디렉토리를 제어하고 제한할 수 있습니다. 아파치 전용 구역을 설정해서, 모든 웹 기반 행동을 사용자, 시스템, 파일에 영향을 주지 않도록 제한할 수 있습니다.
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 :)
There is a safe way to support a lot of users in a secure way, without having to use CGI, in a way which is probebly faster
than mod_php.
Use FastCGI, with the SuExecWrapper set to your suid wrapper. It means every user wil get his own program-group, with processes
which are being reused. If the numer of processes that is being
started on startup is 0, then the processgroup for a user will be generated when needed.
This means: The first page is slow, after that the Zend Engine caching kicks in. When the load on the virtualhost reduces, the
processes wil die off, and extra processes for a user-process-group
will only be started when (again) needed.
Your apache will be a LOT! lichter, because it won't have to drag all
the php-memory overhead with it. This means static content is
faster, and the whole system uses less memory.
The PHP itself also won't need to drag along the apache overhead.
If for one reason or the other php craches, your apache will simple
start some new php-processes. If you want to upgrade/patch php,
you can simple create the new fastcgi binary, and after testing, you can simple update the system by copying it, and maybe doing a
'apachectl gracefull'
In short : Sepparating distinct functions in different processes
communicating useing IPC methodes can be very good
for performance and security. The best example of this
principle at work is Postfix, where every process runs
chroot() under its own uid.
http://wiki.openisis.org/i/view/Php/HowtoFastCgi
Additional CAUTION to anyone trying Pollux's solution:
It's kind a good. Probably works right. I think I'll give it a try myself. BUT...
its safe ONLY on the assumption that apache is 100% CLEAN. (codes and confs.) Any flaws on apache, almost ANYTHING could happen to ALL users -precisely, web users. (Because apache is a member of ALL -again, web user's- GID.) So, leeps's hint should be one of the important things.
There is nothing close to perfect. What I wrote is just one thing you'll have to keep in mind. So, consider carefully BEFORE you try this solution. (Well, this applies to any other solutions though...)
@pollux: additionally, tell your users to set their file-permissions to
- r-- (group) for files
- --x (group) for directories.
this disables the webserver to browse user's directory. if you don't know the filename, you cannot open it, e.g. by running malicious php-code through one of the users scripts.
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
