I’m working with SQL Server 2005 and Windows Server 2000 and wonder if there are any ‘automated’ ways of blocking SQL Injection attacks while I shore up my code.
Some have suggested that there are ways to:
- Put in some kind of ISAPI or HTTP module that filters request post and querystrings for injection-oriented symbols and fails the request before it even hits the application. Most of these solutions specific IIS 6 or higher. I’m running 5.
- Guarantee that each command object runs only a single SQL command at a time.
Any other ideas for my configuration?
When I had a bunch of injection attack attempts on my server, I was worried that they were taking up unnecessary resources. I wrote (hacked!) an HttpModule in c# that would filter out most xss and sql injection attacks. The code is pasted below, along with the config section required to make a website use it. It should be put in a project and compiled to WebSecurityFilter.dll, which should then be referenced by the web project (or otherwise dropped in the bin directory).
This will only work with asp.net, so hopefully your site is asp.net based (I did ask in a comment, but got no answer).
Web config section (add it in the <httpModules> section of <system.web>:
Code for module (SecurityHttpModule.cs):
Hopefully it all formatted okay…
I’ll try to post a link to the complete project in a zip this evening.