I had a client's site and I was trying to stop MySQL Injection on it. The code is so messed up(wasn't coded by me) that I cant use PDO so I tried mysql_real_escape_string()
but it is also not stopping attack as according to my research it only works when MySQL DB structure is in UTF8 so I tried to stop the attack manually so I wrote this code
$input = $_REQUEST;
foreach ($input as $key=>$value){
$input[$key] = preg_replace("/[^A-Za-z0-9\. ]/", "", $input[$key]);
if($input[$key] =='')
$input[$key]=1;
}
I limited only alphanumeric and few other characters for Chatting purposes but this is also not preventing the attack as I run again vulnerability scanner and it says the GET value was set to 6%c0%00xa7%c0%a2 which prompted SQLi error again. Its a HEX value that was converted to 6xa7. Is there any other best approach to stop this attack?