Luis Melo commented on the 24 Jul 2008
Our system was not SQL Injection proof and we recently suffered an attack that corrupted the data in some of our database tables. The attack was quite elegant and fortunately did not cause severe damage other than the appending of a SCRIPT sting to a bunch of VARCHAR fields. This was meant to actually execute a JS file and this qualifies as a XSS attack. In researching the Web for a solution for the problem, and a way to immunize our CF application against further attacks, we came across the CFQUERYPARAM solution, but our application has over 5000 files, each with one or more Queries and Stored Procedure calls. Implementing such a solution in such an extensive amount of files was impossible in a timely fashion, so I looked for another solution and came across a ColdFusion written function (isSqlInjection) that showed some promise but some shortcomings as well. I wanted something that we could deploy fast and that would immunize the entire application in one single swoop. As far as I understand, SQL injections can come from either FORM fields or from URL passed variables. Therefore we developed a function that was placed in our application.cfm and therefore used by all our CFM files. The function used a custom developed Regular Expression to check all URL and FORM fields for possible SQL Injections. We were able to develop this in one day and implement it immediately. That same night we were able to catch and prevent 2 more SQL Injection attempts. We have since improved the script and it now does the following: Checks all FORM and URL input for SQL injection code Interfaces (CFHTTP) with ARIN WHOIS Database Search ([visit link]) to get ISP information for the offenders IP. Automatically sends an abuse report to the ISP concerning the attack. Displays a message informing the hacker that the attack was logged, that his/her ISP was contacted and that he/she is breaking the law Sends us an email with the SQL Injection string, IP address and other information. Stores the hackers IP address in an APPLICATION array (Black List). o Each time a page in our application is requested, the IP address (CGI.REMOTE_ADDR) is compared with those in the Black List and if it is present, page execution is halted right at the application.cfm level returning a blank page to the browser o Black List entries that are older than one hour are cleared by a scheduled task on an hourly basis. We are making this code available to other CF developers for free. Please request a copy by email. luism@grouptraveltech.com. If after receiving it you have suggestions or improvements, please send them my way as well. |