-----------------使用方法------------------------------------------------------------------ 1.將360_safe3.php、update360.php傳到要包含的文件的目錄 2.在所需要防護(hù)的頁面加入代碼 require_once('360_safe3.php'); 就可以做到頁面防注入、跨站 如果想整站防注,就在網(wǎng)站的一個(gè)公用文件中,如數(shù)據(jù)庫鏈接文件config.inc.php中! 添加require_once('360_safe3.php');來調(diào)用本代碼 常用php系統(tǒng)添加文件 PHPCMS V9 \phpcms\base.php PHPWIND8.7 \data\sql_config.php DEDECMS5.7 \data\common.inc.php DiscuzX2 \config\config_global.php Wordpress \wp-config.php Metinfo \include\head.php 3.在每個(gè)文件最前加上代碼 在php.ini中找到: Automatically add files before or after any PHP document. auto_prepend_file = 360_safe3.php路徑; 4.修改update360.php文件名防止黑客利用,訪問修改后update360xxx.php升級(jí)防護(hù)代碼 ------------------------------------------------------------------------------------------------------------------------------------ 以下是360_safe3.php,代碼,新建文本文檔,copy代碼,保存文件名為360_safe3.php。注意保存代碼編碼格式為UTF-8 <?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="'|(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>操作時(shí)間: ".strftime("%Y-%m-%d %H:%M:%S")."<br>操作頁面:".$_SERVER["PHP_SELF"]."<br>提交方式: ".$_SERVER["REQUEST_METHOD"]."<br>提交參數(shù): ".$StrFiltKey."<br>提交數(shù)據(jù): ".$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('update360.php')) { echo "請(qǐng)重命名文件update360.php,防止黑客利用<br/>"; die(); } function slog($logs) { $toppath=$_SERVER["DOCUMENT_ROOT"]."/log.htm"; $Ts=fopen($toppath,"a+"); fputs($Ts,$logs."\r\n"); fclose($Ts); } ?> ------------------------------------------------------------------------------------------------------------------------------------ |
|