记录日常工作关于系统运维,虚拟化云计算,数据库,网络安全等各方面问题。

确认 PHP 能够正常工作后,编辑 /usr/local/Comsenz/etc/php.ini 进行设置提升 PHP 安全性。查找

disable_functions =

修改成

disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen

然后重启 web 服务:

service httpd restart


查找disable_functions然后用下面的替换

复制代码 代码如下:

disable_functions =phpinfo,exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source

Save and close the file. Restart httpd:
复制代码 代码如下:

# service httpd restart

Note that the disable_functions directive can not be used outside of the php.ini file which means that you cannot disable functions on a per-virtualhost or per-directory basis in your httpd.conf file. If we add this to our php.ini file:

iis中设置方法,在c:\windows\php.ini

星外的设置:

代码如下:

disable_functions =exec,system,passthru,popen,pclose,shell_exec,proc_open,dl,chmod,gzinflate,set_time_limit

建议增加phpinfo等,可以参考上面的设置,以后在使用过程中可能会出现php不支持部分功能的现象,然后大家可以搜索下错误提示,去掉相应的函数即可。
支持的越多越不安全,对于采集程序来说需要去掉curl_exec,大家多测试即可。

下面提供一个更完整的版本

代码如下:

disable_functions =phpinfo,exec,system,passthru,popen,pclose,shell_exec,proc_open,dl,curl_exec,multi_exec,chmod,gzinflate,set_time_limit,



注意下面的突破方法:建议打开安全模式


禁用方法如下:
打开/etc/php.ini文件,
查找到 disable_functions ,添加需禁用的函数名,如下:
phpinfo,eval,passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket,fsockopen



建议禁止php函数列表如下:

复制代码
代码如下:

disable_functions = system,exec,shell_exec,passthru,proc_open,proc_close, proc_get_status,checkdnsrr,getmxrr,getservbyname,getservbyport, syslog,popen,show_source,highlight_file,dl,socket_listen,socket_create,socket_bind,socket_accept, socket_connect, stream_socket_server, stream_socket_accept,stream_socket_client,ftp_connect, ftp_login,ftp_pasv,ftp_get,sys_getloadavg,disk_total_space, disk_free_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname



转载请标明出处【php 不安全函数禁用 disable_functions】。

《www.micoder.cc》 虚拟化云计算,系统运维,安全技术服务.

网站已经关闭评论