There's a Classic ASP application at my job that is (I believe) highly vulnerable to SQL injection. I want to prove to management that this code isn't secure, but all I'm able to do is insert "SQLINJ" log records in the database:
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
From my understanding the easiest attack would be on the AccessLogs
table itself, because of replace(lstr,"'","''")
which "sanitizes" the SQL-Injection attempt and logs it.
I KNOW that this code should be ditched and all executable SQL should be executed with actual commands and parameters - I hate concatenated strings with a passion.
I want to demonstrate management that the page is very vulnerable, like, sysobjects
is blacklisted, but not sys.objects
so if I can inject executable SQL it must be possible to get then entire database's schema without sweating.
How can this function be defeated from, say, the username
and password
fields on the login.asp
page? Or am I making this all up and this code is perfectly secure?