我的办法是 ON ERROR RESUME NEXT Err.Clearconn.execute("select * from A where " + Condition) '错误的SQL if Err.Code <> 0 then response.write "错误的SQL" '错误SQL的处理 else response.write "正确的SQL" '证明SQL是正确的。 end if Err.Clear
也许可以用括号将每个条件引起来。 如:select * from class where ((ID= ' ' ) AND (pwd= )) 这样的情况,如果输入' or '1'='1就会变成 select * from class where ((ID= '' or '1'='1') AND (pwd= ) ) 另外如果输入';exec sp_... select * from class where ((ID= '';exec sp_...) AND (pwd= )) 因此,导致括号匹配不完整,可以防止恶意的破坏。 这种方法就有一定的效果。
如果你不把字符串中的“'”再加一个“'”的话,又让别人知道你的语句的话,他甚至可以删表比如你的语句: conn.execute("select * from A where " + Condition) 如果用 Condition =“1=1 drop table A”作参数, 你害怕吗比如你的语句: conn.execute("select * from A where A.Field1='" + Condition+"'")
如果用 Condition =“a' and 1=1 drop table A select * from A where A.Field1='”作参数, 你害怕吗
后果大家说了很多了,我只是建议你把单引号replace()掉,不然很不健壮的!
insert into table values(?,?,?) If u know what's this and how to use, u should know what i'm talking about.:)
在用户名中输入aaa' or '1=1' 等等,没有研究头,总之赶快屏蔽,不然就会被黑
to tripofdream :
会有那么危险吗???什么网站有介绍??
http://211.101.228.186/expert/topic/251/251405.shtm
另外还要屏蔽的符号有\/%<>等。其实屏蔽的方法很简单,在单引号之前再加一个单引号就可以了。其他的可以用转义字符来表示。
能不能谈谈为什么连空格逗号都要屏蔽掉?
to all:
马上给分。
ON ERROR RESUME NEXT
Err.Clearconn.execute("select * from A where " + Condition) '错误的SQL
if Err.Code <> 0 then
response.write "错误的SQL"
'错误SQL的处理
else
response.write "正确的SQL"
'证明SQL是正确的。
end if
Err.Clear
如:select * from class where ((ID= ' ' ) AND (pwd= ))
这样的情况,如果输入' or '1'='1就会变成
select * from class where ((ID= '' or '1'='1') AND (pwd= ) )
另外如果输入';exec sp_...
select * from class where ((ID= '';exec sp_...) AND (pwd= ))
因此,导致括号匹配不完整,可以防止恶意的破坏。
这种方法就有一定的效果。
conn.execute("select * from A where " + Condition) 如果用 Condition =“1=1 drop table A”作参数,
你害怕吗比如你的语句:
conn.execute("select * from A where A.Field1='" + Condition+"'")
如果用 Condition =“a' and 1=1 drop table A select * from A where A.Field1='”作参数,
你害怕吗
If u know what's this and how to use, u should know what i'm talking about.:)