我能举个例子来说明sql注入是如何发生的吗?

发布于 2024-12-12 01:38:25 字数 125 浏览 2 评论 0原文

我是 PHP 新手,即将发布。我正在使用 mysql_real_escape_string();对于所有用户输入以及所有 $_GET 和 $_REQUEST 变量。我想测试一下,但不确定它是如何完成的,以便我可以防止它并采取适当的措施。

I am new to PHP and coming close to launching. I am using mysql_real_escape_string(); for all user input and all $_GET and $_REQUEST variables. I wanted to test it out but not sure how it's done so i can prevent it and put in proper measures.

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

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

发布评论

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

评论(2

千纸鹤 2024-12-19 01:38:25

尝试在所有表单字段(包括隐藏字段)中输入类似于以下字符串的字符串:

blah'"blah

如果没有正确转义它,您将收到 sql 错误。如果您收到该 sql 错误,那么您应该能够弄清楚如何编写一个查询来执行与原始查询不同的操作。

Try inputting a string similar to the one below in all your form fields (including the hidden ones):

blah'"blah

If you're not escaping it properly, you'll get a sql error. If you get that sql error, you should then be able to figure out how to write a query that does something different than what the original one intended.

不知所踪 2024-12-19 01:38:25

我正在使用 mysql_real_escape_string();对于所有用户输入以及所有 $_GET 和 $_REQUEST 变量

,您完全错了。

首先,mysql_real_escape_string()与“用户输入”无关。这是与数据库相关的功能,与用户无关。
接下来,它与“所有输入”无关,因为它的使用仅限于字符串。因此,如果您有这样的代码,那么

$id = mysql_real_escape_string($_GET['id']);
$sql = "SELECT * FROM table WHERE id=$id";

您在这里进行的转义绝对没有用处并且无法保护任何内容。

至于测试——有点棘手。不过,互联网上有一些工具,我相信你可以谷歌一些。

I am using mysql_real_escape_string(); for all user input and all $_GET and $_REQUEST variables

well, you are entirely wrong.

First, mysql_real_escape_string() has nothing to do with "user input". This is database-related function, not user-related.
Next, it has nothing to do with "all input" as it's usage limited to strings only. So, if you have a code like this

$id = mysql_real_escape_string($_GET['id']);
$sql = "SELECT * FROM table WHERE id=$id";

you have here escaping absolutely useless and protects nothing.

as for the test - it's kinda tricky. however, there are tools in the internet, I am sure you can google some.

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