Asp注入:经典ASPSQL注入保护

关于Asp注入的问题,在asp for protection中经常遇到, 什么是一个强大的方式来防止 SQL 注入一个经典的 ASP 应用程序?

什么是一个强大的方式来防止 SQL 注入一个经典的 ASP 应用程序?

FYI 我使用它与访问数据库。(我没有写应用程序)

28

存储过程和 / 或准备好的报表:

https://stackoverflow.com/questions/1973/what-is-the-best-way-to-avoid-sql-injection-attacks Can I protect against SQL Injection by escaping single-quote and surrounding user input with single-quotes? Catching SQL Injection and other Malicious Web Requests

使用 Access DB,你仍然可以做到这一点,但如果你已经担心 SQL 注入,我认为你需要关闭 Access。

以下是 Access 中的技术链接:

http://www.asp101.com/samples/storedqueries.asp

请注意,通常防止注入的不是存储过程本身,而是它是参数化的而不是动态的。请记住,即使构建动态代码的 SP 如果以某些方式使用参数来构建动态代码,也容易受到注入的影响。总的来说,我更喜欢 SP,因为它们形成了应用程序进入数据库的接口层,因此应用程序甚至不允许首先执行任意代码。

此外,如果您不使用命令和参数,则存储过程的执行点可能容易受到攻击,例如,这仍然是易受攻击的,因为它是动态构建的,并且可以是注入目标:

Conn.Execute("EXEC usp_ImOnlySafeIfYouCallMeRight '" + param1 + "', '" + param2 + "'") ;

请记住,您的数据库需要保护自己的边界,并且如果各种登录名都有权访问表中的INSERT/UPDATE/DELETE,则这些应用程序(或受损应用程序)中的任何代码都可能成为潜在问题。如果登录名仅具有执行存储过程的权限,则这将形成一个漏斗,您可以通过该漏斗更轻松地确保正确的行为。(类似于 OO 概念,其中对象负责其接口,并且不公开其所有

12

是一对夫妇的 sqlinject 脚本我做了很久以前一个简单的版本和扩展版本:

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
4

使用参数化查询,你需要创建一个命令对象,为它分配一个名称和一个值的参数,如果你这样做,你不需要担心其他任何事情(指的是 SQL 注入当然;)

http://prepared-statement.blogspot.com/2006/02/asp-prepared-statements.html

而且不要信任存储过程,如果您不使用准备好的语句,它们也可能成为攻击向量。

4

“一个强大的方法来防止 SQL 注入的一个经典的 ASP 应用程序”是无情的验证所有输入.

单独的存储过程和 / 或不同的数据库系统不一定等于良好的安全性。

MS 最近推出了一个 SQL 注入检查工具,用于查找查询中使用的未经验证的输入。

以下是链接:The Microsoft Source Code Analyzer for SQL Injection tool is available to find SQL injection vulnerabilities in ASP code

本站系公益性非盈利分享网址,本文来自用户投稿,不代表码文网立场,如若转载,请注明出处

(545)
Web开发后台开发:Android平板电脑上的Web开发-没有开发工具
上一篇
NTP服务器:将RaspberryPi3设置为NTP服务器(不使用外部NTP服务器)
下一篇

相关推荐

发表评论

登录 后才能评论

评论列表(26条)