关于SQL注入报错:Illegal mix of collations for operation 'UNION’原因剖析与验证
今天练习了一下DVWA的SQL注入模块
使用了union注入时报错如下:Illegal mix of collations for operation ‘UNION’
payload:' union select table_schema,table_name from information_schema.tables where table_schema='dvwa'#
网上查了很多资料,原因是union两端的字段的collatie(排序规则)不同。
【关于collatie】
于是去数据库查询:
查询:
show create table users
主查询中的first_name和last_name字段的collatie为utf8_unicode_ci
- 在information_schema.tables表中:
show create table information_schema.tables
没有显示,但是经过查询charset=utf8的默认collatie为utf8_general_ci如下图:
show collation
查看数据库可知union两端的字段的collatie不同。
验证:
将users表中first_name与last_name字段的collatie改为utf8_general_ci,使union两端的字段的collatie保持一致:
【关于修改collatie】
alter table users modify first_name varchar(15) character set utf8 collate utf8_general_ci
alter table users modify last_name varchar(15) character set utf8 collate utf8_general_ci
再次回到DVWA用union注入尝试:
payload:' union select table_schema,table_name from information_schema.tables where table_schema='dvwa'#
验证成功!