我正在努力学习 SQL 注入(inject),以便将来可以保护自己。
这是 PHP 代码:
$req = mysql_query("INSERT INTO ip_change VALUES('', '".$_SESSION['id']."', '".$_POST['raison']."')") or die(mysql_error());
用户可以完全控制 $_POST['raison'] 内容。
当我使用 'hello
作为 $_POST['raison'] 值时,我得到
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
当我使用'); DELETE * FROM tabledetest;") 或 die(mysql_error());--
作为我得到的 $_POST['raison'] 值
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
所以我不明白为什么我的请求没有被注入(inject),并且我无法删除我的 tabledetest 表。
如有任何帮助,我们将不胜感激。
最佳答案
那是因为你没有进行正确的注入(inject)!
这是您所做的。自动格式会提示您:
<?php
$_SESSION['id'] = "123"; //Just assume
$req = mysql_query("INSERT INTO ip_change VALUES('', '123', ''hello')") or die(mysql_error());
它没有正确结束声明。
对于下一个:
$req = mysql_query("INSERT INTO ip_change VALUES('', '123', ''); DELETE * FROM tabledetest;") or die(mysql_error());--')") or die(mysql_error());
- 来自 the manual :
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
支持 multiple statements .
--
无法注释 PHP 代码! PHP 注释为//
或#
一些可能对您有帮助的链接:[与您的问题类似]
关于php - 基本的sql注入(inject),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36969254/