这种完全没有安全考虑的SQL注入怎么能行得通呢?

发布于 2024-08-18 08:18:38 字数 175 浏览 2 评论 0原文

bob'); drop table students; --

在 PHP 中,这会失败:

mysql("statement1;statement2;");

只能有一个语句,所以我真的怀疑上面的注入实际上是如何工作的?

bob'); drop table students; --

In PHP,this will fail:

mysql("statement1;statement2;");

There can be only one statement,so I really doubt how can the above injection actually work at all?

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

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

发布评论

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

评论(4

哥,最终变帅啦 2024-08-25 08:18:38

如果代码使用 mysqli 库,这种注入就会起作用因为它确实允许同时运行多个查询

That kind of injection will work if the code is using the mysqli library as it does allow for multiple queries to be run at once.

活雷疯 2024-08-25 08:18:38

它在 MySQL 中不起作用,但是 SQL 注入还可以做其他事情。

考虑一下:

$sql = "SELECT * FROM users WHERE username = '$username' AND passwd = '$password'";

// run the query, check if the user exists, let them in, etc

如果将其写入 username 字段:

admin' -- 

它会变成:

SELECT * FROM users WHERE username = 'admin' -- AND passwd = 'whatever'

还有拒绝服务攻击的可能性,它们会构造输入,以便查询需要很长时间才能完成,霸占服务器上的所有资源。

//input:

admin' AND id IN (SELECT u1.id FROM users u1, users u2, users u3, users u4)

如果您的系统中有 1000 个用户,则该子查询将尝试返回 1,000,000,000,000 条记录。

Well it doesn't work in MySQL, but there's other things that can be done with SQL injection.

Consider this:

$sql = "SELECT * FROM users WHERE username = '$username' AND passwd = '$password'";

// run the query, check if the user exists, let them in, etc

If you write this into the username field:

admin' -- 

it becomes:

SELECT * FROM users WHERE username = 'admin' -- AND passwd = 'whatever'

There's also the possibility of Denial-of-service attacks, where they structure the input so that the query takes a very long time to complete, hogging all the resources on your server.

//input:

admin' AND id IN (SELECT u1.id FROM users u1, users u2, users u3, users u4)

If you had 1000 users in your system, that subquery would be trying to return 1,000,000,000,000 records.

临走之时 2024-08-25 08:18:38

这只是一个卡通

你是对的,默认情况下多重查询不起作用,并且 PHP 中的普通 mysql 扩展根本不支持它。

存在更微妙的 SQL 注入漏洞,但漫画就不会那么有趣了,不是吗?

It's just a cartoon!

You're right, multi-query does not work by default, and it's not supported at all by the plain mysql extension in PHP.

More subtle SQL injection exploits exist, but then the comic wouldn't be as funny, would it?

情栀口红 2024-08-25 08:18:38

不确定这是否有效,但尝试使用 // 作为分隔符而不是 ;,例如,

bob')// drop table students// --

有关于使用 PHP 中的 multi_query 语句提交多个语句的信息 此处

Not sure if this will work, but try using // as your separator instead of ;, e.g.,

bob')// drop table students// --

There is info on submitting multiple statements using the multi_query statement from PHP here.

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