PHPCMS v9 安全主机设置方法

PHPCMS又被挂木马了,caches目录下的模板文件被篡改,附件上传目录上传了后门,检查了一下,是因为用的phpcms版本太老,没有进行安全更新。

又检查了一下apache的目录权限,设置的有问题,改了一下,能防住大部份的安全问题。

安全原则:
有写入权限的目录,不能被执行
附件目录,不能的执行文件,如php,asp

修改以后的目录权限如下。phpcms核心框架目录,caches目录肯定是不允许访问的,html生成的目录和附件上传目录,不允许执行php。
至于phpsso_server,这个鸡肋的东西,估计也没有用户使用,直接删除或者禁止访问。

另外呢,svn里也可以很明显的看到文件修改历史,caches目录会不断修改更新,建议写个计划任务,1个小时删除一下所有模板缓存。

[php]
NameVirtualHost *:80
<virtualhost *:80>
DocumentRoot /var/www/www.baidu.com
ServerName www.baidu.com
ServerAlias baidu.com
<directory /var/www/www.baidu.com>
allow from all
Options -Indexes
AllowOverride None
</directory>

<directory /var/www/www.baidu.com/phpcms>
Deny from all
</directory>

<directory /var/www/www.baidu.com/caches>
Deny from all
</directory>

<directory /var/www/www.baidu.com/html>
php_flag engine off
</directory>

<directory /var/www/www.baidu.com/phpsso_server>
php_flag engine off
</directory>

<directory /var/www/www.baidu.com/statics>
php_flag engine off
</directory>

<directory /var/www/www.baidu.com/uploadfile>
php_flag engine off
</directory>

</virtualhost>

[/php]

如果中了木马,在Linux下也有快速的清除方法
[shell]
cd uploadfile
find -name *php -exec rm -rf {} \;
find -name *Php -exec rm -rf {} \;

cd ../caches
ack -i eval

cd ../html
ack -i eval

cd ../
find -name *.php -exec grep eval {} \;

[/shell]

发表评论