-1

I have created this code for testing of SQL injection.

<?php
mysql_connect('localhost', 'root', '');
mysql_select_db("test");
$id = $_POST['data'];
$query = "SELECT * FROM members WHERE memberId ='" . $id . "'";
$q = mysql_query($query);
if (mysql_num_rows($q) == 0) 
{
      printf("<h4>Wrong user ID!</h4>");
}
else
{
  while ($row = mysql_fetch_array($q))
  {
  printf("<h4>Your ID is %s</h4>", $row["memberId"]);
  }
}
?>

When variable $id is 1' OR '1'='1, I can see all IDs in the table members. I would like also realize DROP TABLE, but I can't figure out what to insert in variable id $id. I have tried to insert 123'; DROP TABLE sql injection-- in $id.

Do you have any idea what to insert in $id or how to modify this code?

Mureinik
  • 297,002
  • 52
  • 306
  • 350
metjuf
  • 79
  • 1
  • 9

1 Answers1

0

In the console it would be: '; drop table members; select '

However you are using mysql_query and it supports only a single statement.

Here is what the manual says:

mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier.

Also check this question. As suggested there you can try using multi_query in your example.

Community
  • 1
  • 1
Daniel Sperry
  • 4,381
  • 4
  • 31
  • 41