0

Why is my sql injection which i am trying to practice on not working.

$sql = "INSERT INTO animals VALUES ('', '{$string}', 'rover')";

I have an input box in where i put the following

', ''); drop table dropme; --  

and that is swapped for the injection code.

However the sql fails. But when I process the following statement in phpmyadmin then it does work.

INSERT INTO animals VALUES ('','    ', ''); drop table dropme; --   ','rover')";

How can this be? Is my browser automatically escaping it for me

yehuda
  • 1,254
  • 2
  • 11
  • 21

3 Answers3

8

None of the PHP/MySQL interfaces allow you to execute more than one statement at once. This type of SQL injection is not possible in PHP.

When you execute it in phpMyAdmin, it splits your string up into separate queries and executes them one at a time.

The type of SQL injection that is possible in PHP is stuff like this:

$dirtyString = "' OR 1 = 1 UNION ALL SELECT * FROM private_table WHERE '1' = '1";

$query = "SELECT * FROM public_table WHERE `col` = '$dirtyString'";
DaveRandom
  • 87,921
  • 11
  • 154
  • 174
1

You cannot do this from PHP as it does not allow to execute more than one statement at once. The mysql_query() manual page states:

The query string should not end with a semicolon.

Treffynnon
  • 21,365
  • 6
  • 65
  • 98
0

Some versions of PHP automatically escape everything for you with magic quotes.

http://php.net/manual/en/security.magicquotes.what.php

Farzher
  • 13,934
  • 21
  • 69
  • 100