正在加载……
禁止在允许上传的目录中执行PHP
| |
Posted in 情感天地 on January 24, 2007 / 引用(0)
  • 强烈建议:将服务器上脚本程序目录以外的部分设置为禁止PHP脚本运行(下文中提到的"php_admin_flag engine off/on"参数),以防止恶意脚本的上传和运行。
  • 将register_globals设为关闭状态,否则可能造成部分程序不安全。关闭的方法参见 http://php.net/register_globals (英文)。
  • LocalSettings.php中包含数据库用户的密码,请不要在网站空间上随意建立备份文件,以免被作为文本文件访问而造成泄密。
  • 禁止在允许上传的目录中执行PHP,因为有人可能作为服务器用户来执行任意的代码。同时建议将HTML文件强制解释为文本文件,以避免窃取cookie攻击。这是apache设置的代码片断:
<Location "/wiki/images">
 php_admin_flag engine off
 AddType text/plain .html .htm .shtml
</Location>
  • 这也可以通过设置上传目录中的.htaccess文件完成(注意将该文件进行写保护):
 php_value engine off
 AddType text/plain .html .htm .shtml

关于服务器Apache httpd的说明

你可能希望将HTML文件强制解释为文本文件,以避免窃取cookie攻击。这是apache设置的代码片断:

 <Directory "/Library/MediaWiki/web/images">
    # Ignore .htaccess files
    AllowOverride None
    
    # Serve HTML as plaintext
    AddType text/plain .html .htm .shtml
    
    # Don't run arbitrary PHP code.
    php_admin_flag engine off
    
    # If you've other scrīpting languages, disable them too.
 </Directory>

关于PHP解释器的说明

register_globals

在Mediawiki版本1.2之后,不再需要php.ini中的register_globals被打开。

强烈建议关闭register_globals,除非另外的应用需要。

php.ini可能存放在:

  • /etc/php.ini (Red Hat Linux)
  • /etc/php4/apache/php.ini (Debian woody)
  • /usr/local/php/lib/php.ini (Mac OS X using Marc Liyanage's PHP package)
  • /var/www/conf/php.ini (OpenBSD)
  • /usr/local/etc/php.ini (FreeBSD)
  • /etc/apache2/conf/php.ini (Gentoo Linux)
  • c:\windows\php.ini (Windows)

请将php.ini中的“register_globals = On”改为“register_globals = Off”。

作为替代手段,你可以在apache directive中加入下面一行,以基于单一目录的方式禁用register_globals:

php_flag register_globals off

之后重启Apache以使变动产生作用。

上传目录的安全设置

  • 禁止在允许上传的目录中执行PHP,因为有人可能作为服务器用户来执行任意的代码。实际上,其他CGI程序脚本也应当被禁止。同时建议将HTML文件强制解释为文本文件,以避免窃取cookie攻击。这是apache设置的代码片断范例:
<Location "/wiki/images">
  php_admin_flag engine off
  Options -ExecCGI
  AddType text/plain .html .htm .shtml .php
</Location>
This entry comes from 本站原创 and has been read for 136 times.It is tagged with .
发表评论

昵称

网址

电邮

OpenID登入 高级选项 表情