知行合一

防范php木马

1、防止跳出web目录 (严重采用)

  首先修改httpd.conf,如果你只允许你的php脚本程序在web目录里操作,还可以修改httpd.conf文件限制php的操作路径。比如你的web目录是/usr/local/apache/htdocs,那么在httpd.conf里加上这么几行:

  php_admin_value open_basedir /usr/local/apache/htdocs

  这样,如果脚本要读取/usr/local/apache/htdocs以外的文件将不会被允许,如果错误显示打开的话会提示这样的错误:

  Warning: open_basedir restriction in effect. File is in wrong directory in /usr/local/apache/htdocs/open.php on line 4 等等。

如果有多个基于域名的虚拟主机

<VirtualHost *>
ServerName     www.test1.com
DocumentRoot /usr/local/apache/htdocs/test1
<Directory /usr/local/apache/htdocs/test1>
     php_admin_value open_basedir     /usr/local/apache/htdocs/test1
</Directory>
</VirtualHost>

注意:在php_admin_value open_basedir别忘了加上php.ini中指定的PHP临时上传目录和session保存目录,不然会无法上传文件、存取session
php.ini中按如下配置:
upload_tmp_dir = “/tmp”
session.save_path = “/var/phpsession”

  2、防止php木马执行webshell (严重采用)

  打开safe_mode,

  在,php.ini中设置

  disable_functions= passthru,exec,shell_exec,system

  二者选一即可,也可都选

  3、防止php木马读写文件目录 (好像没有要求这么严格,不推荐采用。)

  在php.ini中的

  disable_functions= passthru,exec,shell_exec,system

  后面加上php处理文件的函数

  主要有

  fopen,mkdir,rmdir,chmod,unlink,dir

  fopen,fread,fclose,fwrite,file_exists

  closedir,is_dir,readdir.opendir

  fileperms.copy,unlink,delfile

  即成为

  disable_functions= passthru,exec,shell_exec,system,fopen,mkdir,rmdir,chmod,unlink,dir

  ,fopen,fread,fclose,fwrite,file_exists

  ,closedir,is_dir,readdir.opendir

  ,fileperms.copy,unlink,delfile

  ok,大功告成,php木马拿我们没辙了.

赞(0) 打赏
未经允许不得转载:嘟嘟鱼 » 防范php木马
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏