新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论.NET,C#,ASP,VB技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区计算机技术与应用『 Dot NET,C#,ASP,VB 』 → ASP函数过滤的几种方法 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 3942 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: ASP函数过滤的几种方法 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     Coral 美女呀,离线,快来找我吧!
      
      
      威望:6
      等级:计算机学士学位(超级版主)
      文章:271
      积分:2320
      门派:XML.ORG.CN
      注册:2004/12/29

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给Coral发送一个短消息 把Coral加入好友 查看Coral的个人资料 搜索Coral在『 Dot NET,C#,ASP,VB 』的所有贴子 引用回复这个贴子 回复这个贴子 查看Coral的博客楼主
    发贴心情 ASP函数过滤的几种方法

    转自: 中国站长贴吧   sungla(maomao) 发表于1-28 10:42


    1.数字型变量:用isNumeric()判断是否为数字
    2.字符型或其它类型变量:将单引号'替换成两个
    下面给出两个函数,用来代替ASP的Request函数,只要每处地方使用这两个函数取值,SQL注入根本没有用武之地.

    '----------------------------------------------------------------
    ' 获取数字型参数
    '----------------------------------------------------------------
    Function ReqNum ( StrName )
    ReqNum = Request ( StrName )
    if not isNumeric ( ReqNum ) then
      response.write "参数必须为数字型!"
      response.end
    end if
    End Function

    '----------------------------------------------------------------
    ' 获取字符型参数
    '----------------------------------------------------------------
    Function ReqStr ( StrName )
    ReqStr = Replace ( Request(StrName),"'","‘")
    End Function

    **************************************************
    '函数名:killbad(苛刻检验)
    '作 用:过滤非法的SQL字符
    '参 数:strChar-----要过滤的字符
    '返回值:过滤后的字符
    '**************************************************
    function killbad(strChar)
    if strChar="" then
    killbad=""
    else
    killbad=replace(replace(replace(replace(replace(replace(replace(replace(strChar,"'","’"),"*","×"),"?","?"),"(","("),")",")"),"<","〈"),".","。"),";",";")
    end if
    end function

    '**************************************************
    '函数名:kickbad(一般检验)
    '作 用:过滤非法的SQL字符
    '参 数:strChar-----要过滤的字符
    '返回值:过滤后的字符
    '**************************************************
    function kickbad(strChar)
    if strChar="" then
    kickbad=""
    else
    kickbad=replace(replace(replace(replace(replace(replace(replace(strChar,"'","’"),"*","×"),"?","?"),"(","("),")",")"),"<","〈"),";",";")
    end if
    end function

    <%
    ' 检查非法*
    dim qs,errc,i
    qs=request.servervariables("query_string")
    dim nothis(18)
    nothis(0)="net user"
    nothis(1)="xp_cmdshell"
    nothis(2)="/add"
    nothis(3)="exec%20master.dbo.xp_cmdshell"
    nothis(4)="net localgroup administrators"
    nothis(5)="select"
    nothis(6)="count"
    nothis(7)="asc"
    nothis(8)="char"
    nothis(9)="mid"
    nothis(10)="'"
    nothis(11)=":"
    nothis(12)=""""
    nothis(13)="insert"
    nothis(14)="delete"
    nothis(15)="drop"
    nothis(16)="truncate"
    nothis(17)="from"
    nothis(18)="%"
    errc=false
    for i= 0 to ubound(nothis)
    if instr(qs,nothis(i))<>0 then
    errc=true
    end if
    next
    if errc then
    response.write "<script language=""javascript"">"
    response.write "parent.alert('很抱歉!你的*作不被允许,请查看您是不是输错了?!确定后将直接转向首页..');"
    response.write "self.location.href='index.asp';"
    response.write "</script>"
    response.end
    end if

    %>


    <%

    function killbad(strchar)

    if strchar="" then

    killbad=""

    else

    killbad=replace(strchar,"'","‘")

    killbad=replace(strchar,";",";")

    killbad=replace(strchar,",",",")

    killbad=replace(strchar,"?","?")

    killbad=replace(strchar,"<","<")

    killbad=replace(strchar,">",">")

    killbad=replace(strchar,"(","(")

    killbad=replace(strchar,")",")")

    killbad=replace(strchar,"@","@")

    killbad=replace(strchar,"=","=")

    killbad=replace(strchar,"+","+")

    killbad=replace(strchar,"*","*")

    killbad=replace(strchar,"&","&")

    killbad=replace(strchar,"#","#")

    killbad=replace(strchar,"%","%")

    killbad=replace(strchar,"$","¥")

    end if

    end function

    %>

    每页都调用,然后在需要验证的地方加上killbad


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/2/1 13:47:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 Dot NET,C#,ASP,VB 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/12 14:54:26

    本主题贴数1,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    46.875ms