在我的工作中有一个经典的 ASP 应用程序(我相信)极易受到 SQL 注入的攻击。我想向管理层证明这段代码不安全,但我所能做的就是在数据库中插入“SQLINJ”日志记录:
Public function preventSQLInjection(lstr)
BlackList = Array("--", ";", "'", "/*", "*/", "@@", "@",_
"alter ", "begin ", "create ", "cursor ",_
"declare ", "delete ", "drop ", " end", "exec ",_
"execute ", "fetch ", "insert ", "kill ", "open ",_
"select ", "sysobjects", "syscolumns",_
"table ", "update ", "=")
preventSQLInjection = lstr
For Each s in BlackList
If ( InStr (lstr, s) <> 0 ) Then
execSqlQuery "INSERT INTO AccesLogs (datetime,ip,action,comments) VALUES ('" & formatDate(date) & " " & formatTime(time) & "','" & request.ServerVariables("REMOTE_ADDR") & "','SQLINJ','" & replace(lstr,"'","''") & "')",connectionstring
preventSQLInjection = "DONOTUSEIT"
exit for
End If
Next
end function
据我了解,最简单的攻击将是对AccessLogs表本身的攻击,因为replace(lstr,"'","''")它会“清理”SQL 注入尝试并记录它。
我知道应该放弃这段代码,所有可执行的 SQL 都应该使用实际的命令和参数执行——我非常讨厌串联的字符串。
我想向管理层展示该页面非常易受攻击,例如sysobjects被列入黑名单,但不是sys.objects这样,如果我可以注入可执行 SQL,则必须能够毫不费力地获取整个数据库的架构。
username比如说,页面上的andpassword字段怎么能打败这个功能login.asp呢?或者我是在编造这一切,而这段代码是完全安全的?