views:

84

answers:

4
bob'); drop table students; --

In PHP,this will fail:

mysql("statement1;statement2;");

There can be only one statement,so I really doubt how can the above injection actually work at all?

A: 

Not sure if this will work, but try using // as your separator instead of ;, e.g.,

bob')// drop table students// --

There is info on submitting multiple statements using the multi_query statement from PHP here.

RedFilter
the mysql functions in PHP only allow for one statement per function call. The semicolon (or otherwise) is ignored.
nickf
Updated answer...
RedFilter
@nickf ,what do you mean by ignored?Do you mean it'll be the same as `bob') drop table students`?
@unknown sorry, that was a bit confusing. it'll only run the first statement, ignoring the rest.
nickf
+1  A: 

Well it doesn't work in MySQL, but there's other things that can be done with SQL injection.

Consider this:

$sql = "SELECT * FROM users WHERE username = '$username' AND passwd = '$password'";

// run the query, check if the user exists, let them in, etc

If you write this into the username field:

admin' -- 

it becomes:

SELECT * FROM users WHERE username = 'admin' -- AND passwd = 'whatever'

There's also the possibility of Denial-of-service attacks, where they structure the input so that the query takes a very long time to complete, hogging all the resources on your server.

//input:

admin' AND id IN (SELECT u1.id FROM users u1, users u2, users u3, users u4)

If you had 1000 users in your system, that subquery would be trying to return 1,000,000,000,000 records.

nickf
I know this will work,but I'm not talking about this at all
See the first 6 words for your answer then. The rest of it you can safely ignore if you like.
nickf
+1  A: 

That kind of injection will work if the code is using the mysqli library as it does allow for multiple queries to be run at once.

John Conde
Again,I'm not using mysqli.
`@unknown (google)`: you don't, but the people in that school do.
Quassnoi
+1  A: 

It's just a cartoon!

You're right, multi-query does not work by default, and it's not supported at all by the plain mysql extension in PHP.

More subtle SQL injection exploits exist, but then the comic wouldn't be as funny, would it?

Bill Karwin