How could I test to see if SQL injection doesn't work in a textbox on my site?
- You'll have to be much more specific. How are you escaping the text before entering it into the database?Savetheinternet– Savetheinternet2011-01-09 17:57:23 +00:00Commented Jan 9, 2011 at 17:57
- Can you show some internal code? i.e. how the textbox is used? There is no generic way, it depends on the query you're usingPekka– Pekka2011-01-09 17:57:44 +00:00Commented Jan 9, 2011 at 17:57
5 Answers
Use a mechanism that guarantees it's impossible by design, like bound parameters. Then no testing (for SQL injection resistance) is necessary.
Put another way: don't rely on ad-hoc escaping code; it's very likely you won't get it 100% correct.
4 Comments
char[] buffers and gets()...you usually have to think how the data from the input field will reach the actual select. Once you know that you try to see what sort of text can you put in that field to terminate a sql statement and start another.
For example, if you have do something like this in code: 'select * from table where id = ' . $_GET['id'] and i call you with script.php?id=0%20OR%20true; drop table table; i can execute two statements.
But in general you should avoid constructing selects by concatenating. Better to use bounded parameters as another responder suggested.
Comments
Just enter this String:
'"; If no escaping is in action, this will break your SQL for sure.
See this site about better Strings and this question for more info.
Comments
You could use this list to create attacks against your code: http://ha.ckers.org/sqlinjection/
You also can assemble a list of 'dangerous' characters and character combinations and create (pseudo)-random input values from it.