过滤网址的非法字符串

上一篇 / 下一篇  2007-08-21 12:04:13 / 个人分类:ASP

51Testing软件测试网f `E a}

第一种:51Testing软件测试网:\,Zk` \Y5n
squery=lcase(Request.ServerVariables("QUERY_STRING"))51Testing软件测试网Q!WD%?-`{#R
sURL=lcase(Request.ServerVariables("HTTP_HOST"))
S1@Y$Z1h6a^051Testing软件测试网5s%A.W${Uj!]*A#{
SQL_injdata =":|;|>|<|--|sp_|xp_|\|dir|cmd|^|(|)|+|$|'|copy|format|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare"51Testing软件测试网@Z f)\Do#xi
51Testing软件测试网v`4x&Jq9Q0q@
SQL_inj = split(SQL_Injdata,"|")
a;J/]Q [051Testing软件测试网'M f5T8o$l
For SQL_Data=0 To Ubound(SQL_inj)
-B sy h(r0aVB7o+s0if instr(squery&sURL,Sql_Inj(Sql_DATA))>0 Then
k}!L^qa9b0Response.Write "SQL通用防注入系统"51Testing软件测试网 ^ E [4hu)t
Response.end
!XH-iI[;t:P?5Osy0end if51Testing软件测试网2c EJa h_+e
next
$Ld8| a Ae Qg{051Testing软件测试网] pgF T` k`

51Testing软件测试网a o.`&Z&h v&Hb^

第二种:
G(M {d#X)a,N0SQL_injdata =":|;|>|<|--|sp_|xp_|\|dir|cmd|^|(|)|+|$|'|copy|format|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare"51Testing软件测试网h9mwR%Cr$f

+k:U_4@1w,OD0SQL_inj = split(SQL_Injdata,"|")51Testing软件测试网7oR"HC)EGv
51Testing软件测试网Fi)T2|Ud
If Request.QueryString<>"" Then
/z#C q4jeUHS}0For Each SQL_Get In Request.QueryString51Testing软件测试网 I#K5y7cM5R
For SQL_Data=0 To Ubound(SQL_inj)51Testing软件测试网 q|QM7?"O8bO9_|
if instr(Request.QueryString(SQL_Get),Sql_Inj(Sql_DATA))>0 Then51Testing软件测试网l)ZA~,\ V n
Response.Write "SQL通用防注入系统"
g$sTH'j S;b0Response.end51Testing软件测试网@2^ j}/yM
end if51Testing软件测试网V9v'R M@P)X
next
.b.xy+F6[J b SP0Next
n1_`/?/B/j_0End If
r'L m'[ ZRF'M9Y0
9waT n\d0If Request.Form<>"" Then51Testing软件测试网7{p6A7_6T(y
For Each Sql_Post In Request.Form51Testing软件测试网|YG[G|9WU [.]S
For SQL_Data=0 To Ubound(SQL_inj)
M8|f+rG0if instr(Request.Form(Sql_Post),Sql_Inj(Sql_DATA))>0 Then51Testing软件测试网 _+STxy4wWc)E'PC
Response.Write "SQL通用防注入系统"
Qfv,xz `"x0Response.end51Testing软件测试网+E:W8t(v L{Ep
end if
4p%F@{f|@V0next51Testing软件测试网 }},r4PR4T
next51Testing软件测试网(mz"|d%d-Z
end if
i*O7FZ*IE"@051Testing软件测试网mGq ui"e4`Jq
第三种51Testing软件测试网{Zhi.I t'q
<%
h?a'Mn?*H0'--------定义部分------------------51Testing软件测试网 dZ+?+t xGq*y:ZB
Dim Str_Post,Str_Get,Str_In,Str_Inf,Str_Xh,Str_db,Str_dbstr
,F6|N.[2GQ-BO0'自定义需要过滤的字串,用 "■"分离51Testing软件测试网)Xg+G!VH w!m6OJ u
Str_In = "'■;■and■exec■insert■select■delete■update■count■*■%■chr■mid■master■truncate■char■declare"51Testing软件测试网,V2`{r1A9JSh
'----------------------------------
&yjD w,e9mX$DF8}0%>51Testing软件测试网T}-I R C
51Testing软件测试网DX)I1d9w$z.a
<%51Testing软件测试网2Nf}Rza9F7s8]%o
Str_Inf = split(Str_In,"■")
1UB4VIGbPn0'--------POST部份------------------51Testing软件测试网'pex%hkoq5l4\
If Request.Form<>"" Then
n\ UkR [3au/|(F0For Each Str_Post In Request.Form
jzn s"Z(F3t0
%S+qL wg0For Str_Xh=0 To Ubound(Str_Inf)51Testing软件测试网R7~P8xT6d
If Instr(LCase(Request.Form(Str_Post)),Str_Inf(Str_Xh))<>0 Then
#Y&iD%vK }0d6n*LS!o0'--------写入数据库----------头-----51Testing软件测试网v+NrB @P
Str_dbstr="DBQ="+server.mappath("SqlIn.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
?PpjG~w!TW S,^,DL0Set Str_db=Server.CreateObject("ADODB.CONNECTION")51Testing软件测试网9Y.w+ulCg f
Str_db.open Str_dbstr51Testing软件测试网C0[ n fW4sk F*X4MQ
Str_db.Execute("insert into SqlIn(Sqlin_IP,SqlIn_Web,SqlIn_FS,SqlIn_CS,SqlIn_SJ) values('"&Request.ServerVariables("REMOTE_ADDR")&"','"&Request.ServerVariables("URL")&"','POST','"&Str_Post&"','"&replace(Request.Form(Str_Post),"'","''")&"')")
!wv Z$g+l#SeK'\ D0Str_db.close
-?U8bzg!abTl0Set Str_db = Nothing51Testing软件测试网 yRP ^o7c q y8]/U{
'--------写入数据库----------尾-----
z@R Qd6V0Response.Write "<scrīpt Language=Javascrīpt>alert('请不要在参数中包含非法字符尝试注入!');</scrīpt>"
yQ}!Y#l+Q"d0Response.Write "非法操作!系统做了如下记录:<br>"
~e6e k/i0Response.Write "操作IP:"&Request.ServerVariables("REMOTE_ADDR")&"<br>"
E&a2D hqHA4DQ0Response.Write "操作时间:"&Now&"<br>"
0IAR"a'h'tR3k;h2~]0Response.Write "操作页面:"&Request.ServerVariables("URL")&"<br>"51Testing软件测试网9b Nm:cT*Gl`l
Response.Write "提交方式:POST<br>"51Testing软件测试网Yb-|1lg K
Response.Write "提交参数:"&Str_Post&"<br>"51Testing软件测试网E0q4\c+s8k y,RD
Response.Write "提交数据:"&Request.Form(Str_Post)
!}.}1h"seZ*F:w0Response.End51Testing软件测试网l,l7e"^N!d9O.m
End If51Testing软件测试网 kr+m7L9J/n;[g
Next51Testing软件测试网({m$XU k

l!a"P h$]C\0Next
4K3t0H(])lL0End If
%s2d {?8z0'----------------------------------51Testing软件测试网+\&ZU j(M)@9f8D
51Testing软件测试网V3S x"k!^$fM
'--------GET部份-------------------51Testing软件测试网&sSV5Pv)CH*f
If Request.QueryString<>"" Then
#E$G(g}$}\#RU,k0For Each Str_Get In Request.QueryString
y i1Cfe)V(`gt0zm051Testing软件测试网'p^,Z-{hU
For Str_Xh=0 To Ubound(Str_Inf)
&@nQ3xv0If Instr(LCase(Request.QueryString(Str_Get)),Str_Inf(Str_Xh))<>0 Then
Yx Qh ^+|Ze0'--------写入数据库----------头-----
+Rv3];t"F0Str_dbstr="DBQ="+server.mappath("SqlIn.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"51Testing软件测试网2TN6r GX9_ cG
Set Str_db=Server.CreateObject("ADODB.CONNECTION")
3K.B ` fp0Str_db.open Str_dbstr51Testing软件测试网$_9g'{2oEy9s?7v/`
Str_db.Execute("insert into SqlIn(Sqlin_IP,SqlIn_Web,SqlIn_FS,SqlIn_CS,SqlIn_SJ) values('"&Request.ServerVariables("REMOTE_ADDR")&"','"&Request.ServerVariables("URL")&"','GET','"&Str_Get&"','"&replace(Request.QueryString(Str_Get),"'","''")&"')")51Testing软件测试网PcOr[E
Str_db.close51Testing软件测试网I_^/CK7n)Z|
Set Str_db = Nothing
U[P9{7}Fj7]'j0'--------写入数据库----------尾-----51Testing软件测试网(bH*m;D:s.U
51Testing软件测试网+O y,YD,PM Y
Response.Write "<scrīpt Language=Javascrīpt>alert('请不要在参数中包含非法字符尝试注入!);</scrīpt>"51Testing软件测试网PHft!P
Response.Write "非法操作!系统做了如下记录:<br>"51Testing软件测试网'`(_"yh6@-f
Response.Write "操作IP:"&Request.ServerVariables("REMOTE_ADDR")&"<br>"
$@L"H"GB l%]0Response.Write "操作时间:"&Now&"<br>"
G+C%Z;z-N&Fs'[0Response.Write "操作页面:"&Request.ServerVariables("URL")&"<br>"
-B/qN;w0U7lz0Response.Write "提交方式:GET<br>"
3K+dMu-G^2q0Response.Write "提交参数:"&Str_Get&"<br>"51Testing软件测试网7wG9_I&O:O j1d!~
Response.Write "提交数据:"&Request.QueryString(Str_Get)
Ed'q _vn6WT0Response.End
Ijt uj!tU!A0End If
ia PI!o0Next
{(Efi ~:M5E]0Next
0x ZcE*hZg8a$h0End If51Testing软件测试网6Y'?.to0is
%>
G"~}xM7E0第3中方法需要你自己建个数据库51Testing软件测试网%J:Xf/H3v[


TAG: ASP

 

评分:0

我来说两句

Open Toolbar