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
https://forums.phpfreaks.com/topic/140735-sql-injection-on-mysql-5-php-5-system/
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.