dbTalk Databases Forums  

Understanding injection attacks

comp.databases.postgresql comp.databases.postgresql


Discuss Understanding injection attacks in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
bcar
 
Posts: n/a

Default Re: Understanding injection attacks - 10-06-2010 , 04:40 AM






Le 06/10/2010 10:50, Lothar Kimmeringer a écrit :
Quote:
Simon Brooke wrote:

So I'm considering building up a query in a string buffer, with clauses
like the following:

String author = context.getValueAsString( Book.AUTHORFN );

if ( author != null ) {
/* do something to sanitise the input */
query.append( " and author like '%" ).append( author ).append( "%'" );
}

query.append(" and author like ?")
parameters.add(new MyParameterInfo(MyParameterInfo.TYPE_STRING,
"%" + author + "%");

You still have injection issues here, the user can enter % and _
for himself but that only affects the results not the statement
itself.

I see another possibility of injection with a string containing
"\';INSERT... --"
So if you simply replace ' by '' in your example you will have :
and author like '%\'';INSERT...--'
So the INSERT (or what you want) will be executed

Quote:
But do all SQL injection attacks depend simply on this trick, or are
there other tricks I need to defend against? In the particular instance,
the database is Postgres 8, but I'd like to have a general understanding
and a general solution.

Reply With Quote
  #12  
Old   
Arne Vajhøj
 
Posts: n/a

Default Re: Understanding injection attacks - 10-06-2010 , 05:43 PM






On 06-10-2010 05:40, bcar wrote:
Quote:
Le 06/10/2010 10:50, Lothar Kimmeringer a écrit :
Simon Brooke wrote:

So I'm considering building up a query in a string buffer, with clauses
like the following:

String author = context.getValueAsString( Book.AUTHORFN );

if ( author != null ) {
/* do something to sanitise the input */
query.append( " and author like '%" ).append( author ).append( "%'" );
}

query.append(" and author like ?")
parameters.add(new MyParameterInfo(MyParameterInfo.TYPE_STRING,
"%" + author + "%");

You still have injection issues here, the user can enter % and _
for himself but that only affects the results not the statement
itself.


I see another possibility of injection with a string containing
"\';INSERT... --"
So if you simply replace ' by '' in your example you will have :
and author like '%\'';INSERT...--'
So the INSERT (or what you want) will be executed
Usually the JDBC driver will reject that.

Multiple SQL statements in a single execute is usually not supported.

Arne

Reply With Quote
  #13  
Old   
Lothar Kimmeringer
 
Posts: n/a

Default Re: Understanding injection attacks - 10-07-2010 , 06:54 AM



bcar wrote:

Quote:
Le 06/10/2010 10:50, Lothar Kimmeringer a écrit :

query.append(" and author like ?")
parameters.add(new MyParameterInfo(MyParameterInfo.TYPE_STRING,
"%" + author + "%");

You still have injection issues here, the user can enter % and _
for himself but that only affects the results not the statement
itself.


I see another possibility of injection with a string containing
"\';INSERT... --"
So if you simply replace ' by '' in your example you will have :
and author like '%\'';INSERT...--'
So the INSERT (or what you want) will be executed
No, because the escaping of all relevant characters will take
place in (or is at least the responsibility of) the JDBC-driver
when setting the parameter using setString(...)

So above text will actually be searched for in the database
leading to (most likely) zero results.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: spamfang (AT) kimmeringer (DOT) de
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!

Reply With Quote
  #14  
Old   
bcar
 
Posts: n/a

Default Re: Understanding injection attacks - 10-13-2010 , 04:55 AM



Le 07/10/2010 13:54, Lothar Kimmeringer a écrit :
Quote:
No, because the escaping of all relevant characters will take
place in (or is at least the responsibility of) the JDBC-driver
when setting the parameter using setString(...)
Yes, I'm OK with that. But you have to check configuration and JDBC used
and at least test to ensure that is safe.

bcar

Reply With Quote
  #15  
Old   
Mladen Gogala
 
Posts: n/a

Default Re: Understanding injection attacks - 10-13-2010 , 04:26 PM



On Wed, 13 Oct 2010 11:55:53 +0200, bcar wrote:

Quote:
Yes, I'm OK with that. But you have to check configuration and JDBC used
and at least test to ensure that is safe.
And this is how you check whether it's safe:
http://www.youtube.com/watch?v=FHbBWC7w_Gk


--
http://mgogala.byethost5.com

Reply With Quote
  #16  
Old   
Arne Vajhøj
 
Posts: n/a

Default Re: Understanding injection attacks - 10-13-2010 , 06:52 PM



On 13-10-2010 05:55, bcar wrote:
Quote:
Le 07/10/2010 13:54, Lothar Kimmeringer a écrit :
No, because the escaping of all relevant characters will take
place in (or is at least the responsibility of) the JDBC-driver
when setting the parameter using setString(...)

Yes, I'm OK with that. But you have to check configuration and JDBC used
and at least test to ensure that is safe.
It is required functionality for the driver to be JDBC compliant.

Arne

Reply With Quote
  #17  
Old   
Mladen Gogala
 
Posts: n/a

Default Re: Understanding injection attacks - 10-14-2010 , 04:17 AM



On Wed, 13 Oct 2010 19:52:02 -0400, Arne Vajhøj wrote:

Quote:
Yes, I'm OK with that. But you have to check configuration and JDBC
used and at least test to ensure that is safe.

It is required functionality for the driver to be JDBC compliant.

JDBC drivers usually are JDBC compliant. If they are not, they're called
something else, not "JDBC drivers".


--
http://mgogala.byethost5.com

Reply With Quote
Reply




Thread Tools
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.