Home > php教程 > PHP源码 > 【转载】360提供的Php防注入代码

【转载】360提供的Php防注入代码

PHP中文网
Release: 2016-05-25 17:09:42
Original
1065 people have browsed it

【转载】360提供的Php防注入代码

<?php  
//Code By Safe3  
function customError($errno, $errstr, $errfile, $errline)  
{  
  echo "<b>Error number:</b> [$errno],error on line $errline in $errfile<br />" ;  
  die();  
}  
set_error_handler("customError",E_ERROR);  
$getfilter="&#39;|(and|or)\\b.+?(>|<|=|in|like)|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?Select|Update.+?SET|Insert\\s+INTO.+?VALUES|(Select|Delete).+?FROM|(Create|Alter|Drop|TRUNCATE)\\s+(TABLE|DATABASE)" ;  
$postfilter="\\b(and|or)\\b.{1,6}?(=|>|<|\\bin\\b|\\blike\\b)|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?Select|Update.+?SET|Insert\\s+INTO.+?VALUES|(Select|Delete).+?FROM|(Create|Alter|Drop|TRUNCATE)\\s+(TABLE|DATABASE)" ;  
$cookiefilter="\\b(and|or)\\b.{1,6}?(=|>|<|\\bin\\b|\\blike\\b)|\\/\\*.+?\\*\\/|<\\s*script\\b|\\bEXEC\\b|UNION.+?Select|Update.+?SET|Insert\\s+INTO.+?VALUES|(Select|Delete).+?FROM|(Create|Alter|Drop|TRUNCATE)\\s+(TABLE|DATABASE)" ;  
function StopAttack($StrFiltKey,$StrFiltValue,$ArrFiltReq){  
  
if(is_array($StrFiltValue))  
{  
  $StrFiltValue=implode($StrFiltValue);  
}  
if (preg_match("/".$ArrFiltReq."/is",$StrFiltValue)==1){  
    //slog("<br><br>操作IP: ".$_SERVER["REMOTE_ADDR"]."<br>操作时间: ".strftime("%Y-%m-%d %H:%M:%S")."<br>操作页面:".$_SERVER["PHP_SELF"]."<br>提交方式: ".$_SERVER["REQUEST_METHOD"]."<br>提交参数: ".$StrFiltKey."<br>提交数据: ".$StrFiltValue);  
    print "360websec notice:Illegal operation!" ;  
    exit();  
}    
}  
//$ArrPGC=array_merge($_GET,$_POST,$_COOKIE);  
foreach($_GET as $key=>$value){  
  StopAttack($key,$value,$getfilter);  
}  
foreach($_POST as $key=>$value){  
  StopAttack($key,$value,$postfilter);  
}  
foreach($_COOKIE as $key=>$value){  
  StopAttack($key,$value,$cookiefilter);  
}  
/*
if (file_exists(&#39;update360.php&#39;)) {  
  echo "请重命名文件update360.php,防止黑客利用<br/>";  
  die();  
} 
*/ 
function slog($logs)  
{  
  $toppath=$_SERVER["DOCUMENT_ROOT"]."/log.htm";  
  $Ts=fopen($toppath,"a+");  
  fputs($Ts,$logs."\r\n");  
  fclose($Ts);  
}
Copy after login


 以上就是【转载】360提供的Php防注入代码的内容,更多相关内容请关注PHP中文网(www.php.cn)!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template