I've been reading about SQL injection attacks and how to avoid them, although I can never seem to make the "awful" examples given work, e.g. this post http://stackoverflow.com/questions/332365/xkcd-sql-injection-please-explain
I created a php file and a table in the database, had a value passed through $_GET
and tried to delete the table by doing bob'); drop table students; --
and it didn't work. PHP automatically escapes the \'
and the query has an error, no harm done. Same issue when trying to replicate login "attacks" like AND WHERE 1=1
etc.
example code:
<?php
$id = $_GET['id'];
$sql = "INSERT INTO Users (Username) VALUES ($id)";
echo $sql;
mysql_query($sql) or die(mysql_error());
And I'd pass sql.php?id=1); delete from Users; --
So is this some dated thing that used to apply in the days of PHP3 or something, and nowadays even novices are protected from things like magic quotes?
I'm using PHP5 on Ubuntu.