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

网上查了很多资料,原因是union两端的字段的collatie(排序规则)不同。
【关于collatie】
于是去数据库查询:
查询:
- 在user表中:
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'#

验证成功!
AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。
更多推荐


所有评论(0)