what is the worst that could happen to my database if my PHP code has a SQL injection vulnerability in the where statement, ie SELECT * FROM table WHERE id='$unescapedstring'
?
sorry forgot to mention mysql
what is the worst that could happen to my database if my PHP code has a SQL injection vulnerability in the where statement, ie SELECT * FROM table WHERE id='$unescapedstring'
?
sorry forgot to mention mysql
What if $unescapedstring
is set to cake';DROP TABLE 'table';--
? That'll execute the select, followed by the DROP TABLE statement. Replace the drop table with whatever sql you want, and you've got yourself the ability to execute any SQL. They can download your database, or wipe it, or modify records...just don't do it. Sanitize your inputs! Otherwise, your users have free reign on your database.
The worst that can happen? I'd say that anything can happen with that query.
For example, I submit this:
unescapedstring: '; (any other query)
Now, your query becomes:
SELECT * FROM table WHERE id=''; (any other query)
From there, I have the ability to execute any MySQL command. I can drop your whole database, I can edit it, I can download your database, and if your server permits, I can even go as far as rooting your actual server.
Basically, the attacker has full access to your MySQL installation. Expect anything.
While the other answers are completely correct, if you have your mysql user accounts set up correctly, the account executing those queries probably shouldn't have permissions to alter/create/drop tables/databases. Therefore, worst that could happend in that scenario: DELETE FROM table