关于SQL注入报错:Illegal mix of collations for operation ‘UNION‘原因剖析与验证

关于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'#

image-20210225135019289

网上查了很多资料,原因是union两端的字段的collatie(排序规则)不同
【关于collatie】

于是去数据库查询:

查询:

  • 在user表中:

show create table users

image-20210225143106758

主查询中的first_name和last_name字段的collatie为utf8_unicode_ci

  • 在information_schema.tables表中:

show create table information_schema.tables

image-20210225154911448

没有显示,但是经过查询charset=utf8的默认collatie为utf8_general_ci如下图:

show collation

image-20210225155227705

查看数据库可知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

image-20210225155850172

image-20210225160555692

再次回到DVWA用union注入尝试:

payload:' union select table_schema,table_name from information_schema.tables where table_schema='dvwa'#

image-20210225160214188

验证成功!

猜你喜欢

转载自blog.csdn.net/qq_43665434/article/details/114088565
今日推荐