0

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.

Shoe
  • 74,840
  • 36
  • 166
  • 272
hd.
  • 17,596
  • 46
  • 115
  • 165

2 Answers2

1

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

Here is an blog article explaining this

MarcDefiant
  • 6,649
  • 6
  • 29
  • 49
1

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.

Ragen Dazs
  • 2,115
  • 3
  • 28
  • 56