MySQL Forums
Forum List  »  Newbie

Re: SQL Injection
Posted by: Richard Creer
Date: November 30, 2009 11:34AM

That's good because I have spend a long time searching and not found any realistic example. I have just searched for 'sql injection attack example' and taking the first on the list - http://unixwiz.net/techtips/sql-injection.html - you find the oft quoted -

By entering anything' OR 'x'='x, the resulting SQL is:
SELECT fieldlist
FROM table
WHERE field = 'anything' OR 'x'='x';

This is nonsense because you can paraphrase it to say

By entering Mike O'Connor, the resulting SQL is:
SELECT fieldlist
FROM table
WHERE field = 'Mike O'Connor'

This isn't an injection attack it is an SQL syntax error.

Therefore you must always double single quotes in strings when the string has been supplied by a user in order to prevent SQL syntax errors. The fact that doing so prevents injection attacks simply a useful byproduct. By doubling single quotes our two examples become

SELECT fieldlist
FROM table
WHERE field = 'Mike O''Connor'
- no syntax error, and
SELECT fieldlist
FROM table
WHERE field = 'anything'' OR ''x''=''x'';'
- no injection attack.

But you're searches must be better than mine so perhaps you would care to share the results with me so that I can see the error of my ways.

Options: ReplyQuote


Subject
Written By
Posted
November 28, 2009 10:43AM
November 28, 2009 11:48AM
November 29, 2009 09:32AM
November 30, 2009 12:21PM
November 29, 2009 12:03AM
November 29, 2009 09:49AM
November 29, 2009 11:59AM
November 29, 2009 01:37PM
November 29, 2009 02:36PM
November 29, 2009 03:09PM
November 30, 2009 08:45AM
November 30, 2009 09:51AM
November 30, 2009 10:17AM
November 30, 2009 08:39AM
November 30, 2009 10:55AM
Re: SQL Injection
November 30, 2009 11:34AM
December 01, 2009 04:14AM
January 18, 2010 11:49AM
January 18, 2010 12:10PM
January 18, 2010 12:10PM
January 18, 2010 12:07PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.