li26598296 发表于 2018-12-22 11:37:14

PHP推荐禁用函数disable_functions PHP安全配置

  最近服务器的phpmyadmin一直不正常,原以为配置错误,结果发现是前段时间修改disable_function引起的,
  逐步比较disable_function的参数发现,原来是因为opendir,readdir,dir,chdir这4个参数引起的
  禁用opendir报错如下:
  phpmyadmin就会出现如下错误
  phpMyAdmin-ERROR: cannot open themes folder: ./themes
  Default theme pmahomme not found!
  Theme original not found!
  Theme not found!
  但是phpspy就不能列出其他虚拟主机的目录
  官方解释:http://cn.php.net/manual/zh/function.opendir.php
  opendir:打开目录句柄
  加上readdir
  phpmyadmin首页能打开,但是不能登陆,502 Bad Gateway
  phpspy此时不能列出其他虚拟主机目录
  官方解释:http://cn.php.net/manual/zh/function.readdir.php
  readdir — 从目录句柄中读取条目,返回目录中下一个文件的文件名
  最后总结出比较安全的php.ini的disable_functions如下(服务器没用到采集):
  disable_functions = exec,passthru,popen,proc_open,shell_exec,system,phpinfo,assert,chroot,getcwd,scandir,unlink,delete,rmdir,rename,chgrp,chmod,chown,fopen,copy,mkdir,file,file_get_contents,fputs,fwrite,dir
  禁用这些函数,网站和phpmyadmin都正常,而且不能上传文件
  利用webshell也不能查看服务器上的文件,不能删除或者修改
  唯一的缺点:能够查看其他虚拟主机的目录,但是仅仅只能看看,做不了什么事情
  如果服务器用到了采集,需要启用unlink和fopen,列表如下:
  disable_functions = exec,passthru,popen,proc_open,shell_exec,system,phpinfo,assert,chroot,getcwd,scandir,delete,rmdir,rename,chgrp,chmod,chown,copy,mkdir,file,file_get_contents,fputs,fwrite,dir
  unlink官方解释为:http://cn.php.net/manual/zh/function.unlink.php
  fopen官方解释为:http://cn.php.net/manual/zh/function.fopen.php
  如果需要用到采集,需要启用这几个函数:
  file_get_contents,fputs,fwrite,dir
  禁用的函数列表为:
  disable_functions =exec,passthru,popen,proc_open,shell_exec,system,phpinfo,assert,chroot,getcwd,scandir,delete,rmdir,rename,chgrp,chmod,chown,copy,mkdir,file
  http://www.linuxso.com/jiaobenruqin/11724.html

页: [1]
查看完整版本: PHP推荐禁用函数disable_functions PHP安全配置