2005-12-17 12:38:00 by: h4x0r

Asp系列安全函数

Font Size: Large | Medium | Small
使用asp制作网页时,要保证网站安全,页面不被用户录入的信息破坏。
下列是在非常代码网中使用的函数。

Function GetSQL(s_Value)
'作用:得到安全的SQL语句
'使用:通常我们在使用SQL语句时都只有一条运行,但是黑客们可以将他要执行的语句放在我们的语句后面,SQL Server 允许多语句运行,将导致信息被更改。
'例子:select * from user ;delete from user '使用该函数后,后面的删除语句将无法执行。

dim s_con,s_In
s_In=s_Value
s_con=split(s_Value,";") '去掉 ;
s_In=s_con(0)
s_con=split(s_In,vbcrlf) '去掉 回车
s_In=s_con(0)
s_con=split(s_In," go ", -1, 1) '去掉 go
s_In=s_con(0)

GetSQL=s_In
'Response.Write s_IN
End Function

Function GetSafeInput(s_Value)
'作用:查询录入安全 将 '替换为 ''
'使用:在登录、查询时,需要把用户输入的信息加入SQL语句,该还是避免黑客从这里入侵。
'例子: s_SQL="select name from user where name='" & GetSafeInput(request("Name')) & "'"

GetSafeInput=Replace(s_Value,"'","''")
End Function

Function GetArea(s_Value)
'作用:将<textarea>录入正确显示
'使用:在<textarea>中,不能再出现</ textarea>,否则页面就会变的很难看。
'例子:<textarea><%=GetArea(txtInfo)%></ textarea>

dim s_ret
s_ret=Replace(s_Value,"</ textarea>","</ textarea>",1,-1,1)
GetArea=s_ret

End Function

Function GetInput(s_Value)
'作用:将HTML属性录入正确显示
'使用:在HTML属性赋值是,是包括在引号里面的,如果值里再出现引号,页面就会变形。
'例子:<input value="<%=GetInput(txtValue)%>">

GetInput=trim(Replace(s_Value,"""","'"))
End Function

Function GetID(l_ID)
'作用:强制转换类型.
'使用:在页面处理中经常有从页面得到参数 判断执行的 ,使用该函数可以避免非正常的错误。
'例子: s_SQL='select name from user where id=' & getid(request("ID"))

On Error Resume Next
'处理ID
dim l_ret
l_ret=clng(l_ID)
if err.Number<>0 then
GetID=0
else
GetID=l_ret
end if
err.Clear
End Function
Comments Feed Comments Feed: http://www.4evil.org/feed.asp?q=comment&id=379

There is no comment on this article.

Post Comment
Smilies
[smile] [confused] [cool] [cry]
[eek] [angry] [wink] [sweat]
[lol] [stun] [razz] [redface]
[rolleyes] [sad] [yes] [no]
[heart] [star] [music] [idea]
Enable UBB Codes
Auto Convert URL
Show Smilies
Hidden Comment
Username:   Password:   Register Now?
Security Code * Please Enter the Security Code