I have this query:
DELETE FROM users WHERE user_email = '$email'
How can it be attacked by SQL injection attack that causes all of records get deleted?
addslashes()
function is applied on $email
before sending it to the query.
I have this query:
DELETE FROM users WHERE user_email = '$email'
How can it be attacked by SQL injection attack that causes all of records get deleted?
addslashes()
function is applied on $email
before sending it to the query.
You can bypass addslashes as following if the wrong encoding is set in the database (this doesn't work with UTF-8):
$email = urldecode('%BF%27 OR 1 -- '); // user input
$email = addslashes($email);
$sql = "DELETE FROM users WHERE user_email = '$email'";
because a \
is prepended to %27
('
), %BF
and a blackslash results in a valid multibyte char
If you are using PDO
you can use $pdo->quote($var)
or use PDOStatement bindParam
, bindValue($var, PDO::INT_PARAM)
that sanitizes data and avoid all public knowed special chars become used as sql injection.
EDIT
Thats because each databse has his own reserved words.