INSERT 上的 SQL 注入

发布于 2024-11-25 10:39:28 字数 653 浏览 2 评论 0原文

这里描述的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

死开点丶别碍眼 2024-12-02 10:39:28

您的注入将单个 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.)

拍不死你 2024-12-02 10:39:28

正如 @pilcrow 指出的,mysql_query 将只接受单个语句。您的示例实际上是两个语句:

INSERT INTO COMMENTS VALUES('122','value');

and:

DELETE FROM users;

PHP mysql API 将立即拒绝此操作,因此您不能使用它来测试 SQL 注入。

该语句的另一个问题是注释字符的使用。 MySQL 注释语法 指出:

从“--”序列到行尾。在 MySQL 中,“--”
(双破折号)注释样式要求第二个破折号后跟
至少一个空格或控制字符(例如空格、制表符、
换行符等)。此语法与标准 SQL 略有不同
注释语法,如第 1.8.5.5 节中所述,“'--' 作为开头”
评论”。

因此,-- 后面必须有空格。如果您使用 # 代替,则不需要以下空格。

开始 SQL 注入测试的一种更简单、更安全的方法是尝试简单的 SELECT:

$value = "1' OR 1; -- ";
$sql = "SELECT * FROM mytable WHERE id = '$value'";

print "$sql\n";
// SELECT * FROM mytable WHERE id = '1' OR 1; #'

$result = mysql_query($sql,$con);

// Should return multiple rows (if your table has multiple rows):
while ($row = mysql_fetch_assoc($result)) {
    print "{$row['id']}\n";
}

由于 PHP mysql API 拒绝多个语句,因此一些更常用的 SQL 注入示例将不起作用,并且这是一件好事。然而,正如您从上面的简单示例中看到的,它并不能阻止其他形式的 SQL 注入。

想想这样的声明会如何受到影响:

DELETE FROM mytable WHERE id = '1'

还要记住,除了只想造成破坏的恶意黑客之外,删除数据可能对任何人都没有多大用处。另一方面,获取您不应该访问的机密数据可能非常有用。

As @pilcrow points out, mysql_query will only accept a single statement. Your example is actually two statements:

INSERT INTO COMMENTS VALUES('122','value');

and:

DELETE FROM users;

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:

From a “-- ” sequence to the end of the line. In MySQL, the “-- ”
(double-dash) comment style requires the second dash to be followed by
at least one whitespace or control character (such as a space, tab,
newline, and so on). This syntax differs slightly from standard SQL
comment syntax, as discussed in Section 1.8.5.5, “'--' as the Start of
a Comment”.

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:

$value = "1' OR 1; -- ";
$sql = "SELECT * FROM mytable WHERE id = '$value'";

print "$sql\n";
// SELECT * FROM mytable WHERE id = '1' OR 1; #'

$result = mysql_query($sql,$con);

// Should return multiple rows (if your table has multiple rows):
while ($row = mysql_fetch_assoc($result)) {
    print "{$row['id']}\n";
}

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:

DELETE FROM mytable WHERE id = '1'

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文