How would I go about storing potential SQL injection attacks in a database?
Assume first that I have detected a potential attack, and have the offending attack string in a variable and would like to add it to a table containing a log of suspicious events.
What would I need to do to safely insert these strings into a database so that no errors would be produced?
I have a feeling that it will be something along the lines of htmlspecialchars and mysql_real_escape_string… but I wanted to throw it out there to see if anybody else had any ideas!
One thought was to store the attack as an encoded base64 value, but that seems a bit hackish…
FYI, I am writing the application in PHP 🙂
Any responses would be greatly appreciated!
Always use parameterized queries. If you are using parameters, you don’t need to rely on escaping strings and your query will always do exactly what you intend.
e.g.:
See documentation for PDO prepare here:
http://www.php.net/manual/en/pdo.prepare.php