I recently performed a code audit on client, I found these lines of code that was subjected to a blind SQL injection
Code snippet:
<?php
if ($_GET['id'] != ''){
$groepsindeling = $_GET['id'];
} else {
$groepsindeling = $_GET['group'];
}
breadcrumb($groepsindeling);
?>
<?php
$groep = "SELECT * FROM `menubalk` WHERE `webnr` LIKE '%$webnr-%' AND `hoofdgroep` = '$_GET[id]' ORDER BY `naamt1` ASC";
$groepres = mysql_query($groep);
while ($groeprij = mysql_fetch_array($groepres)){
?>
I patched it immediately by using the mysqli_real_escape_string() function.
New code:
<?php
if ($_GET['id'] != ''){
$groepsindeling = mysqli_real_escape_string($_GET['id']);
settype($groepsindeling, "integer");
}
else {
$groepsindeling = mysqli_real_escape_string($_GET['group']);
}
breadcrumb($groepsindeling);
?>
<?php
$groep = "SELECT * FROM `menubalk` WHERE `webnr` LIKE '%$webnr-%' AND `hoofdgroep` = '$_GET[id]' ORDER BY `naamt1` ASC";
$groepres = mysql_query($groep);
while ($groeprij = mysql_fetch_array($groepres)){
?>
I did further testing to see if the code would work it worked against the boolean based blind SQL injection, but it seems like a failure as a time based blind SQL injection is still applicable here.
All suggestions are appreciated.