If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > SQL injection?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-24-07, 15:11
quakey quakey is offline
Registered User
 
Join Date: Aug 2007
Posts: 8
SQL injection?

At work, we have a huge user table with all the email addresses. We also have a column acting as a counter that we increment when certain things happen. Recently we found that the counter got incremented on 99% of the email addresses all at once and that really screwed things up. By digging through MySQL logs, I finally found the offending SQL statement (with fake database.table and column name):

UPDATE database.table SET counter = counter + 1 WHERE email = 'In>Ng;>.|-vcduee YSZTM||I!8e1CIVY?oUO<<ACNanZTMabp*TyaIiaE u\"{XSXveZ|'a=$hB|Fa1Tu?ZObP@cbk3n`0RI..C89-WoTc0Eciie5NSPI2q3...pp(..c]0I*|o27r,,p9Q.....ZTobHIETyYP'-'!#0SaaFAO'

That is one crazy WHERE condition clause. Can anyone see why it matches 99% of the email addresses I have in the table? There is not going to be any prize for figuring it out for me unfortunately but I appreciate any feedback on this! Thanks.

You can also respond to this by posing comments on my blog:
<Removed>

Last edited by gvee; 08-24-07 at 15:49.
Reply With Quote
  #2 (permalink)  
Old 08-24-07, 15:48
gvee gvee is offline
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 10,156
Link to blog removed.

If you post on a public forum then the answers are best kept public!
__________________
George
Twitter | Blog
Reply With Quote
  #3 (permalink)  
Old 08-28-07, 07:14
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
What scripting language were/are you using?
Reply With Quote
  #4 (permalink)  
Old 08-28-07, 18:52
quakey quakey is offline
Registered User
 
Join Date: Aug 2007
Posts: 8
I use PHP. Does it matter?

Quote:
Originally Posted by aschk
What scripting language were/are you using?
Reply With Quote
  #5 (permalink)  
Old 08-28-07, 20:51
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
oui, mais bien sur, it certainly does matter

the scripting language is where you stop the injection attack

once you hand the sql over to the database engine, it's too late
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 08-30-07, 03:43
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
I took a brief look at that SQL statement, but I can't for the life of me work out what it does. Anyone care to enlighten me?

note : i should probably try it in mysql first eh?
Reply With Quote
  #7 (permalink)  
Old 08-30-07, 16:10
quakey quakey is offline
Registered User
 
Join Date: Aug 2007
Posts: 8
This is purely a SQL question, nothing to do with the language behind it.

Quote:
Originally Posted by r937
oui, mais bien sur, it certainly does matter

the scripting language is where you stop the injection attack

once you hand the sql over to the database engine, it's too late
Reply With Quote
  #8 (permalink)  
Old 08-30-07, 16:12
quakey quakey is offline
Registered User
 
Join Date: Aug 2007
Posts: 8
I know what it does. I just do not understand why. Please read my original post again, carefully this time. Thanks.

Quote:
Originally Posted by aschk
I took a brief look at that SQL statement, but I can't for the life of me work out what it does. Anyone care to enlighten me?

note : i should probably try it in mysql first eh?
Reply With Quote
  #9 (permalink)  
Old 08-30-07, 16:37
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by quakey
This is purely a SQL question, nothing to do with the language behind it.
as you wish

here's my test setup:
Code:
create table quakey
( id integer not null primary key auto_increment
, email varchar(99)
, counter smallint
);
insert into quakey ( email , counter ) values
 ( 'joe@example.com'  ,  9 )
,( 'todd@example.net' , 37 )
,( 'biff@example.org' ,  0 )
;
and here's my test of your query, which i very carefully copied --
Code:
UPDATE quakey 
   SET counter = counter + 1 
 WHERE email = 'In>Ng;>.|-vcduee YSZTM||I!8e1CIVY?oUO<<ACNanZTMabp*TyaIiaE u\"{XSXveZ|'a=$hB|Fa1Tu?ZObP@cbk3n`0RI..C89-WoTc0Eciie5NSPI2q3...pp(..c]0I*|o27r,,p9Q.....ZTobHIETyYP'-'!#0SaaFAO'
 
Error: input parameter count is less than expected
your move

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #10 (permalink)  
Old 08-30-07, 18:58
quakey quakey is offline
Registered User
 
Join Date: Aug 2007
Posts: 8
Actually the original SQL statement I posted was incorrect as it was most likely escaped when it was posted without the CODE tag. So try this:

Code:
UPDATE quakey SET counter = counter + 1 WHERE email = 'In>Ng;>.|-vcduee  YSZTM||I!8e1CIVY?oUO<<ACNanZTMabp*Ty\\0aIiaE u\\\"{XSXveZ|\\\'a=$hB|Fa1Tu?ZObP@cbk3n`0RI..C89-WoTc0Eciie5NSPI2q3...pp(..c]0I*|o27r,,p9Q.....ZTobHIETyYP'-'!#0SaaFAO'
Your move

Quote:
Originally Posted by r937
as you wish

here's my test setup:
Code:
create table quakey
( id integer not null primary key auto_increment
, email varchar(99)
, counter smallint
);
insert into quakey ( email , counter ) values
 ( 'joe@example.com'  ,  9 )
,( 'todd@example.net' , 37 )
,( 'biff@example.org' ,  0 )
;
and here's my test of your query, which i very carefully copied --
Code:
UPDATE quakey 
   SET counter = counter + 1 
 WHERE email = 'In>Ng;>.|-vcduee YSZTM||I!8e1CIVY?oUO<<ACNanZTMabp*TyaIiaE u\"{XSXveZ|'a=$hB|Fa1Tu?ZObP@cbk3n`0RI..C89-WoTc0Eciie5NSPI2q3...pp(..c]0I*|o27r,,p9Q.....ZTobHIETyYP'-'!#0SaaFAO'
 
Error: input parameter count is less than expected
your move

Reply With Quote
  #11 (permalink)  
Old 08-30-07, 19:03
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
amazin, i would never have believed it without testing

you're right, it did update every row

perhaps you could report it to mysql as a bug?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #12 (permalink)  
Old 08-30-07, 19:08
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
oh, wait a sec..

try this:
Code:
select email = 'foo' - 'bar' as true_or_false
 from quakey
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #13 (permalink)  
Old 08-30-07, 19:15
quakey quakey is offline
Registered User
 
Join Date: Aug 2007
Posts: 8
Ya, you are right. I tried this too and it returns everything:

Code:
select * from quakey where email = '' - ''
What is going on here? What is with the 'xxx' - 'yyy'?

Thank you.

Quote:
Originally Posted by r937
oh, wait a sec..

try this:
Code:
select email = 'foo' - 'bar' as true_or_false
 from quakey
Reply With Quote
  #14 (permalink)  
Old 08-31-07, 05:46
aschk aschk is offline
Registered User
 
Join Date: Mar 2007
Location: 636f6d7075746572
Posts: 770
Could just be me but I can't replicate this error...
Damn copy and pasting!
Reply With Quote
  #15 (permalink)  
Old 08-31-07, 07:59
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by aschk
Could just be me but I can't replicate this error...
Damn copy and pasting!
try replicating the one in post #12
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On