Username: Password:

该文档能够包含在任何需要调用数据库的ASP文档头部,直接过虑掉非法注入-ASP教程,ASP应用
来源:作者: 发布时间:2007-12-26 02:05:10

<%该文档能够包含在任何需要调用数据库的asp文档头部,直接过虑掉非法注入
调用方法为:
function safe(str)该函数用来判断传递过来的变量是否包含特别字符,没有返回true
dim s_badstr, n, i
s_badstr = "  &<>?%,;:()`~!@#$^*{}[]|\/+-="&chr(34)&chr(9)&chr(32)
n = len(s_badstr)
safe = true
for i = 1 to n
if instr(str, mid(s_badstr, i, 1)) > 0 then
safe = false
exit function
end if
next
end function
以下代码直接判断发生请求的url是否包含非法字符
on error resume next
dim strtemp

if lcase(request.servervariables("https")) = "off" then
strtemp = "http://"
else
strtemp = "https://"
end if
strtemp = strtemp & request.servervariables("server_name")
if request.servervariables("server_port") <> 80 then strtemp = strtemp & ":" & request.servervariables("server_port")
strtemp = strtemp & request.servervariables("url")
if trim(request.querystring) <> "" then strtemp = strtemp & "?" & trim(request.querystring)
strtemp = lcase(strtemp)
if instr(strtemp,"select%20") or instr(strtemp,"insert%20") or instr(strtemp,"delete%20from") or instr(strtemp,"count(") or instr(strtemp,"drop%20table") or instr(strtemp,"update%20") or instr(strtemp,"truncate%20") or instr(strtemp,"asc(") or instr(strtemp,"mid(") or instr(strtemp,"char(") or instr(strtemp,"xp_cmdshell") or instr(strtemp,"exec%20master") or instr(strtemp,"net%20localgroup%20administrators") or instr(strtemp,"db_name(") or instr(strtemp,"net%20user") or instr(strtemp,"") or instr(strtemp,"%20or") or instr(strtemp,"backup%20") then
response.write ""
end if

for each name in request.form
dim s_badstr, s_sz, i
s_badstr = "|and|select|update|chr|delete|from|;|insert|mid|master.|truncate|db_name|xp_cmdshell|exec%20master|net%20localgroup%20administrators|drop|table|db_name(|exec"
s_sz = split(s_badstr,"|")
for i = 0 to ubound(s_sz)
if instr(request.form(name), s_sz(i)) > 0 then
response.write ""
end if
next
next
%>


喜欢本文,那就收藏到:

    Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪ViVi 365Key网摘 天极网摘 和讯网摘 博拉网 POCO网摘 添加到饭否 QQ书签 Digbuzz我挖网
相关评论  我也要评论
还没有关于此文章的相关评论!
  • 昵称: (为空则显示guest)
  • 评论分数: ★ ★ ★★★ ★★★★ ★★★★★
  • 评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
  • 导航
    赞助商
    文章类别
    订阅