360 XSS protection script

Source: Internet
Author: User
360 XSS protection script
Reprint address: http://blog.qita.in /? Posting = 275

Usage:
Require_once ('2014. 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 ("

    Operation IP address: ". $ _ SERVER [" REMOTE_ADDR "]."
    Operation Time: ". strftime (" % Y-% m-% d % H: % M: % S ")."
    Operation page: ". $ _ SERVER [" PHP_SELF "]."
    Submission method: ". $ _ SERVER [" REQUEST_METHOD "]."
    Parameter submitted: ". $ StrFiltKey ."
    Submit data: ". $ StrFiltValue );
  18. Print "360 websec 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. ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.