PHP security filter code (provided by 360 with high security factor)

WBOY
Release: 2016-07-25 08:57:33
Original
1323 people have browsed it
  1. /**

  2. * Filter dangerous parameters
  3. * edit: bbs.it-home.org
  4. */
  5. //Code By Safe3
  6. function customError($errno, $errstr, $errfile, $errline)
  7. {
  8. echo "Error number: [$errno],error on line $errline in $errfile
    ";
  9. die();
  10. }
  11. set_error_handler("customError",E_ERROR);
  12. $getfilter="'|(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)";
  13. $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)";
  14. $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)";
  15. function StopAttack($StrFiltKey,$StrFiltValue,$ArrFiltReq){

  16. if(is_array($StrFiltValue))

  17. {
  18. $StrFiltValue=implode($StrFiltValue);
  19. }
  20. if (preg_match("/".$ArrFiltReq."/is",$StrFiltValue)==1){
  21. //slog("

    操作IP: ".$_SERVER["REMOTE_ADDR"]."
    操作时间: ".strftime("%Y-%m-%d %H:%M:%S")."
    操作页面:".$_SERVER["PHP_SELF"]."
    提交方式: ".$_SERVER["REQUEST_METHOD"]."
    提交参数: ".$StrFiltKey."
    提交数据: ".$StrFiltValue);
  22. print "360websec notice:Illegal operation!";
  23. exit();
  24. }
  25. }
  26. //$ArrPGC=array_merge($_GET,$_POST,$_COOKIE);
  27. foreach($_GET as $key=>$value){
  28. StopAttack($key,$value,$getfilter);
  29. } //bbs.it-home.org
  30. foreach($_POST as $key=>$value){
  31. StopAttack($key,$value,$postfilter);
  32. }
  33. foreach($_COOKIE as $key=>$value){
  34. StopAttack($key,$value,$cookiefilter);
  35. }
  36. if (file_exists('update360.php')) {
  37. echo "请重命名文件update360.php,防止黑客利用
    ";
  38. die();
  39. }
  40. function slog($logs)
  41. {
  42. $toppath=$_SERVER["DOCUMENT_ROOT"]."/log.htm";
  43. $Ts=fopen($toppath,"a+");
  44. fputs($Ts,$logs."rn");
  45. fclose($Ts);
  46. }
  47. ?>

复制代码

您可能感兴趣的文章:

PHP过滤post,get敏感数据的实例代码 php 过滤非法与特殊字符串的方法 php 防注入的一段代码(过滤参数) php正则过滤html标签、空格、换行符等的代码示例 php实现过滤IP黑白名单的方法 很好用的php防止sql注入漏洞过滤函数的代码 php中使用过滤功能的输入验证 php防止sql注入正则过滤一例 php过滤危险html的代码


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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template