views:

152

answers:

2

when i use acunetix on my page i get a: Blind SQL/XPath injection

header: GET /file.php?id=2'+and+31337-31337=0+--+&page=2

response:

no files found

(sometimes it shows results)

here is my php code:

$id = (int) htmlentities($_GET['id']);
$fileid = mysql_real_escape_string($id);

the query:

SELECT * FROM `files` WHERE `id` = '".$fileid."'

what am i doing wrong? can someone erase my database just with this? im also getting the same message at some queries almost equal to that one but that also have limit 0,1

i'm using paginator (i fixed some injections that where in that script) but the example i gaved its not using it

+1  A: 

Casting the id on int should already prevent any chance of SQL injection attacks (as far as I know).

$id = (int) $_GET["id"];
$Query = "SELECT * FROM files WHERE id = $id;";

file.php?id=abcabc would result in $id = 0, so in worst case you won't find any record matching this id, but $id would never contain any string (especially not SQL) because of this integer cast.

I hope that's what you wanted to know.

sHiRoKKo
He is already using `mysql_real_escape_string()`, there is no need for this.
Alix Axel
but for cases that i dont cast anything and use only the real escape + htmlentities, can i be vulnerable to these attacks? i cant reproduce any of the injections that acunetix gives me. Even when i put a ' i get no error just a Invalid ID
Pizza Overflow
What I mean is that you don't need htmlentities and mysql_real_escape_string if you simply cast it on int, but in the example code he used all three of these at the same time. Of course, if id could be a string then mysql_real_escape_string is the right choice, otherwise, (int) can solve this as well.
sHiRoKKo
+1  A: 

I believe Acunetix is really buggy, doesn't seems to exist any SQL injection vulnerability at all.

Alix Axel
hm i fixed some xss attacks that he showed me but im receiving several messages from blind sql and im really worried
Pizza Overflow
@PO: **To avoid SQL Injections**, you don't need to **cast variables** much less use **`htmlentities()` or `htmlspecialchars()`**, as long as you **use `mysql_real_escape_string()`** you're safe. To **avoid XSS** attacks using **`htmlspecialchars()`** is enough.
Alix Axel