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
  • 72,892
  • 33
  • 161
  • 264
hd.
  • 16,676
  • 43
  • 110
  • 160

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,321
  • 5
  • 26
  • 47
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,045
  • 3
  • 25
  • 54