还继续回到我们的主题," 脚本期望的输入变量是数字变量 (ID)".怎样进行注入防范,天呐,方法太多了,最直接的就是判断是否是数字整型,还有一些比较个性的验证办法,我们一一介绍一下 如:程序体(8)
一,判断数字是否是整型
p_lngID = CLng(Request("ID"))
二 取字长 这一点我相信一般的数据长度不会大于8位所以:
If len(ID)>8 then
response.write "bedpost"
response end
end if
三 我认为这是一种比较冒险的办法,就是再进行一次数据库的查询,如果数据库表内没有相同的值与之相同那么返回错误.
sql = "Select NAME FROM Category where ID="&ID
set temp=conn.Execute(SQL)
if temp.bof or temp.eof then
response.Redirect("index.asp")
else
cat_name=temp("name")
end if
set temp=nothing
‘上面的是数据ID 的检测,下面则是正式的查询
sql = "Select ID T_ID, NAME FROM Category where ID="&ID&" orDER BY xh asc"
rs.open sql,conn,1,1
四,我自己常用的数据过滤脚本,专利,呵~
id=replace(id,"'","")
If len( request("id"))>8 then ‘ 为什么取长度上面程序中已经说明
response.write "<script language=""****"">"
response.write "parent.alert('老大,你说吧,你想干什么?..');"
response.write "history.back();"
response.write "</script>"
response.end
else
If request("id")<>"" then ‘取不为空则是为了防止一些程序页中会出现空值情况,如果不在这里做判断,程序会校验出错.
If IsNumeric(request("id"))=False then ' 风清扬修改 ID数据监控程式
response.write "<script language=""****"">"
response.write "parent.alert('错误的数据编号类型\n\n请返回校验');"
response.write "history.back();"
response.write "</script>"
response.end
end if
end if
end if
程序体(8)
由于我个人的编程习惯,我喜欢将所有的数据检验程序全部保留到整站的公用程序中,比如:conn.asp啦,只需要写一次就可以修复全站的问题.
说到这里,我提一点关于攻击的问题,就是跑用户密码或者是用户名,一般常用的就是
....../show.asp?id=1 and 0<>(select count(*) from admin where id=3 and left(username,1)='a')
这样去一个一个尝试,当然我们不能在这里提什么Perl程序去跑密码,程序是别人写,要自己知道原理.这里我只是想给个比较方便的办法就是取ASC码范围.这个要比单独跑要快很多.不论是是字母,数字,汉字,特殊字符,他们总会有对应的ASC码,用以下办法:
....../show.asp?id=1 and 0<>(select count(*) from admin where id=3 and asc(right(left(username
e,3),1)) between 1 and 10000) 剩下的就随你了,一般的从97到122就可以啦,字母嘛,很快D.呵呵,有人想用mid 函数当然也是不错 asc(mid(username,2,1)) between 1 and 10000 也成.
如何更加有效的防止SQL注入攻击?我们将在下面的文章中具体提到!
上一页 [1] [2] [3] [4] [5] 下一页