1. sql injection

There was a way perl implementers of the db libraries avoided sql injection attacks. You would pass the values you were sending outside of the string:

So the statement woudl be passed as: insert into tablefoo values (?,?,?,?) and then for each actual execution you would send the four values as part of an argument list.

I don't know if the .e libraries allow you to do the same thing but they ought to.

Shawn

new topic     » topic index » view message » categorize

2. Re: sql injection

Shawn Pringle said...

There was a way perl implementers of the db libraries avoided sql injection attacks. You would pass the values you were sending outside of the string:

So the statement woudl be passed as: insert into tablefoo values (?,?,?,?) and then for each actual execution you would send the four values as part of an argument list.

I don't know if the .e libraries allow you to do the same thing but they ought to.

That's really a job for the database library you are using because different database servers escape characters differently. Some may use '' to escape a single quote, others will use \'. Now, the way I did it in my unfinished DBI library was to allow you to do things such as:

dt:datetime now = dt:now() 
sequence name = "John Mc'Doe" 
atom salary = 100500.52 
integer age = 11 
sequence comparator = ">" 
 
db:execute(dbh, "UPDATE people SET updated_at=%D, name=%s, salary=%.2f, age=%d WHERE id %S 100", 
    {now, name, salary, age, comparator}) 

The escape codes keep with sprintf as much as possible. The %D converts a datetime.e datetime type into a SQL valid date time string, the %s escapes and quotes the content, the %f, %d work the same as printf, %S is a non-escaped, non-quoted string.

Jeremy

new topic     » goto parent     » topic index » view message » categorize

3. Re: sql injection

Shawn Pringle said...

There was a way perl implementers of the db libraries avoided sql injection attacks. You would pass the values you were sending outside of the string:

So the statement woudl be passed as: insert into tablefoo values (?,?,?,?) and then for each actual execution you would send the four values as part of an argument list.

I don't know if the .e libraries allow you to do the same thing but they ought to.

Oh, I wanted to mention also that there are other injection methods. Two others are XSS injection (injecting JavaScript code into HTML) and possibly the most dangerous shell injection. Prevention of shell injection will be added to os.e, as that's where system commands are executed. Prevention of XSS type injections should be done by the web framework you are using.

Jeremy

new topic     » goto parent     » topic index » view message » categorize

4. Re: sql injection

Jeremy Cowgar said...

That's really a job for the database library you are using because different database servers escape characters differently. Some may use '' to escape a single quote, others will use \'. Now, the way I did it in my unfinished DBI library was to allow you to do things such as:

If I read this correctly, you're taking an escape approach, rather than using parameters? What about prepared statements?

Matt

new topic     » goto parent     » topic index » view message » categorize

5. Re: sql injection

Matt Lewis said...

If I read this correctly, you're taking an escape approach, rather than using parameters? What about prepared statements?

Prepared statements are not supported yet grin It may very well change the design overall. One difficulty with prepared statements and a DBI is how each database may do it slightly different and some databases do not do it at all getlost... Some use ?, others use %1, %2, %3. I am not yet sure how to go about handling it. I am open to suggestions.

Jeremy

new topic     » goto parent     » topic index » view message » categorize

6. injection

system( ... , int )

Instead of passing a string with system() a better function should take what would be formated like the return value of command_line().

shell_execute( { "/bin/rm", file_name } ) illistrative use only

There are all kinds of problems using system( "rm file_name", 0 ). Imagine if the user installs the program under Program Files and this call is for deleting for an uninstall. The system answers as it cannot find the file c:\Programs.

Shawn

new topic     » goto parent     » topic index » view message » categorize

7. Re: injection

Shawn Pringle said...

shell_execute( { "/bin/rm", file_name } ) illistrative use only

Shawn, an escape.e is floating around out there that has a escape_shellarg() which I was going to add to the standard library for handling shell injection. I will still do that because I am sure people will want to use it, but I really like your idea. That would indeed be a nice function. I'll add it to os.e

Jeremy

new topic     » goto parent     » topic index » view message » categorize

8. Re: sql injection

Yeah, that's exactly what I was thinking. In addition to that, they all handle lots of stuff slightly differently. It's really hard to get good, cross-DB code. If I wanted that portability, I'd probably just use ODBC.

new topic     » goto parent     » topic index » view message » categorize

9. Re: injection

Shawn Pringle said...

system( ... , int )

Instead of passing a string with system() a better function should take what would be formated like the return value of command_line().

shell_execute( { "/bin/rm", file_name } ) illistrative use only

There are all kinds of problems using system( "rm file_name", 0 ). Imagine if the user installs the program under Program Files and this call is for deleting for an uninstall. The system answers as it cannot find the file c:\Programs.

Shawn

system( "rm \"file_name\"", 0 ) 

Not good? CChris

btw I have cookies enabled, but still asked for my name.

new topic     » goto parent     » topic index » view message » categorize

10. Re: injection

CChris said...
Shawn Pringle said...

system( ... , int )

Instead of passing a string with system() a better function should take what would be formated like the return value of command_line().

shell_execute( { "/bin/rm", file_name } ) illistrative use only

There are all kinds of problems using system( "rm file_name", 0 ). Imagine if the user installs the program under Program Files and this call is for deleting for an uninstall. The system answers as it cannot find the file c:\Programs.

Shawn

system( "rm \"file_name\"", 0 ) 

Not good? CChris

btw I have cookies enabled, but still asked for my name.

No idea about DOS. On Unix we can do the shell_execute via execv(), and avoid the need to quote altogether. (Presumbly shell_execute() wouldn't allow you to use > or < for redirection or | for piping anyways.) However afaik the w32api doesn't have a way to specify arguments as an array of strings so this can't be done on Windows.

Jeremy had an idea to implement shell_execute() cross-platform by simply escaping each argument individually and passing a combined string to system(). This seems to be the best compromise and the simplest approach.

new topic     » goto parent     » topic index » view message » categorize

11. Re: injection

CChris said...
system( "rm \"file_name\"", 0 ) 

Not good?

Nope. For instance:

    file_name = "\"; rm -rf \"~/*" 

Matt

PS Some birds do swim.

new topic     » goto parent     » topic index » view message » categorize

12. Re: injection

Matt Lewis said...
CChris said...
system( "rm \"file_name\"", 0 ) 

Not good?

Nope. For instance:

    file_name = "\"; rm -rf \"~/*" 

Matt

shell argument escaping would take care of this.

Matt Lewis said...

PS Some birds do swim.

Which is why its a perfect choice of question! The ambiguity guarrantees only a human brain will be able to solve it!

At least until thoes T-500s start ramping up production...

new topic     » goto parent     » topic index » view message » categorize

13. Re: injection

Matt Lewis said...

PS Some birds do swim.

There's a flying fish too... but yes, the questions are good because you can work out what is meant rather than what the answer should be from the question.

Like any captcha though, you should be able to reload the question if you really don't get it (non-native English speaker maybe).

Gary

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu