Recently, I encoded my site in PHP, and I was very proud of myself for the good methods of disinfecting my input before I used it in the request. Everything was great until my friend said that I needed to misinform my contribution. When I tried to explain to him that he was disinfected, he showed me that he found everything in the user table in my database. I did not know how, so I thought I would publish what I was doing wrong, which is why my disinfection does not work. Here is the PHP code that he used:
start_mysql(); // Starts the databases stuff, etc. $id = mysql_real_escape_string($_GET['id']); $game = mysql_query("SELECT * FROM `games` WHERE `id` = $id LIMIT 0, 1");
All he did was change the id parameter, allowing him to use SQL injection in my database. I thought mysql_real_escape_string escaped all such characters, but apparently I was wrong. I did some tests with a normal line to find out what would happen, and here's what I said
URL: /game.php? Id = 'OR' '='
echo($_GET['id']); // This echo'd: \' OR \'\' = \' echo(mysql_real_escape_string($_GET['id'])); // This echo'd: \\\' OR \\\'\\\' = \\\'
So my simple question is: what am I doing wrong?
Matt
source share