我一直在试图弄清楚 到底是怎么回事\x00、\n、\r、\或\x1a 可能导致 SQL 注入(inject)(如 http://nl3.php.net/manual/en/function.mysql-real-escape-string.php 中所述)
我理解单引号和双引号的概念,但是我如何以及为什么需要处理其他项目以确保我的查询安全?
最佳答案
我想知道同样的问题,我在 C API documentation of MySQL 中找到了答案。 , 它指出:
Characters encoded are “\”, “'”, “"”, NUL (ASCII 0), “\n”, “\r”, and Control+Z (\x1a). Strictly speaking, MySQL requires only that backslash and the quote character used to quote the string in the query be escaped. mysql_real_escape_string() quotes the other characters to make them easier to read in log files.
String Literals 中也有解释。那:
The mysql client truncates quoted strings containing NUL characters if they are not escaped, and Control+Z may be taken for END-OF-FILE on Windows if not escaped.
NUL 字符在 C 语言中表示字符串的结尾,因此这可能会错误地终止 mysql 客户端程序的输入参数。
\x1a
也是如此,它在 Windows 下标记文件的结尾(在命令提示符中尝试 type test.txt
,文件中间带有 \x1a
字符)。要点是,如果管理员的日志文件阅读器没有显示超出这些字符之一的数据,管理员可能会错过日志文件中的重要信息。但是谁还在用风雨飘摇
type
无论如何,在 Windows 下使用命令或等效命令来读取日志文件?换句话说,
\n
没有危险。 , \r
, \0
或 \x1a
在 PHP 中,除了可能使日志文件难以阅读之外。至于反斜杠,\' 或 1==1 将转换为 \\' 或 1==1 如果它也没有被转义,则取消引用转义的效果。
关于mysql-real-escape-string - PHP 的 mysql_real_escape_string 和 MySQL 注入(inject),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9279973/