哪些 SQL 注入方法不会被“破坏”?通过 mysql_real_escape_string();?

发布于 2024-11-19 19:12:00 字数 212 浏览 2 评论 0原文

是否存在仅使用 utf8 编码的 mysql_real_escape_string(); 无法保护的 SQL 注入方法列表?

对于整数,我使用 intval(); 它足够安全吗?

对于那些认为我想获得“教程”来攻击任何人的人:不,我不会。我只是想知道如何让我的应用程序更加安全,并且我想知道它们是否能够 99% 地抵御黑客攻击

Is there a list of SQL injection methods which can't be protected with just using mysql_real_escape_string(); with utf8 encoding?

For integer, I'm using intval();
Is it secure enough?

For those who think I want to get "tutorial" to hack anyone: No, I won't. I just want to know how to make my applications more secure, and I want to know if they're secured 99% against hackers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

献世佛 2024-11-26 19:12:00

如果给定有效的数据库连接,mysql_real_escape_string() 在所有情况下都应该是安全的字符串数据(除了 这个答案)。

但是,字符串之外的任何内容,它都不会转义:

$id = mysql_real_escape_string($_GET["id"]);

mysql_query("SELECT * FROM table WHERE id = $id");

仍然容易受到攻击,因为您不必“突破”字符串来添加邪恶的附加命令。

If given a valid database connection, mysql_real_escape_string() is supposed to be safe for string data under all circumstances (with the rare exception described in this answer).

However, anything outside a string, it won't escape:

$id = mysql_real_escape_string($_GET["id"]);

mysql_query("SELECT * FROM table WHERE id = $id");

is still vulnerable, because you don't have to "break out" of a string to add an evil additional command.

桃酥萝莉 2024-11-26 19:12:00

sql注入的方法并不多。它们总是由于输入没有被正确清理和转义造成的。因此,虽然 mysql_real_escape_string() 将使任何字符串安全地包含在数据库查询中,但您应该遵循以下避免技术来保护您的数据和用户免受 SQL 注入。

  • 切勿以超级用户或数据库所有者的身份连接到数据库。始终使用权限非常有限的自定义用户。
  • 检查给定的输入是否具有预期的数据类型。
  • 如果应用程序等待数字输入,请考虑使用 is_numeric() 验证数据,或使用 settype() 默默地更改其类型
  • 引用传递给的每个非数字用户提供的值具有特定于数据库的字符串转义函数的数据库。因此 mysql_real_escape_string() 将使所有字符串安全地包含在对 mysql 数据库的 SQL 查询中
  • 您还可以学习使用存储过程和预准备语句,它们往往非常安全,但会产生其他影响

另请参阅: 关于 SQL 注入的 PHP 页面

There are not many sql injection methods. They are always due to input not being sanitized and escaped properly. So, While mysql_real_escape_string() will make any string safe to be included in a database query, you should follow the following avoidance techniques to protect your data and users from sql injection.

  • Never connect to the database as a superuser or as the database owner. Use always customized users with very limited privileges.
  • Check if the given input has the expected data type.
  • If the application waits for numerical input, consider verifying data with is_numeric(), or silently change its type using settype()
  • Quote each non numeric user supplied value that is passed to the database with the database-specific string escape function. So mysql_real_escape_string() will make all strings safe to be included in an SQL query to a mysql database
  • You could also learn to use stored procedures and prepared statements which tend to be very safe but have other impacts

See also: PHP page on SQL injection

土豪我们做朋友吧 2024-11-26 19:12:00

有很多东西可能无法受到标准方法的保护(例如字符串转义、整数转换),这也取决于您使用的软件版本。例如,utf-8 本身就是一个很大的问题,作为一个小例子(在许多例子中),您应该确保请求是有效的 utf-8(或将其转换为 utf-8)。请参阅示例

作为网站的不死祸根,我认为 MySQL 注入保护不能被压缩到单个 SO 答案中,因此我将这些链接作为一般起点。

http://ferruh.mavituna.com/sql-injection-cheatsheet-oku/< /a>

还有: 搜索mysql注入utf8

There are many things that may not get protected by standard methods (e.g. string escaping, int casting), also depending on the version of software you use. For example, utf-8 is quite an issue by itself, as a tiny example (among many) you should make sure the request is valid utf-8 (or convert it into utf-8). See an example.

As the undead bane of websites, I think that MySQL injection protection cannot be squeezed into a single SO answer, hence I'm including these links as general starting points.

http://ferruh.mavituna.com/sql-injection-cheatsheet-oku/

And also : Search for mysql injection utf8

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