Jump to content

SQL injection on MySQL 5 + PHP 5 system


s0c0

Recommended Posts

I am pen testing a clients system (I did not write the orignal code) and I am able to login as a customer using a SQL injection hack due to some poorly written SQL and other issues.  My question is if its possible to execute to multiple queries using PHPs mysql_query and/or mysqli_query functions, for instance:

 

The query written by developer A looks like this:

 

$sql = "
SELECT * FROM clients WHERE username='$user' AND key='$password'
";
$result = mysql_query($sql);

 

My hack turns the query into this:

$sql = "
SELECT * FROM clients WHERE username='$user' AND key='' OR ''=''
";
$result = mysql_query($sql);

 

My question is if its possible to pass in 2 queries and have it properly execute and return a result set.  For instance the end query would look something like this after the injection:

 

$sql = "
SELECT * FROM clients WHERE user='$user'; SELECT * FROM customers;
"

Link to comment
Share on other sites

The php mysql client does not support multiple queries. The php mysqli does.  But you can always just inject a UNION SELECT * FROM customers onto the end of any SELECT query, which is why it is imperative that ALL external data be validated and use mysql_real_escape_string() on string data and force numeric data to be numbers of the correct type.

Link to comment
Share on other sites

Actually I think you are incorrect.  I ran this test and it did not work.

 

$sql = "SELECT * FROM office; SELECT * FROM office";
$result = mysqli_query($db->LINK,$sql);
$row=mysqli_fetch_assoc($result);
print_r($row);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.