I'm trying to learn SQL injections so I can protect myself in the future.
Here is the PHP code:
$req = mysql_query("INSERT INTO ip_change VALUES('', '".$_SESSION['id']."', '".$_POST['raison']."')") or die(mysql_error());
And the user has full control over $_POST['raison'] content.
When i use 'hello
as $_POST['raison'] value I get
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'hello')' at line 1
When i use '); DELETE * FROM tabledetest;") or die(mysql_error());--
'); DELETE * FROM tabledetest;") or die(mysql_error());--
as $_POST['raison'] value I get
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELETE * FROM tabledetest;") or die(mysql_error());--')' at line 1
So I don't understand why my request isn't injected and I can't delete my tabledetest table.
Any help would be appreciated.
It is because you didn't do proper injection!
Here is the one you have done. The auto-format will hint you:
<?php
$_SESSION['id'] = "123"; //Just assume
$req = mysql_query("INSERT INTO ip_change VALUES('', '123', ''hello')") or die(mysql_error());
It didn't properly end the statement.
For the next one:
$req = mysql_query("INSERT INTO ip_change VALUES('', '123', ''); DELETE * FROM tabledetest;") or die(mysql_error());--')") or die(mysql_error());
mysql_query()
sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier.
mysqli
has support for multiple statements .
--
can't comment PHP code! PHP comment is //
or #
Some of the links that might help you: [Similar to your question]
为了防止SQL注入,您不应直接将变量注入以使用Prepared Statements查询。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.