当前位置:Gxlcms > PHP教程 > 360防跨站攻击脚本

360防跨站攻击脚本

时间:2021-07-01 10:21:17 帮助过:9人阅读

填写您的邮件地址,订阅我们的精彩内容:转载地址: http://blog.qita.in/?post=275

使用方法:
require_once('360.php');
  1. //http://blog.qita.in
  2. function customError($errno, $errstr, $errfile, $errline)
  3. {
  4. echo "Error number: [$errno],error on line $errline in $errfile
    ";
  5. die();
  6. }
  7. set_error_handler("customError",E_ERROR);
  8. $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)";
  9. $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)";
  10. $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)";
  11. function StopAttack($StrFiltKey,$StrFiltValue,$ArrFiltReq){
  12. if(is_array($StrFiltValue))
  13. {
  14. $StrFiltValue=implode($StrFiltValue);
  15. }
  16. if (preg_match("/".$ArrFiltReq."/is",$StrFiltValue)==1){
  17. //slog("

    操作IP: ".$_SERVER["REMOTE_ADDR"]."
    操作时间: ".strftime("%Y-%m-%d %H:%M:%S")."
    操作页面:".$_SERVER["PHP_SELF"]."
    提交方式: ".$_SERVER["REQUEST_METHOD"]."
    提交参数: ".$StrFiltKey."
    提交数据: ".$StrFiltValue);
  18. print "360websec notice:Illegal operation!";
  19. exit();
  20. }
  21. }
  22. //$ArrPGC=array_merge($_GET,$_POST,$_COOKIE);
  23. foreach($_GET as $key=>$value){
  24. StopAttack($key,$value,$getfilter);
  25. }
  26. foreach($_POST as $key=>$value){
  27. StopAttack($key,$value,$postfilter);
  28. }
  29. foreach($_COOKIE as $key=>$value){
  30. StopAttack($key,$value,$cookiefilter);
  31. }
  32. function slog($logs)
  33. {
  34. $toppath=$_SERVER["DOCUMENT_ROOT"]."/log.htm";
  35. $Ts=fopen($toppath,"a+");
  36. fputs($Ts,$logs."\r\n");
  37. fclose($Ts);
  38. }
  39. ?>

人气教程排行