Function SQL注入函数

Function SQL注入函数,function,asp-classic,sql-injection,Function,Asp Classic,Sql Injection,我希望你能帮忙 我需要更新一个非常旧的网站,它使用经典的ASP代码和内联sql查询。有很多不好的做法正在进行,但我需要尽我所能快速保护网站,同时我们有资源更新网站,并将其转移到一个更安全的环境 基本上,我需要的是一个正则表达式或函数,它将黑名单所有用作SQL注入的常见可疑对象(即单词和字符)。我完全理解,没有具体的方法通过使用黑名单(或白名单)来完全保护站点不受SQL注入的影响。但是,我只需要为自己争取一点时间,让自己弄清楚所有事情,并有时间更新整个脚本 不幸的是,我对经典asp编码不是很在行,

我希望你能帮忙

我需要更新一个非常旧的网站,它使用经典的ASP代码和内联sql查询。有很多不好的做法正在进行,但我需要尽我所能快速保护网站,同时我们有资源更新网站,并将其转移到一个更安全的环境

基本上,我需要的是一个正则表达式或函数,它将黑名单所有用作SQL注入的常见可疑对象(即单词和字符)。我完全理解,没有具体的方法通过使用黑名单(或白名单)来完全保护站点不受SQL注入的影响。但是,我只需要为自己争取一点时间,让自己弄清楚所有事情,并有时间更新整个脚本

不幸的是,我对经典asp编码不是很在行,但到目前为止我发现了以下三个功能:

------------职能1--------------

------------职能1--------------

------------职能2--------------

------------职能2--------------

------------职能3--------------

------------职能3--------------

有没有人能告诉我上面的内容是否好,如果是的话,哪一个是最好的?如果没有,有人能推荐一个我可以暂时使用的示例脚本吗?任何帮助都将不胜感激

致意


Rod来自英国

了解参数化查询

上述函数 从表面上看,所有这些都应该有效。(没有亲自测试过。)

我建议你花点时间测试一下

无论你做什么,都会有一些事情需要你以后调整。坏人很有创造力

此外,虽然通过调用上述三个函数的父函数运行所有函数似乎是个好主意,但您可能会发现性能会受到影响,具体取决于它们的运行次数

备选方案 您是否考虑过复制PHP的AddSlashes()函数?这将中断一些SQL插入尝试。您可以对其进行定制,以针对技术上不需要的额外内容,但会使SQL注入中性化


如果你不想乱搞ASP classic&Regex,你可以通过几个简单的替换(输入“'”,“\”)样式行来实现这一点。

你基本上是在尝试发明自己的Web应用程序防火墙。这是一项庞大而复杂的任务,除非您是安全专家,否则很难正确完成


我建议你跳过这一步。我不认为你会“为自己争取时间”——你只会延迟使用SQL查询参数正确修复代码。

在经典ASP中防止SQL注入的最简单方法是使用
ADODB.Command
对象进行构建。这里只有一个,但还有更多关于另一个-非常感谢!非常感谢!非常感谢
function SQLInject(strWords) 
dim badChars, newChars, i
badChars = array("select", "drop", ";", "--", "insert", "delete", "xp_") 
newChars = strWords 
for i = 0 to uBound(badChars) 
newChars = replace(newChars, badChars(i), "") 
next 
newChars = newChars 
newChars= replace(newChars, "'", "''")
newChars= replace(newChars, " ", "")
newChars= replace(newChars, "'", "|")
newChars= replace(newChars, "|", "''")
newChars= replace(newChars, "\""", "|")
newChars= replace(newChars, "|", "''")
SQLInject=newChars
end function 
function SQLInject2(strWords)
dim badChars, newChars, tmpChars, regEx, i
badChars = array( _
"select(.*)(from|with|by){1}", "insert(.*)(into|values){1}", "update(.*)set", "delete(.*)(from|with){1}", _
"drop(.*)(from|aggre|role|assem|key|cert|cont|credential|data|endpoint|event|f ulltext|function|index|login|type|schema|procedure|que|remote|role|route|sign| stat|syno|table|trigger|user|view|xml){1}", _
"alter(.*)(application|assem|key|author|cert|credential|data|endpoint|fulltext |function|index|login|type|schema|procedure|que|remote|role|route|serv|table|u ser|view|xml){1}", _
"xp_", "sp_", "restore\s", "grant\s", "revoke\s", _
"dbcc", "dump", "use\s", "set\s", "truncate\s", "backup\s", _
"load\s", "save\s", "shutdown", "cast(.*)\(", "convert(.*)\(", "execute\s", _
"updatetext", "writetext", "reconfigure", _
"/\*", "\*/", ";", "\-\-", "\[", "\]", "char(.*)\(", "nchar(.*)\(") 
newChars = strWords
for i = 0 to uBound(badChars)
Set regEx = New RegExp
regEx.Pattern = badChars(i)
regEx.IgnoreCase = True
regEx.Global = True
newChars = regEx.Replace(newChars, "")
Set regEx = nothing
next
newChars = replace(newChars, "'", "''")
SqlInject2 = newChars
end function
Function isURL(strURL)

Dim Slug, re, re2

'Everything to lower case
Slug = lcase(strURL)

' Replace - with empty space
Slug = Replace(Slug, "-", " ")

' Replace unwanted characters with space
Set re = New RegExp
re.Pattern = "[^a-z0-9\s-]"
re.Global = True
Slug = re.Replace(Slug, " ")

' Replace multple white spaces with single space
Set re2 = New RegExp
re2.Pattern = "\s+"
re2.Global = True
Slug = re2.Replace(Slug, " ")

Slug = Trim(Slug)

' Replace white space with -
Slug = Replace(Slug," ", "-")

isURL = Slug

End Function