That SQL injection attack...
August 6, 2008 · 40 Comments
You know the one I mean. It's been doing the rounds lately. This morning I checked my webmaster mailbox and found hundreds of error messages from my blog. Normally, I only get one or two a day due to URL hackery attempts so something was clearly up. Yup, that SQL injection attack had been tried on my blog. Fortunately, the code uses cfqueryparam in all of the queries (it's an old version of BlogCFC but Ray has always been really good about this!) so every attack was repelled, with just an error raised due to the URL string being too long for the DB column.
Thank you Ray!
Moral: always use cfqueryparam!
Tags: coldfusion

40 responses so far ↓
1 Anuj Gakhar // Aug 6, 2008 at 8:14 AM
Good that cfqueryparam is to the rescue.
2 todd sharp // Aug 6, 2008 at 8:19 AM
http://slidesix.com/view/ColdFusion--Protecting-Your-Applications
3 Steve Withington // Aug 6, 2008 at 8:25 AM
4 Jim Pickering // Aug 6, 2008 at 8:33 AM
5 Jason Fisher // Aug 6, 2008 at 10:39 AM
6 ike // Aug 6, 2008 at 11:10 AM
7 Sean Corfield // Aug 6, 2008 at 11:55 AM
8 todd sharp // Aug 6, 2008 at 2:54 PM
9 Dmitry Yakhnov // Aug 6, 2008 at 9:07 PM
10 Gert Franz // Aug 6, 2008 at 9:10 PM
This means the server will execute the prepared statement nr. 23 and pass the parameters 34,54,23 and 21 to it. But it is another matter to find out which prepared statement that might be. This is the only downside I see in queryparams and prepared statements. In Railo 3.1 you will have an option to turn of the background use of prepared statements but still being able to use cfqueryparam. Of course prepared statements are faster since the DB server does not have to recalculate the execution plan for a particular query all over again. But in order to find errors it might be useful to temporary turn of the use of prepared statements.
Gert
11 Sean Corfield // Aug 6, 2008 at 9:48 PM
12 Dane Pescaia // Aug 6, 2008 at 11:17 PM
declare @p1 int
set @p1=NULL
exec sp_prepexec @p1 output,N'@P1 int',N'select top 1 * from some_table where some_id = @P1 ',100
select @p1
13 Tom Chiverton // Aug 7, 2008 at 2:37 AM
@Gert: I have *never* had an issue where use of a prepared statement made it hard to debug anything. I've never even heard anyone moan that it was a problem.
14 Sebastiaan // Aug 7, 2008 at 3:36 AM
http://www.coldfusiondeveloper.com.au/go/blog/protect-your-cf-application/
Good luck with it - I've not been hit yet, but I know a lot of CFWebstore users have had problems with these attacks for some time now.
15 Patrick McElhaney // Aug 7, 2008 at 5:39 AM
RewriteCond %{QUERY_STRING} EXEC\(@S\) [NC]
RewriteRule .* - [F]
16 William from Lagos // Aug 7, 2008 at 6:00 AM
17 Pete Freitag // Aug 7, 2008 at 12:04 PM
@Dane - I see statements like that in CF7, but with CF8 I see statements like Gert describes. So must be due to how the prepared statements are invoked (and must have changed in CF7-8), I think there are a few different ways of doing this on SQL Server.
18 samuel // Aug 7, 2008 at 7:40 PM
Which goes where and does what exactly?
19 Sean Corfield // Aug 7, 2008 at 8:23 PM
20 Dane Pescaia // Aug 7, 2008 at 9:18 PM
21 Gert Franz // Aug 7, 2008 at 10:19 PM
Gert
22 Pete Freitag // Aug 8, 2008 at 9:20 AM
23 Mary Jo Sminkey // Aug 8, 2008 at 11:51 AM
24 Sebastiaan // Aug 8, 2008 at 11:13 PM
25 Jeff Knooren // Aug 9, 2008 at 1:00 AM
26 Sean Corfield // Aug 9, 2008 at 11:09 AM
27 ike // Aug 9, 2008 at 12:15 PM
Beyond Sean's advice that it's not a general solution, I also had to add when I replied that I see these only as temporary solutions while working on implementing cfqueryparam because as long as that solution is in place, you're going to get false positives. The problem with false positives is that friendly users who are doing what they are supposed to be doing will be prevented from legitimate uses of your site.
For example in the case of throwing an error on "declare " in the query-string you're going to get some user writing a forum entry with the phrase "I declare this project a success!" - your workaround for the sql-injection attack will produce a false positive, log the error and frustrate the hell out of your previously friendly and now possibly irate user.
So I wouldn't leave anything like that in any application on a permanent basis, just as a last-ditch to give you some breathing room while you deal with the problem at the source. Then code like hell until you're pretty sure all your queries are param'ed and comment it out and wait to see if you missed any.
So even if it weren't for the fact that it's not a general solution, I wouldn't recommend that as an addition to any framework distribution.
28 Jason Fisher // Aug 9, 2008 at 2:15 PM
I agree with not putting such specific traps into a framework's codebase, but you really should not have to worry about false positives with the DECLARE test. First of all, if you use Find("DECLARE", cgi.query_string) as your test, then it will be case-sensitive, and secondly, your forms shouldn't ever be posting to your query_string so long as you're using method="post". Basically, by testing 'DECLARE', you would be trapping only for bot and URL injection attempts that use the specific pattern being currently observed across these attacks.
Still wouldn't want it in the core distro, but little or no worry about false positives that I can see.
29 ike // Aug 9, 2008 at 2:57 PM
30 Jordan // Aug 14, 2008 at 6:47 AM
31 Pete Freitag // Aug 14, 2008 at 10:25 AM
32 Sean Corfield // Aug 14, 2008 at 10:38 AM
33 Sean Corfield // Aug 14, 2008 at 10:40 AM
34 ike // Aug 14, 2008 at 10:58 AM
1) twins separated at birth (in this day and age?)
2) clones ... (in this day and age?)
3) the orbital mind control lasers are working...
:)
35 Sean Corfield // Aug 14, 2008 at 11:07 AM
36 Tom Chiverton // Aug 15, 2008 at 7:37 AM
37 Sean Corfield // Aug 15, 2008 at 8:02 AM
38 ike // Aug 15, 2008 at 9:14 AM
@Sean - I can't say I've ever had that experience... I think I might enjoy it. :)
39 ike // Aug 15, 2008 at 3:34 PM
40 Sean Corfield // Aug 15, 2008 at 3:55 PM
Leave a Comment