- 论坛徽章:
- 1
|
本帖最后由 yakczh_cu 于 2014-11-03 21:24 编辑
- <?php
-
- 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="'|(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){
-
- print " websec 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);
- }
复制代码 把这段代码当狗皮膏药贴到index.php里面,一贴就灵 |
|