<p>I am looking for a tool that can detect malicious requests (such as obvious SQL injection gets or posts) and will immediately ban the IP address of the requester/add to a blacklist. I am aware that in an ideal world our code should be able to handle such requests and treat them accordingly, but there is a lot of value in such a tool even when the site is safe from these kinds of attacks, as it can lead to saving bandwidth, preventing bloat of analytics, etc.</p>

<p>Ideally, I'm looking for a cross-platform (<code>LAMP/.NET</code>) solution that sits at a higher level than the technology stack; perhaps at the web-server or hardware level. I'm not sure if this exists, though.</p>

<p>Either way, I'd like to hear the community's feedback so that I can see what my options might be with regard to implementation and approach.</p>

[{'answer_id': 1317, 'author': 'Mat', 'author_id': 48, 'author_profile': 'https://Stackoverflow.com/users/48', 'pm_score': 3, 'selected': False, 'text': "<p>The problem with a generic tool is that it is very difficult to come up with a set of rules that will only match against a genuine attack.</p>\n\n<p>SQL keywords are all English words, and don't forget that the string</p>\n\n<pre><code> DROP TABLE users;\n</code></pre>\n\n<p>is perfectly valid in a form field that, for example, contains an answer to a programming question.</p>\n\n<p>The only sensible option is to sanitise the input before ever passing it to your database but pass it on nonetheless.  Otherwise lots of perfectly normal, non-malicious users are going to get banned from your site.</p>\n"}, {'answer_id': 1328, 'author': 'ricree', 'author_id': 121, 'author_profile': 'https://Stackoverflow.com/users/121', 'pm_score': 2, 'selected': False, 'text': '<p>One method that might work for some cases would be to take the sql string that would run if you naively used the form data and pass it to some code that counts the number of statements that would actually be executed.  If it is greater than the number expected, then there is a decent chance that an injection was attempted, especially for fields that are unlikely to include control characters such as username.</p>\n\n<p>Something like a normal text box would be a bit harder since this method would be a lot more likely to return false positives, but this would be a start, at least.</p>\n'}, {'answer_id': 1333, 'author': 'Michael Stum', 'author_id': 91, 'author_profile': 'https://Stackoverflow.com/users/91', 'pm_score': 2, 'selected': False, 'text': '<p>One little thing to keep in mind: In some countries (i.e. most of Europe), people do not have static IP Addresses, so blacklisting should not be forever.</p>\n'}, {'answer_id': 1336, 'author': 'ricree', 'author_id': 121, 'author_profile': 'https://Stackoverflow.com/users/121', 'pm_score': 0, 'selected': False, 'text': '<p>Now that I think about it, a Bayesian filter similar to the ones used to block spam might work decently too.  If you got together a set of normal text for each field and a set of sql injections, you might be able to train it to flag injection attacks.</p>\n'}, {'answer_id': 1356, 'author': 'Uberfuzzy', 'author_id': 314, 'author_profile': 'https://Stackoverflow.com/users/314', 'pm_score': 4, 'selected': False, 'text': '<p>Your almost looking at it the wrong way, no 3party tool that is not aware of your application methods/naming/data/domain is going to going to be able to perfectly protect you.</p>\n\n<p>Something like SQL injection prevention is something that has to be in the code, and best written by the people that wrote the SQL, because they are the ones that will know what should/shouldnt be in those fields (unless your project has very good docs)</p>\n\n<p>Your right, this all has been done before. You dont quite have to reinvent the wheel, but you do have to carve a new one because of a differences in everyone\'s axle diameters.</p>\n\n<p>This is not a drop-in and run problem, you really do have to be familiar with what exactly SQL injection is before you can prevent it. It is a sneaky problem, so it takes equally sneaky protections.</p>\n\n<p>These 2 links taught me far more then the basics on the subject to get started, and helped me better phrase my future lookups on specific questions that weren\'t answered.</p>\n\n<ul>\n<li><a href="http://en.wikipedia.org/wiki/SQL_injection" rel="nofollow noreferrer">SQL injection</a></li>\n<li><a href="http://www.unixwiz.net/techtips/sql-injection.html" rel="nofollow noreferrer">SQL Injection Attacks by Example</a></li>\n</ul>\n\n<p>And while this one isnt quite a 100% finder, it will "show you the light" on existing  problem in your existing code, but like with webstandards, dont stop coding once you pass this test.</p>\n\n<ul>\n<li><a href="http://www.securitycompass.com/exploitme.shtml" rel="nofollow noreferrer">Exploit-Me</a></li>\n</ul>\n'}, {'answer_id': 2608, 'author': 'Mario Marinato', 'author_id': 431, 'author_profile': 'https://Stackoverflow.com/users/431', 'pm_score': 2, 'selected': False, 'text': '<p>Oracle has got an <a href="http://st-curriculum.oracle.com/tutorial/SQLInjection/index.htm" rel="nofollow noreferrer">online tutorial about SQL Injection</a>.  Even though you want a ready-made solution, this might give you some hints on how to use it better to defend yourself.</p>\n'}, {'answer_id': 72620, 'author': 'user7428', 'author_id': 7428, 'author_profile': 'https://Stackoverflow.com/users/7428', 'pm_score': 0, 'selected': False, 'text': "<p>One of my sites was recently hacked through SQL Injection.  It added a link to a virus for every text field in the db!  The fix was to add some code looking for SQL keywords.  Fortunately, I've developed in ColdFiusion, so the code sits in my Application.cfm file which is run at the beginning of every webpage &amp; it looks at all the URL variables.  Wikipedia has some good links to help too.</p>\n"}, {'answer_id': 24925655, 'author': 'ECE', 'author_id': 1877309, 'author_profile': 'https://Stackoverflow.com/users/1877309', 'pm_score': -1, 'selected': False, 'text': '<p>Interesting how this is being implemented years later by google and them removing the URL all together in order to prevent XSS attacks and other malicious acitivites</p>\n'}]
['https://Stackoverflow.com/questions/1284', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']