SQL注入预防

Jas*_*sky 4 mysql sql sql-injection asp-classic

我目前正在开发一个传统的ASP项目,其中安全性现在已成为一个大问题.它不仅是不安全的加密方法(md5),而且我担心SQL注入问题.我对注射效果还不是很好,而且我只尝试过我所知道的基础知识.我发现了"保护"任何用户输入的功能,但我想知道它是否真的做了什么来防止注入攻击.这是功能:

function sqlfix(input)
    if not isnull(input) and input <> "" then
        input = replace(input, ";", "&#59;")
        input = replace(input, "'", "&#39;")
        input = replace(input, """", "&#34;")
        input = replace(input, "(", "&#40;")
        input = replace(input, ")", "&#41;")
        input = replace(input, "|", "&#124;")
        input = replace(input, "<", "&#60;")
        input = replace(input, ">", "&#62;")
        input = replace(input , "'", "''")
        'input = Server.HTMLEncode(input)
        'input = Server.UrlEncode(input)
        sqlfix = input
    else
        sqlfix = ""
    end if
end function
Run Code Online (Sandbox Code Playgroud)

我记得在很多年前我第一次使用mysql_*函数启动PHP时做了类似的事情,但现在我已经转向了PDO和参数绑定.但是我不知道这对ASP应用程序有多安全.感谢您的任何意见.

Bil*_*win 6

不要陷入弦插值陷阱!这不安全.

即使在ASP Classic中,您也可以使用真正的SQL查询参数.

我不是ASP程序员,但我发现这个博客有一个明确的例子,即使用ADODB.Command对象进行参数化SQL查询,并在执行前将值绑定到参数.

http://securestate.blogspot.com/2008/09/classic-asp-sql-injection-prevention_30.html

有关使用命名参数的更多示例,请参阅此SO问题:

参数化查询中的ASP经典命名参数:必须声明标量变量