php addslashes sql注入仍然有效吗?
我知道“参数化查询”是圣杯。这不是主题。
有一篇旧帖子,似乎是所有与使用addslashes时的sql注入相关的讨论的参考。
这是链接:http://shiflett.org/ blog/2006/jan/addslashes-versus-mysql-real-escape-string
我的问题是:这个概念证明仍然正确吗?我尝试测试它,但添加斜杠似乎工作正常。有没有其他人真正尝试过这个,或者每个人都认为这是理所当然的?
很明显这个技巧不起作用
更新:请阅读我提出的问题。 我不关心最佳实践,我不需要替代方案,我只需要确保这仍然有效或无效。
更新:另外,我想提醒一下这个 POC 适用于 GBK、SJIS 或 BIG5 等字符集,但每个人似乎都忘记了这一点。当说“addslashes”时,让标题听起来有点吓人是不安全的。
解决方案:在我的例子中,mysql版本5.5.9-log不允许像/*这样未完成的内联注释。如果我使用 -- 或 # 就可以了。
I know "parameterised queries" is the holy grail. This is not the topic.
There is an old post, that seems to be the reference for all discussions related to sql injections when addslashes is used.
This is the link : http://shiflett.org/blog/2006/jan/addslashes-versus-mysql-real-escape-string
My question is : is this Proof of concept still correct ? I tried to test it but the addslashes seems to be working correctly. Did anyone else actually tried this or everybody is taken it for granted ?
SELECT *
FROM users
WHERE username = '�\' OR username = username /*'
AND password = 'guess'
so clearly the trick it's not working
Update : Please read the question I'm asking.
I don't care for best practice, I don't need alternatives, I just need to makes sure this is still valid or not.
Update : Also I would like to remind this POC works for character sets like GBK, SJIS or BIG5 and everybody seems to forget that. Making the titles sound a bit to scary when saying addslashes is not safe.
Solution : In my case the mysql version 5.5.9-log is not allowing inline comments that are not finised like /*. If I use -- or # it works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这似乎对我有用。
mysql:
PHP:
结果:
结论:
It seems working for me.
mysql:
PHP:
result:
Conclusions:
为了让您获得
'�\'
我猜您使用了0x??5c
多字节字符而不是0x??27
> 多字节字符。我在服务器上得到以下结果(导致成功注入的测试代码点的数量):
我没有测试 MySQL 的其他可用字符集,因为它们不是PHP 的
mbstring
扩展中提供了这些字符,因此我无法快速确定这些编码中存在哪些多字节字符。我也只尝试了双字节字符,因此可能存在更容易受到攻击的字符集。此外,如果表数据采用与客户端设置的编码相同的编码,也会有所帮助。否则,许多潜在的代码点都会出现“非法排序规则混合”错误。
For you to get
'�\'
I'm guessing you used the0x??5c
multi-byte character instead of the0x??27
multibyte character.I got the following results on my server (number of tested code points resulting in successful injections):
I didn't test MySQL's other available charsets since they weren't available in PHP's
mbstring
extension, so I had no quick way of determining which multi-byte characters existed in those encodings. I also only tried double-byte characters, so there may be more vulnerable character sets.Also, it helps if the table data is in the same encoding that the client is set to. Otherwise, you get "Illegal mix of collations" errors for a lot of the potential code points.