当前位置:首页 > 软件开发 > net
firefox

预防SQL注入漏洞函数

仅仅代表我的观点.不怕见笑.有问题请大家指教!我想如果你是牛人,那这个已经不是值得你看的内容,只是觉得对与很多刚入门的asp程序员来说还是有点实际意义,所以不怕被大家笑话,写了贴在这里!

----<%
function checkstr(str)

if isnull(str) then

checkstr = ""

exit function

end if

checkstr=replace(str," ","")

checkstr=replace(str,"'","'")

checkstr=replace(str,";","'")

checkstr=replace(str,"--","'")

checkstr=replace(str,"(","'")

checkstr=replace(str,"[","'")

checkstr=replace(str,"$","'")

end function

%>


相关函数
left(string, length)
返回指定数目的从字符串的左边算起的字符

asc(string)
返回与字符串的第一个字母对应的 ansi 字符代码。

mid(string, start[, length])
从字符串中返回指定数目的字符。

***********************************
我自己的做法是把字符串限定在8个字符内,呵!(千万条数据啊,没谁有这样大的记录吧?99,999,999呵!不够用,才怪了!除非你的数据从来不更新删出,那也没办法,问题是sql到了这样的时会是怎么样的速度)


---<%
if len(request.querystring("ddd"))> 8 then
response.write(黑我啊,不要了。少来)
response.end '最好有这句

'''初步是判断是否是数字=======isnumeric 函数
if isnumeric(request.querystring("ddd")) then

execute("select * from [table]")

....

else

response.write(黑我啊,不要了。少来)
response.end '最好有这句

%>

当然了,加上上面的函数,在你的sql过程里,效果就非常完美了!

呵!!!在变态点做个函数。

---<%
function checkstr(str)

if isnull(str) then

checkstr = ""

exit function

end if

checkstr=replace(str," ","")

checkstr=replace(str,"'","'")

checkstr=replace(str,";","'")

checkstr=replace(str,"--","'")

checkstr=replace(str,"(","'")

checkstr=replace(str,"[","'")

checkstr=replace(str,"$","'")

checkstr=replace(str,"asc'," ")

checkstr=replace(str,"mid"," ")

checkstr=replace(str,"delete"," ")

checkstr=replace(str,"drop"," ")

'''呵!!我这里没屏蔽select,count,哈!想起来我就笑,太变态了,那其不是我什么都不用了不是更更安全啊!!!呵!!~^)^~
end function

%>


足够了,这个函数加载到sql选取记录集的地方。
如:rsql="select * from table where xxx="&checkstr(request.querystring("xxyy"))&""
或者来就判断字符串

说的有点林乱,但是就是这些了,对于普通的“黑客”已经足够他毫些时间了。但是对于老到的真正意义的黑客,这些都不是万能的东西,人家连服务器都黑,你能怎么样啊?嘿!!

看了些资料,结合自己的经验,写在这里。算是自己复习一下,看到的朋友也可以一起交流!qq:22979784(加的请说明这篇文章的地址,怕扰啊!多多见谅了!)

另外对于sql注入漏洞,好象只是asp里多些!其它的我还不是太清楚,所以还是需要提醒所有搞asp的朋友,请多看看,微软的最新【windows 脚本技术】这个东西。
http://download.microsoft.com/download/winscript56/install/5.6/w982kme/cn/scd56chs.exe
这里下,就可以了!

 ↓相关文章:
© 2006-2008 All Rights Reserved