INSERT 上的 SQL 注入
这里描述的 INSERT 上的 SQL 注入似乎不适用于 MySQL。 INSERT 上的 SQL 注入
当我使用此语句时:
INSERT INTO COMMENTS VALUES('122','$_GET[value1]');
将此作为 'value1' 变量值:
<代码>');从用户中删除; --
返回此错误:
错误:您的 SQL 语法中有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在“DELETE FROM users;”附近使用的正确语法。 --')' 在第 1 行
出了什么问题???
PS:有人建议我用这个作为变量值进行 SQL 注入:
',(SELECT group_concat(table_name) FROM information_schema.tables INTO OUTFILE '/var/www/tables.txt'))-- -
但它也不起作用,并返回语法错误。
The SQL Injection on INSERT as described here doesn't seem to work with MySQL.
SQL injection on INSERT
When I use this statement:
INSERT INTO COMMENTS VALUES('122','$_GET[value1]');
With this as the 'value1' variable value:
'); DELETE FROM users; --
This error gets returned:
Error: 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 users; --')' at line 1
What's wrong???
PS: Someone suggested me to do an SQL injection with this as variable value:
',(SELECT group_concat(table_name) FROM information_schema.tables INTO OUTFILE '/var/www/tables.txt'))-- -
But it didn't work either, and returned a syntax error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的注入将单个 SQL 语句 (
INSERT ...
) 转换为多个 SQL 语句 (INSERT ...; DELETE ...
)。但是,PHP mysql API 不支持单个查询中的多个语句 。 (底层 MySQL C API 必须明确指示支持此功能,但您的绑定不支持此功能。)
Your injection turns a single SQL statement (
INSERT ...
) into multiple SQL statements (INSERT ...; DELETE ...
).However, the PHP mysql API does not support multiple statements in a single query. (The underlying MySQL C API must be explicitly instructed to support this functionality, which your bindings do not do.)
正如 @pilcrow 指出的,
mysql_query
将只接受单个语句。您的示例实际上是两个语句:and:
PHP
mysql
API 将立即拒绝此操作,因此您不能使用它来测试 SQL 注入。该语句的另一个问题是注释字符的使用。 MySQL 注释语法 指出:
因此,
--
后面必须有空格。如果您使用#
代替,则不需要以下空格。开始 SQL 注入测试的一种更简单、更安全的方法是尝试简单的 SELECT:
由于 PHP
mysql
API 拒绝多个语句,因此一些更常用的 SQL 注入示例将不起作用,并且这是一件好事。然而,正如您从上面的简单示例中看到的,它并不能阻止其他形式的 SQL 注入。想想这样的声明会如何受到影响:
还要记住,除了只想造成破坏的恶意黑客之外,删除数据可能对任何人都没有多大用处。另一方面,获取您不应该访问的机密数据可能非常有用。
As @pilcrow points out,
mysql_query
will only accept a single statement. Your example is actually two statements:and:
The PHP
mysql
API will reject this immediately, so you can't use that to test SQL injection.Another problem with the statement is the use of comment characters. The MySQL Comment Syntax states that:
So you have to have whitespace after the
--
. If you use#
instead, no following whitespace is required.A simpler and safer way to begin your SQL injection testing is to try a simple SELECT:
As the PHP
mysql
API rejects multiple statements, some of the more commonly used examples of SQL injection won't work, and that's a good thing. However, as you can see from the simple example above, it doesn't prevent other forms on SQL injection.Think how a statement like this could be affected:
Also bear in mind that deleting data is probably not of much use to anyone other than a malicious hacker who just wants to cause disruption. Obtaining confidential data to which you are not supposed to have access, on the other hand, may be very useful.