I am running a small website where I have published some articles. I am also very interesed in security topics and tried sqlmap on my website. It found the database name, so my question is how it could find it.
The website is very basic and does just contain a very small number of php files and I have just tested on the index.php file:
sqlmap.py -u http://myurl.com/index.php?id=5 --dbs
In the index.php I have used the php functions mysql_real_escape_string
and stripslashes
to clean the string before using it in the SQL question and if the visitor tries to mess with the id
in the URL, then I just reload the index.php:
$id = $_GET['id'];
if (get_magic_quotes_gpc()) {
$id = stripslashes($id);
}
$id = mysql_real_escape_string($id);
$sql = "SELECT * , COUNT( * ) AS amount
FROM articles
WHERE id = $id
GROUP BY id";
$result = mysql_query($sql) or die(header("Location: index.php"));
So how on earth could sqlmap.py get the database name out of the above information?
Could you please explain how it is possible and also provide an example?