禁用php函数的设置

来源:互联网 发布:linux结束进程命令 编辑:程序博客网 时间:2024/05/21 13:57
打开PHP.INI,找到这行:
disable_functions =

在后面那里加上要禁用的函数,如禁用多个函数,要用半角逗号 , 分开 

给个例子:

disable_functions = passthru,exec,system,popen,chroot,scandir,chgrp,chown,escapesh

ellcmd,escapeshellarg,shell_exec,proc_open,proc_get_status


建议在主机上禁用的函数:

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] view plaincopy
  1. <?php  
  2. header("content-Type: text/html; charset=utf-8");  
  3. header("Cache-Control: no-cache, must-revalidate");    
  4. header("Pragma: no-cache");  
  5. error_reporting(0);  
  6. ob_end_flush();  
  7.   
  8. ?>  
  9. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  10. <html xmlns="http://www.w3.org/1999/xhtml">  
  11. <head>  
  12. <meta http-equiv="Pragma" content="No-cache" />  
  13. <meta http-equiv="Expires" content="0" />  
  14. <meta http-equiv="cache-control" content="private" />  
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />//[color=red]加了这句,看看能不能解决linux下显示乱码的问题?[/color]  
  16. <title>PHP 探针 v1.0</title>  
  17. <style type="text/css">  
  18. <!--  
  19. body{text-align:center;margin-top:20px;background-color:#a9b674;}  
  20.   
  21. #overview{width:700px;margin:0 auto;text-align:left;}  
  22. a{text-decoration:underline;color:#992700;}  
  23. .strong{color:#992700;}  
  24. .basew{width:300px;}  
  25. -->  
  26. </style>  
  27. </head>  
  28.   
  29. <body>  
  30. <div id="overview">  
  31. <div id="copyright">版权信息  
  32. <a href="hello.php?typ=baseinfo">[基本信息]</a> <a href="hello.php?typ=superinfo">[高级信息]</a>  
  33. <?php  
  34. if (function_exists("phpinfo")){  
  35.     echo'<a href="hello.php?typ=phpinfo">[phpinfo]</a>';}  
  36.   
  37. echo'<br />php探针v1.0 by MKDuse(blueidea-id)<br /><br />此程序代码,可免费使用;但不得用于商业用途;完全转载或使用此代码,请保留版权信息;<br />欢迎指正错误提建议,QQ:122712355</div>';  
  38.   
  39. if (empty($_GET['typ'])){  
  40.     baseinfo();}  
  41. else{  
  42. switch ($_GET['typ']){  
  43. case 'phpinfo':  
  44. phpinfoview();  
  45. break;  
  46. case 'superinfo':  
  47. superinfo();  
  48. break;  
  49. case 'baseinfo':  
  50. baseinfo();  
  51. break;  
  52. default:  
  53. baseinfo();}  
  54. }  
  55.   
  56. function getime()  
  57. {  
  58.   $t = gettimeofday();  
  59.   return (float)($t['sec'] + $t['usec']/1000000);  
  60. }  
  61.   
  62.   
  63. function baseinfo(){  
  64. echo '<h1>基本信息</h1>';  
  65. $arr[]=array("Current PHP version:",phpversion());  
  66. $arr[]=array("Zend engine version:",zend_version());  
  67. $arr[]=array("服务器版本",$_SERVER['SERVER_SOFTWARE']);  
  68. $arr[]=array("ip地址",$_SERVER['REMOTE_HOST']);//ip  
  69. $arr[]=array("域名",$_SERVER['HTTP_HOST']);  
  70. $arr[]=array("协议端口",$_SERVER['SERVER_PROTOCOL'].'  '.$_SERVER['SERVER_PORT']);  
  71. $arr[]=array("站点根目录",$_SERVER['PATH_TRANSLATED']);  
  72. $arr[]=array("服务器时间",date('Y年m月d日,H:i:s,D'));  
  73. $arr[]=array("当前用户",get_current_user());  
  74. $arr[]=array("操作系统",php_uname('s').php_uname('r').php_uname('v'));  
  75. $arr[]=array("include_path",ini_get('include_path'));  
  76. $arr[]=array("Server API",php_sapi_name());  
  77.   
  78. $arr[]=array("error_reporting level",ini_get("display_errors"));  
  79. $arr[]=array("POST提交限制",ini_get('post_max_size'));  
  80. $arr[]=array("upload_max_filesize",ini_get('upload_max_filesize'));  
  81. $arr[]=array("脚本超时时间",ini_get('max_execution_time').'秒');  
  82.   
  83. if (ini_get("safe_mode")==0){  
  84. $arr[]=array("PHP安全模式(Safe_mode)",'off');}  
  85. else{  
  86. $arr[]=array("PHP安全模式(Safe_mode)",'on');}  
  87.   
  88. if (function_exists('memory_get_usage')){  
  89. $arr[]=array("memory_get_usage",ini_get('memory_get_usage'));}  
  90.   
  91. //$arr[]=array("可用空间",intval(diskfreespace('/')/(1024 * 1024))."M");  
  92. echo'<table>';  
  93. for($i=0;$i<count($arr);$i++)  
  94. {  
  95.     $overview='<tr><td class="basew">'.$arr[$i][0].'</td><td>'.$arr[$i][1].'</td></tr>';  
  96.     echo $overview;  
  97. }  
  98. echo'</table>';  
  99. echo '<h2>服务器性能测试</h2>';  
  100. echo'<table><tr><td>服务器</td><td>整数运算<br />50万次加法(1+1)</td><td>浮点运算<br />50万次平方根(3.14开方)</td></tr>';  
  101. echo'<tr><td>MKDuse的机子(P4 1.5G 256DDR winxp sp2)</td><td>465.08ms</td><td>466.66ms</td></tr>';  
  102. $time_start=getime();  
  103. for($i=0;$i<=500000;$i++);  
  104. {$count=1+1;}  
  105. $timea=round((getime()-$time_start)*1000,2);  
  106. echo '<tr class="strong"><td>当前服务器</td><td>'.$timea.'ms</td>';  
  107.   
  108. $time_start=getime();  
  109. for($i=0;$i<=500000;$i++);  
  110. {sqrt(3.14);}  
  111. $timea=round((getime()-$time_start)*1000,2);  
  112. echo '<td>'.$timea.'ms</td></tr></table>';  
  113.   
  114.   
  115. ?>  
  116. <script language="javascript" type="text/javascript">  
  117. function gettime()  
  118. {    
  119.   var time;    
  120.   time=new Date();  
  121.   return time.getTime();    
  122. }  
  123. start_time=gettime();  
  124. </script>  
  125. <?php  
  126. echo '<h2>带宽测试</h2>';  
  127. for ($i=0;$i<100;$i++){  
  128. print "<!--1234567890#########0#########0#########0#########0#########0#########0#########0#########012345-->";}  
  129.   
  130. ?>  
  131. <p id="dk"></p>  
  132. <script language="javascript" type='text/javascript'>  
  133. var timea;  
  134. var netspeed;  
  135. timea=gettime()-start_time;  
  136. netspeed=Math.round(10/timea*1000);  
  137. document.getElementByIdx("dk").innerHTML="向客户端发送10KB数据,耗时"+timea+"ms<br />您与此服务器的连接速度为"+netspeed+"kb/s";  
  138. </script>  
  139.   
  140. <?php  
  141.   
  142. echo'<h2>已加载的扩展库(enable)</h2><div>';  
  143. $arr =get_loaded_extensions();  
  144. foreach($arr as $value){  
  145.     echo $value.'<br />';}  
  146.   
  147. echo'</div><h2>禁用的函数</h2><p>';  
  148. $disfun=ini_get('disable_functions');  
  149. if (empty($disfun)){  
  150.     echo'没有禁用</p>';}  
  151. else{  
  152. echo ini_get('disable_functions').'</p>';}  
  153.   
  154. }//关闭  
  155.   
  156.   
  157.   
  158. function superinfo(){  
  159. echo'<h1>高级信息</h1><p>PHP_INI_USER 1 配置选项可用在用户的 PHP 脚本或Windows 注册表中<br> PHP_INI_PERDIR 2 配置选项可在 php.ini, .htaccess 或 httpd.conf 中设置 <br>PHP_INI_SYSTEM 4 配置选项可在 php.ini or httpd.conf 中设置 <br>PHP_INI_ALL 7 配置选项可在各处设置</p>';  
  160.   
  161. $arr1=ini_get_all();  
  162. for ($i=0;$i<count($arr1);$i++)  
  163.     {  
  164. $arr2=array_slice($arr1,$i,1);  
  165. print_r($arr2);  
  166. echo '<br />';  
  167. }  
  168.   
  169. }  
  170.   
  171. function phpinfoview(){  
  172.     phpinfo();  
  173. }  
  174. ?>  
  175. </div>  
  176. </body>  
  177. </html>  

phpinfo() 
功能描述:输出 PHP 环境信息以及相关的模块、WEB 环境等信息。 
危险等级:中 

passthru() 
功能描述:允许执行一个外部程序并回显输出,类似于 exec()。 
危险等级:高 

exec() 
功能描述:允许执行一个外部程序(如 UNIX Shell 或 CMD 命令等)。 
危险等级:高 

system() 
功能描述:允许执行一个外部程序并回显输出,类似于 passthru()。 
危险等级:高 

chroot() 
功能描述:可改变当前 PHP 进程的工作根目录,仅当系统支持 CLI 模式 
PHP 时才能工作,且该函数不适用于 Windows 系统。 
危险等级:高 

scandir() 
功能描述:列出指定路径中的文件和目录。 
危险等级:中 

chgrp() 
功能描述:改变文件或目录所属的用户组。 
危险等级:高 

chown() 
功能描述:改变文件或目录的所有者。 
危险等级:高 

shell_exec() 
功能描述:通过 Shell 执行命令,并将执行结果作为字符串返回。 
危险等级:高 

proc_open() 
功能描述:执行一个命令并打开文件指针用于读取以及写入。 
危险等级:高 

proc_get_status() 
功能描述:获取使用 proc_open() 所打开进程的信息。 
危险等级:高 

error_log() 
功能描述:将错误信息发送到指定位置(文件)。 
安全备注:在某些版本的 PHP 中,可使用 error_log() 绕过 PHP safe mode, 
执行任意命令。 
危险等级:低 

ini_alter() 
功能描述:是 ini_set() 函数的一个别名函数,功能与 ini_set() 相同。 
具体参见 ini_set()。 
危险等级:高 

ini_set() 
功能描述:可用于修改、设置 PHP 环境配置参数。 
危险等级:高 

ini_restore() 
功能描述:可用于恢复 PHP 环境配置参数到其初始值。 
危险等级:高 

dl() 
功能描述:在 PHP 进行运行过程当中(而非启动时)加载一个 PHP 外部模块。 
危险等级:高 

pfsockopen() 
功能描述:建立一个 Internet 或 UNIX 域的 socket 持久连接。 
危险等级:高 

syslog() 
功能描述:可调用 UNIX 系统的系统层 syslog() 函数。 
危险等级:中 

readlink() 
功能描述:返回符号连接指向的目标文件内容。 
危险等级:中 

symlink() 
功能描述:在 UNIX 系统中建立一个符号链接。 
危险等级:高 

popen() 
功能描述:可通过 popen() 的参数传递一条命令,并对 popen() 所打开的文件进行执行。 
危险等级:高 

stream_socket_server() 
功能描述:建立一个 Internet 或 UNIX 服务器连接。 
危险等级:中 

putenv() 
功能描述:用于在 PHP 运行时改变系统字符集环境。在低于 5.2.6 版本的 PHP 中,可利用该函数 
修改系统字符集环境后,利用 sendmail 指令发送特殊参数执行系统 SHELL 命令。 
危险等级:高 

禁用方法如下: 
打开/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
0 0
原创粉丝点击