1.将360_safe3.php传到要包含的文件的目录
2.在页面中加入防护,有两种做法,根据情况二选一即可: 香山红叶网- DsZ)9Cl@eJg3LV3M
a).在所需要防护的页面加入代码
require_once('360_safe3.php');
就可以做到页面防注入、跨站
如果想整站防注,就在网站的一个公用文件中,如数据库链接文件config.inc.php中!
添加require_once('360_safe3.php');来调用本代码 香山红叶网- {&}{{x6}8I8XmTpf
b).在每个文件最前加上代码
在php.ini中找到:
Automatically add files before or after any PHP document.
auto_prepend_file = 360_safe3.php路径; 香山红叶网- YRQLke{k|VvW}9Gn
PHP代码
<?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>操作时间: ".strftime("%Y-%m-%d %H:%M:%S")."<br>操作页面:".$_SERVER["PHP_SELF"]."<br>提交方式: ".$_SERVER["REQUEST_METHOD"]."<br>提交参数: ".$StrFiltKey."<br>提交数据: ".$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 "请重命名文件update360.php,防止黑客利用<br/>";
die();
}
function slog($logs)
{
$toppath=$_SERVER["DOCUMENT_ROOT"]."/log.htm";
$Ts=fopen($toppath,"a+");
fputs($Ts,$logs."\r\n");
fclose($Ts);
}
?>
asp使用方法: 香山红叶网- 3S!%mHoAi{}:pf9S
1、将如下代码保存为360_safe3.asp 文件并上传到要包含的文件的目录 香山红叶网- D:PqiR@FDU[1$rN|
2、在页面中引入上述 360_safe3.asp 文件: 香山红叶网- @%hNvkgNYqd^z3^n
<!--#include virtual=“/360_safe3.asp”--> 香山红叶网- u{3*1"~q_zC[9)W"
如果想整站防注,就在网站的一个公用文件中,如数据库链接文件 conn.asp 中引入! 香山红叶网- M@"IocW cpCNnxT2
香山红叶网- mkRq23h#:|LE}tm~
Asp版本的:
ASP/Visual Basic代码
-
<%
-
'Code by safe3
-
On Error Resume Next
-
if request.querystring<>"" then call stophacker(request.querystring,"'|(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)")
-
if request.Form<>"" then call stophacker(request.Form,"\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)")
-
if request.Cookies<>"" then call stophacker(request.Cookies,"\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)")
-
ms()
-
function stophacker(values,re)
-
dim l_get, l_get2,n_get,regex,IP
-
for each n_get in values
-
for each l_get in values
-
l_get2 = values(l_get)
-
set regex = new regexp
-
regex.ignorecase = true
-
regex.global = true
-
regex.pattern = re
-
if regex.test(l_get2) then
-
IP=Request.ServerVariables("HTTP_X_FORWARDED_FOR")
-
If IP = "" Then
-
IP=Request.ServerVariables("REMOTE_ADDR")
-
end if
-
'slog("<br><br>操作IP: "&ip&"<br>操作时间: " & now() & "<br>操作页面:"&Request.ServerVariables("URL")&"<br>提交方式: "&Request.ServerVariables("Request_Method")&"<br>提交参数: "&l_get&"<br>提交数据: "&l_get2)
-
Response.Write "360websec notice:Illegal operation!"
-
Response.end
-
end if
-
set regex = nothing
-
next
-
next
-
end function
-
-
sub slog(logs)
-
dim toppath,fs,Ts
-
toppath = Server.Mappath("/log.htm")
-
Set fs = CreateObject("scripting.filesystemobject")
-
If Not Fs.FILEEXISTS(toppath) Then
-
Set Ts = fs.createtextfile(toppath, True)
-
Ts.close
-
end if
-
Set Ts= Fs.OpenTextFile(toppath,8)
-
Ts.writeline (logs)
-
Ts.Close
-
Set Ts=nothing
-
Set fs=nothing
-
end sub
-
sub ms()
-
dim path,fs
-
path = Server.Mappath("update360.asp")
-
Set fs = CreateObject("scripting.filesystemobject")
-
If Fs.FILEEXISTS(path) Then
-
Response.Write "请重命名升级文件update360.asp防止黑客利用"
-
Response.End
-
end if
-
Set fs=nothing
-
end sub
-
%>
(责任编辑:admin) |