
select * from ttt where name = 'shuibianshu' * 'xxooxxoo'
这条语句为什么可以把 ttt 表里的全部数据查出来? 后面星号两边的字符串可以随便乱输。
1 EchoUtopia 2016-04-22 16:14:07 +08:00 我试的时候返回的星号后面那个条件的查询结果 |
2 SilentDepth 2016-04-22 16:22:07 +08:00 我是想说,那个字念 suí…… |
3 lancerliu 2016-04-22 16:22:15 +08:00 数据库类型和版本呢? 我执行这条语句是报错的 |
5 warlock OP @SilentDepth 哈哈 我的平翘舌一直有问题 ;) |
6 cdxy 2016-04-22 16:27:09 +08:00 aaa' or 1=1 -- 注意--右边有空格,在 url 里面可以 --+ 完整语句: select * from ttt where name='aaa' or 1=1 -- ' * 'xxx'; |
7 qhxin 2016-04-22 16:31:59 +08:00 'shuibianshu' * 'xxooxxoo'===>0 试试: select 'shuibianshu' * 'xxooxxoo' from ttt where name = 'shuibianshu' * 'xxooxxoo' |
8 warlock OP 后面两个字符串中间的星号 是做了乘法运算 结果是 0 , 然后匹配字符串的时候,表里的字符串都被转成了 0 , 0=0 ,所以就都查出来了。 参考资料: http://stackoverflow.com/questions/22080382/mysql-why-comparing-a-string-to-0-gives-true |
9 ivvei 2016-04-22 16:43:10 +08:00 Mysql 奇葩问题就是多啊 |
10 liyj144 2016-04-22 16:44:07 +08:00 因为'shuibianshu' * 'xxooxxoo' 的值是整数类型的 0 , 然后查询是 name 先做整型转换,然后和 0 对比,因为一般字符串(只要首字符不是数字的,比如 1qwe 这样的记录)都转成了 0 ,所以就造成了这种假象。 |
11 lancerliu 2016-04-22 20:17:40 +08:00 |
12 loading 2016-04-22 20:24:48 +08:00 这个是考试题? |
13 billlee 2016-04-22 20:39:11 +08:00 看了这个,我只想说,弱类型真可怕。 |
14 SunnySuo 2016-08-04 10:38:26 +08:00 楼主,我司招后端开发工程师( golang ), web 前端工程师、资深软件工程师,欢迎关注! http://v2ex.com/t/296530#reply3 |